Skip to content
Permalink
Browse files
modify interpret-cli ppt address
  • Loading branch information
hufeng committed Jun 11, 2018
1 parent 22fe026 commit b28e70b6658e362613a140329a28774b16fc3f99
Showing 2 changed files with 65 additions and 70 deletions.
@@ -1,92 +1,88 @@

Translator
-------
## 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通道
dubbo2.js 打通了 node 与 dubbo 服务调用的 rpc 通道

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

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

**_职责_**

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

## TODO

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

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

1. 在java接口项目生成jar包及依赖文件;
2. 从生成的jar字节码中提取ast信息,翻译师根据ast信息生成typescript;
3. 项目中调用生成代码;
如何把一个 dubbo 接口转换为 node 客户端能调用的代码,并在项目中使用呢?我们分为 3 个步骤:

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

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

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

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

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


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

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

dubbo.json:

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

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

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

***Tip*** 生成的代码可以发npm包供其他业务线使用或直接在项目中引用
**_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);
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`;
**_Tip_** `npm install interpret-util dubbo2.js`;
@@ -14,9 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import debug from "debug";
import debug from 'debug';

const log = debug("j2t:core:paramEnhance");
const log = debug('j2t:core:paramEnhance');

export function argumentMap() {
let _arguments = Array.from(arguments);
@@ -25,11 +25,10 @@ export function argumentMap() {
argumentItem =>
argumentItem.__fields2java
? paramEnhance(argumentItem.__fields2java())
: argumentItem
: argumentItem,
);
}


//删除对象中包含undefined 与null的值情况
function paramEnhance(javaParams: Array<object> | object) {
if (javaParams instanceof Array) {
@@ -50,29 +49,29 @@ function minusRedundancy(itemParam: any) {
for (var _key in itemParam.$) {
if (itemParam.$[_key] === null || itemParam.$[_key] === undefined) {
delete itemParam.$[_key];
log("删除 key %s from %j ", itemParam, _key);
log('删除 key %s from %j ', itemParam, _key);
}
}
}

export type JavaString=Object;
export type JavaBoolean=Object;
export type Javaboolean=Object;
export type JavaInteger=Object;
export type Javaint=Object;
export type JavaShort=Object;
export type Javashort=Object;
export type Javabyte=Object;
export type JavaByte=Object;
export type JavaLong=Object;
export type Javalong=Object;
export type Javadouble=Object;
export type JavaDouble=Object;
export type Javafloat=Object;
export type JavaFloat=Object;
export type Javachar=Object;
export type Javachars=Object;
export type JavaList=Object;
export type JavaSet=Object;
export type JavaHashMap=Object;
export type JavaMap=Object;
export type JavaString = Object;
export type JavaBoolean = Object;
export type Javaboolean = Object;
export type JavaInteger = Object;
export type Javaint = Object;
export type JavaShort = Object;
export type Javashort = Object;
export type Javabyte = Object;
export type JavaByte = Object;
export type JavaLong = Object;
export type Javalong = Object;
export type Javadouble = Object;
export type JavaDouble = Object;
export type Javafloat = Object;
export type JavaFloat = Object;
export type Javachar = Object;
export type Javachars = Object;
export type JavaList = Object;
export type JavaSet = Object;
export type JavaHashMap = Object;
export type JavaMap = Object;

0 comments on commit b28e70b

Please sign in to comment.