# interpret-dubbo2js.pdd

> interpret java-jar file to typescript files

Latest version **0.0.5** (published 2019-05-16) · Apache Licence 2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install interpret-dubbo2js.pdd
pnpm add interpret-dubbo2js.pdd
yarn add interpret-dubbo2js.pdd
bun add interpret-dubbo2js.pdd
```

Provides the command `interpret`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2019-05-16 |
| First published | 2019-05-13 |
| Weekly downloads | 0 |
| License | Apache Licence 2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 6 |
| Unpacked size | 5.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 777 |
| Maintainers | sunchuanleihit |
| Keywords | dubbo, typescript, ts-simple-ast |

## Links

- npm: https://www.npmjs.com/package/interpret-dubbo2js.pdd
- Repository: https://github.com/dubbo/dubbo2.js/blob/master/packages/interpret-cli
- npm.io page: https://npm.io/package/interpret-dubbo2js.pdd

## Dependencies (6)

- [klaw](https://npm.io/package/klaw.md) ^2.1.1
- [debug](https://npm.io/package/debug.md) 3.1.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^4.0.2
- [prettier](https://npm.io/package/prettier.md) ^1.10.2
- [commander](https://npm.io/package/commander.md) ^2.12.2
- [ts-simple-ast](https://npm.io/package/ts-simple-ast.md) ^1.3.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.5 (latest) — 2019-05-16
- 0.0.4 — 2019-05-14
- 0.0.3 — 2019-05-14
- 0.0.2 — 2019-05-13
- 0.0.1 — 2019-05-13

## README

## Translator

<img src="http://oss-hz.qianmi.com/x-site/dev/doc/dong/video2deal/xsite/interpret/鹦鹉.png" width = "100" alt="图片名称" align=center />

dubbo2.js 打通了 node 与 dubbo 服务调用的 rpc 通道

调用 dubbo 接口时, 如果能自动生成接口定义,参数的转换,代码提示 开发体验会更优秀;

"Translator(翻译师)" 为此而生!!

**_职责_**

1.  翻译 Interface 代码,生成 node 端可调用代码;
2.  自动将参数转换为 hessian.js 能识别的对象;
3.  接口方法及参数类型提示;

## TODO

* [ ] 接口注释信息未同步;
* [ ] mvn 打包插件;

## How to Usage?

如何把一个 dubbo 接口转换为 node 客户端能调用的代码,并在项目中使用呢?我们分为 3 个步骤:

1.  在 java 接口项目生成 jar 包及依赖文件;
2.  从生成的 jar 字节码中提取 ast 信息,翻译师根据 ast 信息生成 typescript;
3.  项目中调用生成代码;

注:

具体实现 参考文档 [dubbo2js-翻译师.pdf](https://github.com/hufeng/iThink/blob/master/talk/dubbo2js-%E7%BF%BB%E8%AF%91%E5%B8%88.pdf)

### step1:从 java 项目生成 jar

```shell
; 进入接口项目目录执行命令
mvn package
mvn install dependency:copy-dependencies
```

### step2:翻译生成 typescript 代码

```shell
npm install interpret-dubbo2js -g
interpret -c dubbo.json
```

dubbo.json:

```json
{
  "output": "./src",
  "entry": "com.qianmi",
  "entryJarPath": "${jarPath}",
  "libDirPath": "${denpendJarDir}"
}
```

| 参数名称     | 作用             |
| ------------ | ---------------- |
| output       | 生成代码保存路径 |
| entry        | 可选过滤无关代码 |
| entryJarPath | 接口的 jar 包    |
| libDirPath   | 接口所依赖的     |

**_Tip_** 生成的代码可以发 npm 包供其他业务线使用或直接在项目中引用

### step2:Use the provider

```typescript
import {ShowCaseProvider} from '@qianmi/***-api/lib/com/qianmi/ShowCaseProvider';
const dubbo = new Dubbo({
  application: {name: 'd2p-visitor-bff'},
  dubboInvokeTimeout: 10,
  //zookeeper address
  register: app.config.zookeeper,
  dubboVersion: '2.4.13',
  logger: app.logger as ILogger,
  interfaces: [
    'com.qianmi.cloudshop.api.marketing.d2p.D2pMarketingQueryProvider',
  ],
});
let showCaseProvider = ShowCaseProvider(dubbo);
showCaseProvider.show();
```

**_Tip_** `npm install interpret-util dubbo2.js`;

---
_Source: https://npm.io/package/interpret-dubbo2js.pdd · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
