diff --git a/FAQ.md b/FAQ.md index f91ab905857d2e3f01c00d1d70e9944e66bf96bb..1185f047194651cfb0a0498a578f70a72aeb6dd1 100644 --- a/FAQ.md +++ b/FAQ.md @@ -1,101 +1,101 @@ -## NAPI框架生成工具 问题反馈 - -### 1. pkg cmd_gen.js 生成.exe程序失败 - -问题描述:在Linux命令行入口安装辅助工具过程中,按文档步骤,在使用pkg命令打包生成.exe文件时,发生报错。 - - ~/workspace/assist_tool/assist_tools/napi_tool/code/tool_code/gen$ pkg cmd_gen.js - - > pkg@5.5.2 - > Targets not specified. Assuming: - > node10-linux-x64, node10-macos-x64, node10-win-x64 - > Fetching base Node.js binaries to PKG_CACHE_PATH - > fetched-v10.24.1-linux-x64 [ ] 0%> Not found in remote cache: - > {"tag":"v3.2","name":"node-v10.24.1-linux-x64"} - > Building base binary from source: - > built-v10.24.1-linux-x64 - > Fetching Node.js source archive from nodejs.org... - > Error! AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value: - -问题定位:这是由于在使用pkg命令打包生成.exe文件时,需要连接github来生成对应的可执行程序,由于国内的网络的问题,连接github的时候有时候时连接不上的。 - -问题解决:如果失败继续执行这个命令,多执行几次就会成功。 - - - -### 2. 用可执行程序生成c++代码失败 - -问题描述:在windows下用cmd_gen-win.exe生成对应的c++代码报错。 - - D:\napi_tool>cmd_gen-win.exe @ohos.power.d.ts pkg/prelude/bootstrap.js:1794 return wrapper.apply(this.exports, args); ^ TypeError: Cannot read property 'name' of undefined at GenerateAll (C:\snapshot\gen\generate.js) at Object.DoGenerate (C:\snapshot\gen\main.js) at Object. (C:\snapshot\gen\cmd_gen.js) at Module._compile (pkg/prelude/bootstrap.js:1794:22)  at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)  at Module.load (internal/modules/cjs/loader.js:950:32)  at Function.Module._load (internal/modules/cjs/loader.js:790:12) at Function.runMain (pkg/prelude/bootstrap.js:1847:12)  at internal/main/run_main_module.js:17:47 - -问题定位:在windows命令行中执行cmd_gen-win.exe的时候后面没有加d.ts文件所在的绝对路径,导致d.ts文件没有找到。 - -问题解决:在执行cmd_gen-win.exe的时候后面要加.d.ts文件所在的绝对路径,或者把d.ts文件放入到cmd_gen-win.exe所在的目录中。例如直接执行: - - cmd_gen-win.exe @ohos.power.d.ts - -### 3.未安装系统依赖插件,运行测试用例失败 - -问题描述:首次运行UT或ST用例失败。 - - Error: Cannot find module '../../node_modules/typescript' - Require stack: - - /home/harmony/hhhh/napi_generator_1/src/gen/tools/common.js - - /home/harmony/hhhh/napi_generator_1/src/gen/analyze.js - - /home/harmony/hhhh/napi_generator_1/test/unittest/analyze.test.js - at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15) - at Function.Module._load (internal/modules/cjs/loader.js:746:27) - at Module.require (internal/modules/cjs/loader.js:974:19) - at require (internal/modules/cjs/helpers.js:101:18) - at Object. (/home/harmony/hhhh/napi_generator_1/src/gen/tools/common.js:16:13) - -问题定位:首次运行测试用例napi_generator目录下、napi_generator/src目录下依赖插件未全部安装。 - -问题解决:napi_generator目录下、napi_generator/src目录下重新安装依赖即可,直到napi_generator/src/package.json文件中包含以下所有插件: - - "devDependencies": { - "@types/glob": "^7.1.4", - "@types/mocha": "^9.0.0", - "@types/node": "14.x", - "@types/vscode": "^1.62.0", - "@vscode/test-electron": "^1.6.2", - "eslint": "^8.1.0", - "glob": "^7.1.7", - "mocha": "^9.1.3", - "webpack": "^5.64.4", - "webpack-cli": "^4.9.1" - } - -### 4.未安装rewire插件,运行测试用例失败 - -问题描述:readme中插件全部安装完成后,执行测试用例失败。 - - Error: Cannot find module 'rewire' - Require stack: - - /home/harmony/myNapi/napi_generator_1/test/unittest/extend.test.js - at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15) - at Function.Module._load (internal/modules/cjs/loader.js:746:27) - at Module.require (internal/modules/cjs/loader.js:974:19) - -问题定位:由于ut用例代码中引入rewire,执行用例时未安装该插件,导致执行用例失败。 - -问题解决:执行命令: - - npm i rewire - - 安装插件之后,再次运行用例即可。 - -### 5.后缀为gyp文件中包含/*注释,执行用例失败 - -问题描述:代码中后缀为gyp的文件中包含/*注释,执行用例失败。 - - File "/home/harmony/myNapi/napi_generator/node_moduless/node-gyp/gyp/pylib/gyp/input.py",line 237,in LoadOneBuildFile - build_file_data = eval(build_file_contents,{"__builtins__":{}},None) - File "bingding.gyp",Line 1 - /* - ^ - -问题定位:代码中后缀为gyp的文件中包含/*,但工具不能解析,只能解析#后面的注释,导致执行用例失败。 - +# NAPI框架生成工具 问题反馈 + +## 1. pkg cmd_gen.js 生成.exe程序失败 + +问题描述:在Linux命令行入口安装辅助工具过程中,按文档步骤,在使用pkg命令打包生成.exe文件时,发生报错。 + + ~/workspace/assist_tool/assist_tools/napi_tool/code/tool_code/gen$ pkg cmd_gen.js + + > pkg@5.5.2 + > Targets not specified. Assuming: + > node10-linux-x64, node10-macos-x64, node10-win-x64 + > Fetching base Node.js binaries to PKG_CACHE_PATH + > fetched-v10.24.1-linux-x64 [ ] 0%> Not found in remote cache: + > {"tag":"v3.2","name":"node-v10.24.1-linux-x64"} + > Building base binary from source: + > built-v10.24.1-linux-x64 + > Fetching Node.js source archive from nodejs.org... + > Error! AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value: + +问题定位:这是由于在使用pkg命令打包生成.exe文件时,需要连接github来生成对应的可执行程序,由于国内的网络的问题,连接github的时候有时候时连接不上的。 + +问题解决:如果失败继续执行这个命令,多执行几次就会成功。 + + + +## 2. 用可执行程序生成c++代码失败 + +问题描述:在windows下用cmd_gen-win.exe生成对应的c++代码报错。 + + D:\napi_tool>cmd_gen-win.exe @ohos.power.d.ts pkg/prelude/bootstrap.js:1794 return wrapper.apply(this.exports, args); ^ TypeError: Cannot read property 'name' of undefined at GenerateAll (C:\snapshot\gen\generate.js) at Object.DoGenerate (C:\snapshot\gen\main.js) at Object. (C:\snapshot\gen\cmd_gen.js) at Module._compile (pkg/prelude/bootstrap.js:1794:22)  at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)  at Module.load (internal/modules/cjs/loader.js:950:32)  at Function.Module._load (internal/modules/cjs/loader.js:790:12) at Function.runMain (pkg/prelude/bootstrap.js:1847:12)  at internal/main/run_main_module.js:17:47 + +问题定位:在windows命令行中执行cmd_gen-win.exe的时候后面没有加d.ts文件所在的绝对路径,导致d.ts文件没有找到。 + +问题解决:在执行cmd_gen-win.exe的时候后面要加.d.ts文件所在的绝对路径,或者把d.ts文件放入到cmd_gen-win.exe所在的目录中。例如直接执行: + + cmd_gen-win.exe @ohos.power.d.ts + +## 3.未安装系统依赖插件,运行测试用例失败 + +问题描述:首次运行UT或ST用例失败。 + + Error: Cannot find module '../../node_modules/typescript' + Require stack: + - /home/harmony/hhhh/napi_generator_1/src/gen/tools/common.js + - /home/harmony/hhhh/napi_generator_1/src/gen/analyze.js + - /home/harmony/hhhh/napi_generator_1/test/unittest/analyze.test.js + at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15) + at Function.Module._load (internal/modules/cjs/loader.js:746:27) + at Module.require (internal/modules/cjs/loader.js:974:19) + at require (internal/modules/cjs/helpers.js:101:18) + at Object. (/home/harmony/hhhh/napi_generator_1/src/gen/tools/common.js:16:13) + +问题定位:首次运行测试用例,napi_generator目录下、napi_generator/src目录下依赖插件未全部安装。 + +问题解决:napi_generator目录下、napi_generator/src目录下重新安装依赖即可,直到napi_generator/src/package.json文件中包含以下所有插件: + + "devDependencies": { + "@types/glob": "^7.1.4", + "@types/mocha": "^9.0.0", + "@types/node": "14.x", + "@types/vscode": "^1.62.0", + "@vscode/test-electron": "^1.6.2", + "eslint": "^8.1.0", + "glob": "^7.1.7", + "mocha": "^9.1.3", + "webpack": "^5.64.4", + "webpack-cli": "^4.9.1" + } + +## 4.未安装rewire插件,运行测试用例失败 + +问题描述:readme中插件全部安装完成后,执行测试用例失败。 + + Error: Cannot find module 'rewire' + Require stack: + - /home/harmony/myNapi/napi_generator_1/test/unittest/extend.test.js + at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15) + at Function.Module._load (internal/modules/cjs/loader.js:746:27) + at Module.require (internal/modules/cjs/loader.js:974:19) + +问题定位:由于ut用例代码中引入rewire,执行用例时未安装该插件,导致执行用例失败。 + +问题解决:执行命令: + + npm i rewire + + 安装插件之后,再次运行用例即可。 + +## 5.后缀为gyp文件中包含/*注释,执行用例失败 + +问题描述:代码中后缀为gyp的文件中包含/*注释,执行用例失败。 + + File "/home/harmony/myNapi/napi_generator/node_moduless/node-gyp/gyp/pylib/gyp/input.py",line 237,in LoadOneBuildFile + build_file_data = eval(build_file_contents,{"__builtins__":{}},None) + File "bingding.gyp",Line 1 + /* + ^ + +问题定位:代码中后缀为gyp的文件中包含/*,但工具不能解析,只能解析#后面的注释,导致执行用例失败。 + 问题解决:修改代码。 \ No newline at end of file diff --git a/README_zh.md b/README_zh.md index 6f0214589eb1e214d59a6264269fdf3f39251f91..0cb39ff235f8d63ee4f48cab93532d07bc9fac3b 100755 --- a/README_zh.md +++ b/README_zh.md @@ -47,12 +47,12 @@ 使用者可以根据自己的需要选择合适的工具,VS Code插件存放在以下路径: ``` -napi_generator/ prebuilt +napi_generator/prebuilt ``` -可执行文件与IntelliJ插件下载路径如下: +可执行文件与IntelliJ插件下载路径如下,选择napi_generator_outputs.zip下载。 -[下载链接](https://repo.huaweicloud.com/harmonyos/develop_tools/napi_generator/napi_generator_20220319.tart.gz) +[下载链接](http://ftpkaihongdigi.i234.me:5000/fsdownload/PPVcNMgVv/2022-06-13) 具体的工具使用步骤,可以左键单击以下链接了解: @@ -65,7 +65,7 @@ napi_generator/ prebuilt 为了方便使用者快速上手工具,可供测试的typescript文件存放在以下路径: ``` -napi_generator/ examples / ts +napi_generator/examples/ts ``` 在window环境下的,根据输入文件@ohos.napitest.d.ts和basic.d.ts生成的输出文件,如下所示: @@ -121,7 +121,7 @@ bool TestClass1::if_callback(std::string &v1, std::string &out) { ## 版本说明 - 当前版本已支持的特性和代开发的特性,如下所示: + 当前版本已支持的特性和待开发的特性,如下所示: [已支持特性](https://gitee.com/openharmony/napi_generator/blob/master/release-notes/napi_generator-1.0.md) diff --git a/docs/DEVELOP_ZH.md b/docs/DEVELOP_ZH.md index 81b8480cdf63805fa1ec4821289adb5e3222644b..54bdfe9e0b11e9006558753f627b61514b8628e0 100755 --- a/docs/DEVELOP_ZH.md +++ b/docs/DEVELOP_ZH.md @@ -1,106 +1,133 @@ -# NAPI框架生成工具开发说明 -若当前工具功能不满足开发者需求,开发者需增强工具能力,则可基于已有源码进行工具二次开发,编译打包生成自定义的可执行文件和插件。 - -## 工具开发 - -### 可执行文件开发说明 - -#### 环境说明 - -系统:建议Ubuntu 20.04或者Windows 10 - -#### 开发步骤 - -1.安装typescript:在napi_generator目录下和napi_generator/src目录下分别都执行命令: - - npm i typescript - -2.安装stdio:在napi_generator目录下执行命令: - - npm i stdio - -3.安装pkg : 在napi_generator目录下执行命令: - - sudo npm i -g pkg - -4.打包三个版本 : 执行命令: - - pkg . - -执行以上步骤后,即可在gen目录下生成Windows、linux、mac系统下的可执行程序: - - napi_generator-win.exe、napi_generator-linux、napi_generator-macos - -### VS插件开发说明 - -#### Linux - -1.在napi_generator/src这个目录下执行命令: - - npm i typescript - -2.在napi_generator/src这个目录下执行命令: - - npm i vsce - -3.在napi_generator/src这个目录下执行命令: - - npx vsce package - -4.每个选项都选择y,然后回车,最终会在当前目录下打包生成一个插件gnapi-0.0.1.vsix。结果如下: - - ![](../figures/linux_package_vsix.png) - -#### Windows - -1.在napi_generator/src这个目录下执行命令: - - npm i typescript - -2.在napi_generator/src这个目录下执行命令: - - npm i vsce - -3.在napi_generator/src这个目录下执行命令: - - npx vsce package - -4.每个选项都选择y,然后回车,最终会在当前目录下打包生成一个插件gnapi-0.0.1.vsix。结果如下: - - ![](../figures/win_package_vsix.png) - -### IntelliJ插件开发说明 - -#### 环境说明 - -系统:建议Ubuntu 20.04或者Windows 10 - -#### 开发步骤 - -1.通过IntelliJ IDEA打开generator目录下的代码。 - -![](../figures/IntelliJ_develop_one.png) - -2.执行IntelliJ IDEA工具右上角的run。 - -![](../figures/IntelliJ_develop_two.png) - -3.IntelliJ IDEA会自动拉起一个应用程序。 - -![](../figures/IntelliJ_develop_three.png) - -4.选择.d.ts文件,右键选择generate.d.ts选项,生成文件。 - -![](../figures/IntelliJ_develop_four.png) - -5.执行结束后会在目录下生成对应的文件。 - -![](../figures/IntelliJ_develop_five.png) - -## 工具测试 - 进行工具二次开发后,本地可进行单元测试、story特性测试确保工具的可用性。左键单击以下链接了解详情: - - [单元测试](https://gitee.com/openharmony/napi_generator/blob/master/test/unittest/README_ZH%20.md) - - [story测试](https://gitee.com/openharmony/napi_generator/blob/master/test/storytest/README_ZH.md) - +# NAPI框架生成工具开发说明 + +若当前工具功能不满足开发者需求,开发者需增强工具能力,则可基于已有源码进行工具二次开发,编译打包生成自定义的可执行文件和插件。 + +## 工具开发 + +### 可执行文件开发说明 + +#### 环境说明 + +系统:建议Ubuntu 20.04或者Windows 10 + +#### 开发步骤 + +##### Linux + +1.安装typescript:在napi_generator目录下和napi_generator/src目录下分别都执行命令: + + npm i typescript + +2.安装stdio:在napi_generator目录下执行命令: + + npm i stdio + +3.安装pkg : 在napi_generator目录下执行命令: + + sudo npm i -g pkg + +4.打包三个版本 : 执行命令: + + pkg . + +执行以上步骤后,即可在napi_generator目录下生成Windows、linux、mac系统下的可执行程序: + + napi_generator-win.exe、napi_generator-linux、napi_generator-macos + +##### Windows + +1.安装typescript:使用管理员身份在napi_generator目录下和napi_generator/src目录下分别都执行命令: + + npm i typescript + +2.安装stdio:使用管理员身份在napi_generator目录下执行命令: + + npm i stdio + +3.安装pkg : 使用管理员身份在napi_generator目录下执行命令: + + npm i -g pkg + +4.打包三个版本 : 使用管理员身份执行命令: + + pkg . + +执行以上步骤后,即可在napi_generator目录下生成Windows、linux、mac系统下的可执行程序: + + napi_generator-win.exe、napi_generator-linux、napi_generator-macos + +### VS插件开发说明 + +#### Linux + +1.在napi_generator/napi_vs_plugin/src这个目录下执行命令: + + npm i typescript + +2.在napi_generator/napi_vs_plugin/src这个目录下执行命令: + + npm i vsce + +3.在napi_generator/napi_vs_plugin/src这个目录下执行命令: + + npx vsce package + +4.每个选项都选择y,然后回车,最终会在当前目录下打包生成一个插件gnapi-0.0.1.vsix。结果如下: + + ![](../figures/linux_package_vsix.png) + +#### Windows + +1.在napi_generator/napi_vs_plugin/src这个目录下执行命令: + + npm i typescript + +2.在napi_generator/napi_vs_plugin/src这个目录下执行命令: + + npm i vsce + +3.在napi_generator/napi_vs_plugin/src这个目录下执行命令: + + npx vsce package + +4.每个选项都选择y,然后回车,最终会在当前目录下打包生成一个插件gnapi-0.0.1.vsix。结果如下: + + ![](../figures/win_package_vsix.png) + +### IntelliJ插件开发说明 + +#### 环境说明 + +系统:建议Ubuntu 20.04或者Windows 10 + +#### 开发步骤 + +1.通过IntelliJ IDEA打开generator目录下的代码。 + +![](../figures/IntelliJ_develop_one.png) + +2.执行IntelliJ IDEA工具右上角的run。 + +![](../figures/IntelliJ_develop_two.png) + +3.IntelliJ IDEA会自动拉起一个应用程序。 + +![](../figures/IntelliJ_develop_three.png) + +4.选择.d.ts文件,右键选择generate Napi Frame选项,工具打开generate Napi Frame弹窗。接口文件路径默认填写,此处不修改;生成框架路径默认填写,此处修改为新增out文件夹下;编译脚本路径默认填写,不修改。点击ok,生成文件。 + +![](../figures/IntelliJ_develop_four.png) + +![](../figures/IntelliJ_develop_six.png) + +5.执行结束后会在目录下生成对应的文件。 + +![](../figures/IntelliJ_develop_five.png) + +## 工具测试 + 进行工具二次开发后,本地可进行单元测试、story特性测试确保工具的可用性。左键单击以下链接了解详情: + + [单元测试](https://gitee.com/openharmony/napi_generator/blob/master/test/unittest/README_ZH%20.md) + + [story测试](https://gitee.com/openharmony/napi_generator/blob/master/test/storytest/README_ZH.md) + diff --git a/docs/ENSEMBLE_METHOD_ZH.md b/docs/ENSEMBLE_METHOD_ZH.md index 722c6c1a5c12007da042278c87d737ef1ea5e553..48cb3833dc06871418bbf95788aea2931eb353fb 100755 --- a/docs/ENSEMBLE_METHOD_ZH.md +++ b/docs/ENSEMBLE_METHOD_ZH.md @@ -7,7 +7,7 @@ ## 建立模块位置 -模块目录理论上可以建立在OpenHarmony代码库的任何地方,为行文方便,假设OpenHarmony代码库的目录为`OHOS_SRC`,在`OHOS_SRC`目录下,例如建立此次测试模块目录:napitest。此时,`OHOS_SRC`目录下应该有 ark, foundation, device, …, napitest等目录,其中napitest就是刚刚建立的,在napitest目录下,把之前用可执行文件或者插件转换出来的文件全部拷贝到该目录下,并且在该目录下新建一个文件ohos.build。例如napitest目录下有以下文件: +模块目录理论上可以建立在OpenHarmony代码库的任何地方,为行方便,假设OpenHarmony代码库的目录为`OHOS_SRC`,在`OHOS_SRC`目录下,例如建立此次测试模块目录:napitest。此时,`OHOS_SRC`目录下应该有 ark, foundation, device, …, napitest等目录,其中napitest就是刚刚建立的,在napitest目录下,把之前用可执行文件或者插件转换出来的文件全部拷贝到该目录下,并且在该目录下新建一个文件ohos.build。例如napitest目录下有以下文件: foundation/napitest |-- binding.gyp diff --git a/docs/INSTRUCTION_ZH.md b/docs/INSTRUCTION_ZH.md index 2af2e4d1af7fe3c63c8a27c5abab65f442e4a7da..4440f3b13f87737f27bda6df00a64a2ac934bba7 100755 --- a/docs/INSTRUCTION_ZH.md +++ b/docs/INSTRUCTION_ZH.md @@ -4,13 +4,12 @@ NAPI框架生成工具支持三种入口,分别是可执行程序、VS Code插件、IntelliJ插件,使用者可以根据自己的需要选择合适的工具,VS Code插件存放在以下路径: ``` -napi_generator/ prebuilt +napi_generator/prebuilt ``` -可执行文件与IntelliJ插件下载路径如下: - -[下载链接](https://repo.huaweicloud.com/harmonyos/develop_tools/napi_generator/napi_generator_20220319.tart.gz) +可执行文件与IntelliJ插件下载路径如下,选择napi_generator_outputs.zip下载。 +[下载链接](http://ftpkaihongdigi.i234.me:5000/fsdownload/PPVcNMgVv/2022-06-13) 下载文件说明如下: @@ -63,13 +62,13 @@ napi_generator的可执行程序方式和插件方式都具有预检查的功能 xudong@xudong:~/napi_tool$ ls napi_generator-linux @ohos.napitest.d.ts basic.d.ts xudong@xudong:~/napi_tool$ ./napi_generator-linux -f @ohos.napitest.d.ts - -3) 运行成功后会在.d.ts文件说在的目录下生成对应的文件。例如: + +3) 运行成功后会在napi_generator-linux文件所在的目录下生成对应的文件。例如: xudong@xudong:~/napi_tool$ ls binding.gyp BUILD.gn cmd_gen-linux @ohos.napitest.d.ts napitest.cpp napitest.h napitest_middle.cpp test.sh x_napi_tool.cpp x_napi_tool.h xudong@xudong:~/napi_tool$ - + #### Windows 1.将要转换的.d.ts文件放到任意目录下,建议放到可执行程序napi_generator-win.exe同级目录下,并且检查需要转换的d.ts文件中是否声明了import的d.ts文件,如果存在需要将import的d.ts文件也放入到待转换的d.ts文件相同的目录下。示例如下: @@ -88,15 +87,13 @@ napi_generator的可执行程序方式和插件方式都具有预检查的功能 命令行参数如下,-f是必须添加的参数,-o是可选参数,如果不加就默认当前目录。 - -f, --filename .d.ts file -o, --out output directory ("." by default) - + -f, --filename .d.ts file + -o, --out output directory ("." by default) -3.运行成功后会在.d.ts文件说在的目录下生成对应的文件。例如: +3.运行成功后会在napi_generator-win.exe文件所在的目录下生成对应的文件。例如: ![](../figures/pic-d-ts-transition.png) - - #### Mac 方法步骤参考windows、Linux的使用方法。 @@ -106,15 +103,15 @@ visual studio code 版本需1.62.0及以上。 #### 步骤 -1) 打开VS Code,在左侧边栏中选择插件安装。 +1. 打开VS Code,在左侧边栏中选择插件安装。 ![](../figures/pic-plug-in-search.png) -2) 单击上面三个点的按钮,选择从VSIX安装选项,然后选择刚才生成的gnapi-0.0.1.vsix插件文件,再单击安装。 +2. 单击上面三个点的按钮,选择从VSIX安装选项,然后选择刚才生成的gnapi-0.0.1.vsix插件文件,再单击安装。 ![](../figures/pic-plug-in-select.png) -3) 安装完成后就会在VS Code的插件管理器中能看到gnapi这个插件了。 +3. 安装完成后就会在VS Code的插件管理器中能看到gnapi这个插件了。 ![](../figures/pic-plug-in-gnapi.png) @@ -122,11 +119,13 @@ visual studio code 版本需1.62.0及以上。 ![](../figures/pic-plug-in-select-d-ts.png) -5. 鼠标在.d.ts上单击右键,选择.d.ts生成c++选项。 +5. 鼠标在.d.ts上单击右键,选择“ Generate Napi Frame”选项,工具打开 Generate Napi Frame窗口。选择方式有.d.ts文件、文件夹两种方式,此处以.d.ts文件为例;选择接口文件文本框中默认填写.d.ts文件路径,此处不修改;生成框架路径文本框填写生成文件所放文件夹绝对路径;编译脚本路径文本框选填,此处不填写,然后点击ok。 ![](../figures/pic-plug-in-gen-c++.png) -6. 转换成功就会提示“生成成功”的信息,并且在该目录下生成对应文件,例如: + ![](../figures/pic-generator-napi-frame.png) + +6. 转换成功工具右下角就会提示“Generated successfully”的信息,并且在.d.ts文件当前目录下生成对应文件,例如: ![](../figures/pic-plug-in-gen-sucess.png) @@ -137,48 +136,52 @@ visual studio code 版本需1.62.0及以上。 #### 依赖 系统:不限 -开发工具:IntelliJ IDEA +开发工具:DevEco stdio #### 使用指导 -下载可执行程序与插件包generator.jar,将需要平台下的可执行文件放到以下路径中的对应平台目录下 - - napi_generator\src\generator\resources\cmds +下载可执行程序与插件包generator.jar,下载链接如下: -[下载链接](https://repo.huaweicloud.com/harmonyos/develop_tools/napi_generator/napi_generator_20220319.tart.gz) +[下载链接](http://ftpkaihongdigi.i234.me:5000/fsdownload/PPVcNMgVv/2022-06-13) -使用者下载插件包后,按照下述步骤安装使用即可: +使用者进入上述链接中选择napi_generator_outputs.zip,下载插件包后,按照下述步骤安装使用即可: 1.新建或打开项目工程,以下以新建项目工程为例。 -File->New->Project。 +File->New->Create Project。 -![](../figures/IntelliJ_step_newFile.png) +![](../figures/DevEco_step_newFile.png) -左侧栏选择Java,右侧默认选择Groovy,单击Next,继续单击Next,单击Finish,新的工程就创建好了。 +Ability Template选择Empty Ability,单击Next。 -![](../figures/IntelliJ_step_firstNext.png) +![](../figures/DevEco_step_firstNext.png) -2.复制本地napi_generator/test/unittest/basic.d.ts文件,进入IntelliJ新建项目中选中src粘贴,将basic.d.ts文件放入src目录。 +填写Project name、Save location,其他选项可不修改,单击Finish,新的工程就创建好了。 -![](../figures/IntelliJ_step_upload.png) +![](../figures/DevEco_step_finish.png) -3.把需要转换的.d.ts文件放到项目中。 +2.复制本地napi_generator/test/unittest/basic.d.ts文件,进入DevEco stdio新建项目中选中src粘贴,将basic.d.ts文件放入src目录。 -![](../figures/IntelliJ_step_project.png) +![](../figures/DevEco_step_upload.png) + +3.把需要转换的.d.ts文件放到项目中basic.d.ts相同位置。 + +![](../figures/DevEco_step_project.png) 4.安装插件,File->Settings->Plugins->Installed->Install Plugin from Disk...,选择下载的generator.jar,安装成功之后重启IDE。 -![](../figures/IntelliJ_step_pluginsOk.png) +![](../figures/DevEco_step_pluginsOk.png) + +![](../figures/DevEco_step_applyPlugins.png) -![](../figures/IntelliJ_step_applyPlugins.png) +5.选择.d.ts文件,右键选择 Generate Napi Frame选项,工具弹出 Generate Napi Frame弹窗。接口文件文本框填写.d.ts文件路径;生成框架路径文本框填写转换后生成文件存放文件夹路径,此处为src下新增out文件夹,生成文件存放在out中;编译脚本路径默认填写不修改,点击ok。 -5.选择.d.ts文件,右键选择Generate NAPI Frame选项,生成文件。 +![](../figures/DevEco_step_generate.png) -![](../figures/IntelliJ_step_generate.png) +![](../figures/DevEco_step_generate_ok.png) 6.执行结束后会在目录下生成对应的文件。 -![](../figures/IntelliJ_step_generateSuccess.png) +![](../figures/DevEco_step_generateSuccess.png) ### 注意 diff --git a/figures/DevEco_step_applyPlugins.png b/figures/DevEco_step_applyPlugins.png new file mode 100755 index 0000000000000000000000000000000000000000..01c92f5bd5dd0be42d59ec19553715599c4291d5 Binary files /dev/null and b/figures/DevEco_step_applyPlugins.png differ diff --git a/figures/DevEco_step_finish.png b/figures/DevEco_step_finish.png new file mode 100755 index 0000000000000000000000000000000000000000..b02a3bd8ab283840a1401131153e1b67d83dd772 Binary files /dev/null and b/figures/DevEco_step_finish.png differ diff --git a/figures/DevEco_step_firstNext.png b/figures/DevEco_step_firstNext.png new file mode 100755 index 0000000000000000000000000000000000000000..812504617e554fa1985f1bda04fa2af3b122a4a0 Binary files /dev/null and b/figures/DevEco_step_firstNext.png differ diff --git a/figures/DevEco_step_generate.png b/figures/DevEco_step_generate.png new file mode 100755 index 0000000000000000000000000000000000000000..68e93cbc16e33c0d057f71518fede3dca7fec52d Binary files /dev/null and b/figures/DevEco_step_generate.png differ diff --git a/figures/DevEco_step_generateSuccess.png b/figures/DevEco_step_generateSuccess.png new file mode 100755 index 0000000000000000000000000000000000000000..486b749cd639adaa074441d5d1e49c6bebbea4e3 Binary files /dev/null and b/figures/DevEco_step_generateSuccess.png differ diff --git a/figures/DevEco_step_generate_ok.png b/figures/DevEco_step_generate_ok.png new file mode 100755 index 0000000000000000000000000000000000000000..db626c8da3d15930b8057a0b57ec3594efbe3628 Binary files /dev/null and b/figures/DevEco_step_generate_ok.png differ diff --git a/figures/DevEco_step_newFile.png b/figures/DevEco_step_newFile.png new file mode 100755 index 0000000000000000000000000000000000000000..017b12d81b77c8b156b4936c87f39d83f83f66d8 Binary files /dev/null and b/figures/DevEco_step_newFile.png differ diff --git a/figures/DevEco_step_pluginsOk.png b/figures/DevEco_step_pluginsOk.png new file mode 100755 index 0000000000000000000000000000000000000000..39ab066456486b8d643128e9775ac2bc18aaeb0d Binary files /dev/null and b/figures/DevEco_step_pluginsOk.png differ diff --git a/figures/DevEco_step_project.png b/figures/DevEco_step_project.png new file mode 100755 index 0000000000000000000000000000000000000000..ed31b740565b9c6686556ef660d2838bb63adf42 Binary files /dev/null and b/figures/DevEco_step_project.png differ diff --git a/figures/DevEco_step_upload.png b/figures/DevEco_step_upload.png new file mode 100755 index 0000000000000000000000000000000000000000..051300303cbda48f7764aab7a7a907cf9ab13dbf Binary files /dev/null and b/figures/DevEco_step_upload.png differ diff --git a/figures/IntelliJ_develop_five.png b/figures/IntelliJ_develop_five.png index 832f78b4654da781b68df967de2a9ce848ba72cb..476d8fe2c2a6eb124d4ccbe14412c0f8d6da8266 100644 Binary files a/figures/IntelliJ_develop_five.png and b/figures/IntelliJ_develop_five.png differ diff --git a/figures/IntelliJ_develop_four.png b/figures/IntelliJ_develop_four.png index 665c6ecba555a943b2a6aa21ab8c7f0359e67f6e..7661d1c4c9e6877d08db3307c34684cd3a67f702 100644 Binary files a/figures/IntelliJ_develop_four.png and b/figures/IntelliJ_develop_four.png differ diff --git a/figures/IntelliJ_develop_six.png b/figures/IntelliJ_develop_six.png new file mode 100755 index 0000000000000000000000000000000000000000..2b1ce2cba1cdb82b7bd4d4df3d0a32230a98b631 Binary files /dev/null and b/figures/IntelliJ_develop_six.png differ diff --git a/figures/IntelliJ_step_applyPlugins.png b/figures/IntelliJ_step_applyPlugins.png deleted file mode 100755 index 7e704d09ce54a41719d29064b2c669fd56c30874..0000000000000000000000000000000000000000 Binary files a/figures/IntelliJ_step_applyPlugins.png and /dev/null differ diff --git a/figures/IntelliJ_step_finish.png b/figures/IntelliJ_step_finish.png deleted file mode 100755 index 44cc8c95c80e95d9b7f9cbb17a83e622c5eea8f6..0000000000000000000000000000000000000000 Binary files a/figures/IntelliJ_step_finish.png and /dev/null differ diff --git a/figures/IntelliJ_step_firstNext.png b/figures/IntelliJ_step_firstNext.png deleted file mode 100755 index 5afc90502779f13f08c5e55dca4ea8039161aaa6..0000000000000000000000000000000000000000 Binary files a/figures/IntelliJ_step_firstNext.png and /dev/null differ diff --git a/figures/IntelliJ_step_generate.png b/figures/IntelliJ_step_generate.png deleted file mode 100755 index d3df99e707c9ee1428175b808cd607b8d9e6ab09..0000000000000000000000000000000000000000 Binary files a/figures/IntelliJ_step_generate.png and /dev/null differ diff --git a/figures/IntelliJ_step_generateSuccess.png b/figures/IntelliJ_step_generateSuccess.png deleted file mode 100755 index ddcdbea9dfea87ea01f5c22d8574c520c776c1b0..0000000000000000000000000000000000000000 Binary files a/figures/IntelliJ_step_generateSuccess.png and /dev/null differ diff --git a/figures/IntelliJ_step_newFile.png b/figures/IntelliJ_step_newFile.png deleted file mode 100755 index 92d374990e0fc747b09d1781ac9c3063786da389..0000000000000000000000000000000000000000 Binary files a/figures/IntelliJ_step_newFile.png and /dev/null differ diff --git a/figures/IntelliJ_step_pluginsOk.png b/figures/IntelliJ_step_pluginsOk.png deleted file mode 100755 index b479e4864f5442e57aa234cf8fdc8145eecffac6..0000000000000000000000000000000000000000 Binary files a/figures/IntelliJ_step_pluginsOk.png and /dev/null differ diff --git a/figures/IntelliJ_step_project.png b/figures/IntelliJ_step_project.png deleted file mode 100755 index faef2165c13200eed99374f804945cdf772ac0da..0000000000000000000000000000000000000000 Binary files a/figures/IntelliJ_step_project.png and /dev/null differ diff --git a/figures/IntelliJ_step_upload.png b/figures/IntelliJ_step_upload.png deleted file mode 100755 index 09ec6e8a91ed92b1935ce295bd06df1c1d1e3e28..0000000000000000000000000000000000000000 Binary files a/figures/IntelliJ_step_upload.png and /dev/null differ diff --git a/figures/pic-generator-napi-frame.png b/figures/pic-generator-napi-frame.png new file mode 100755 index 0000000000000000000000000000000000000000..1f587e8b022ecf9b382a1bc201436bd74be8be46 Binary files /dev/null and b/figures/pic-generator-napi-frame.png differ diff --git a/figures/pic-plug-in-gen-c++.png b/figures/pic-plug-in-gen-c++.png index ff1c12ea2648a1542a75540e190b75db6dd856cb..ccfd5583cb715f8a11e004f94d86557eac2a4769 100755 Binary files a/figures/pic-plug-in-gen-c++.png and b/figures/pic-plug-in-gen-c++.png differ diff --git a/figures/pic-plug-in-gen-sucess.png b/figures/pic-plug-in-gen-sucess.png index 7d766c697677cfa5b88dac8be1a69b6318246445..3f1bfc5ffc0840c7a0783d22aa74aba444d53218 100755 Binary files a/figures/pic-plug-in-gen-sucess.png and b/figures/pic-plug-in-gen-sucess.png differ diff --git a/src/generator/README_zh.md b/src/generator/README_zh.md index a3202496d6206cb58831fbbf27fd1c3ba90d90f9..af040dd26928e15b01d588dcbe60a1e7a4cb3eb1 100644 --- a/src/generator/README_zh.md +++ b/src/generator/README_zh.md @@ -1,42 +1,38 @@ -# IDEA插件开发环境配置 - -基础环境要求: -JDK 11 ,IDEA Community 2021.3.3 - -1.下载IDEA Community 与 JDK11 配置好环境 -点击 https://www.jetbrains.com/idea/download/ 下载Community版本,并完成安装。 - - -2.打开IDEA Community 应用程序。 -依次点击项目File>Open 选择napi_generator/src/generator项目文件夹。 -![](../../figures/IntelliJ_env_config_open_proj.png) - -3.项目配置 -项目打开完成,点击File>Project Structure -![](../../figures/IntelliJ_env_proj_structure.png) - - -4.配置Modules. -Project Settings > Modules 新建Modules.点击上方“-”删除原有的Modules,“+”选择 New Modules。 -![](../../figures/IntelliJ_env_Proj_Module.png) - - -5.配置Module SDK. -在New Modules对话框中,选择IntelliJ Platform Plugin。若为首次环境配置,请在Module SDK 下拉框中点击 Add IntelliJ Platform Plugin SDK 选择IDEA Community安装目录,点击OK,在Select Internal Java Platform 选择 JAVA SDK 11(213版本只支持 11) -![](../../figures/IntelliJ_env_Proj_Module_New.png) - -6.配置Root Content. -在上图界面点击Next,选择Content root:为napi_generator/src/generator文件夹,module name会自动变为generator,若出现提示已存在是否覆盖的提示,请点“是”完成配置。 -![](../../figures/IntelliJ_env_module_root.png) - - -7.配置完成Modules后,若在SDKs中无相应JDK和Plugin SDK,请点击+号分别添加 Add Java JDK和Add Intellij PlantForm Plugin SDK,Java JDK为java11的安装目录,Plugin SDK为 IDEA Community 2021.3.3的安装目录。 -![](../../figures/IntelliJ_env_config_SDKs.png) - -8.若完成步骤7配置,点击OK完成配置。Rebuild项目,若IDEA依然不能点击右上角的运行。请重新配置一次Modules。 - -9.项目运行成功后,会另起一个IDEA应用程序。插件运行在IDEA中,只需要新建一个Grandle Project,添加相应的TS文件到项目文件夹里面,就可以右击文件,选择Generate napi Frame出现插件主界面进行相应操作。 - -10.在Deveco stdio中安装插件。 -请在IDEA Community中依次点击Build>Prepare Plugin Module " " for development"生成jar包(jar一般生成在generator目录下)。打开DevEco Studio 工具,点击File>settings>plugin。点击右方齿轮选择install plugin from disk选择jar包,点击确定完成。重新IDE完成安装 +# IDEA插件开发环境配置 + +基础环境要求: +JDK 11 ,IDEA Community 2021.3.3 + +1.下载IDEA Community 与 JDK11 配置好环境。 +点击 https://www.jetbrains.com/idea/download/ 下载Community版本,并完成安装。 + +2.打开IDEA Community 应用程序。 +依次点击项目File>Open 选择napi_generator/src/generator项目文件夹。 +![](../../figures/IntelliJ_env_config_open_proj.png) + +3.项目配置 +项目打开完成,点击File>Project Structure。 +![](../../figures/IntelliJ_env_proj_structure.png) + +4.配置Modules. +Project Settings > Modules 新建Modules.点击上方“-”删除原有的Modules,“+”选择 New Modules。 +![](../../figures/IntelliJ_env_Proj_Module.png) + +5.配置Module SDK. +在New Modules对话框中,选择IntelliJ Platform Plugin。若为首次环境配置,请在Module SDK 下拉框中点击 Add IntelliJ Platform Plugin SDK 选择IDEA Community安装目录,点击OK,在Select Internal Java Platform 选择 JAVA SDK 11(213版本只支持 11) +![](../../figures/IntelliJ_env_Proj_Module_New.png) + +6.配置Content root. +在上图界面点击Next,选择Content root:为napi_generator/src/generator文件夹,module name会自动变为generator,若出现提示已存在是否覆盖的提示,请点“是”完成配置。 +![](../../figures/IntelliJ_env_module_root.png) + +7.配置完成Modules后,若在SDKs中无相应JDK和Plugin SDK,请点击+号分别添加 Add Java JDK和Add Intellij PlantForm Plugin SDK,Java JDK为java11的安装目录,Plugin SDK为 IDEA Community 2021.3.3的安装目录。 +![](../../figures/IntelliJ_env_config_SDKs.png) + +8.若完成步骤7配置,点击OK完成配置。Rebuild项目,若IDEA依然不能点击右上角的运行。请重新配置一次Modules。 + +9.项目运行成功后,会另起一个IDEA应用程序。插件运行在IDEA中,只需要新建一个Grandle Project,添加相应的TS文件到项目文件夹里面,就可以右击文件,选择Generate Napi Frame出现插件主界面进行相应操作。 + +10.在Deveco stdio中安装插件。 +请在IDEA Community中依次点击Build>Prepare Plugin Module " " for development"生成jar包(jar一般生成在generator目录下)。打开DevEco Studio 工具,点击File>settings>plugin。点击右方齿轮选择install plugin from disk选择jar包,点击确定完成。重新IDE完成安装 ![](../../figures/IntelliJ_env_deveco_install.png) \ No newline at end of file diff --git a/test/storytest/README_ZH.md b/test/storytest/README_ZH.md index 53eb4faac1a6a3bed1b0f4eef733efbe9a1fb8ab..066bd307636fa27621f051b08b138427cf59dc52 100755 --- a/test/storytest/README_ZH.md +++ b/test/storytest/README_ZH.md @@ -17,7 +17,7 @@ │ | | ├── test_number # ts文件输入number测试用例 │ | | ├── test_string # ts文件输入string测试用例 │ | | └── test.py # 用例执行脚本 - | | └── unittest # 单元测试用例 + | | └── unittest # 单元测试用例 ## 软件环境准备 diff --git a/test/unittest/README_ZH .md b/test/unittest/README_ZH .md index a09bc9f94106566062d43f4474287cf9ef95e850..7b4028aee6accb39d73dd4944cd5f7ed941eb865 100755 --- a/test/unittest/README_ZH .md +++ b/test/unittest/README_ZH .md @@ -6,11 +6,11 @@ ## 目录 - ├── napi_generator # NAPI框架代码生成工具 - │ ├── src # 工具源码 - │ ├── ... # 其他文件夹 - │ ├── test # 测试用例 - | | ├── unittest # 单元测试代码 + ├── napi_generator # NAPI框架代码生成工具 + │ ├── src # 工具源码 + │ ├── ... # 其他文件夹 + │ ├── test # 测试用例 + | | ├── unittest # 单元测试代码 │ | | ├── analyze.test.js #执行gen/analyze目录下函数测试用例 │ | | ├── basic.d.ts* #基础函数模板 │ | | ├── extend.test.js* #执行gen/extend目录下函数测试用例