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..5e2a15cfc5fd58571f04c096326b4b78df54dbc3 100755 --- a/docs/DEVELOP_ZH.md +++ b/docs/DEVELOP_ZH.md @@ -1,106 +1,164 @@ -# 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/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/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_generator-linux可执行文件复制到napi_generator/napi_vs_plugin/src/目录下,执行命令如下: + + cp napi_generator-linux napi_vs_plugin/src/ + +2.在napi_generator/napi_vs_plugin/src目录下执行命令: + + npm i + +3.在napi_generator/napi_vs_plugin/src目录下执行命令: + + npm i typescript + +4.在napi_generator/napi_vs_plugin/src目录下执行命令: + + npm i vsce + +5.在napi_generator/napi_vs_plugin/src目录下执行命令: + + npx vsce package + + 每个选项都选择y,然后回车,最终会在当前目录下打包生成一个插件gnapi-0.0.1.vsix。结果如下: + + harmony@Ubuntu-64:~/napi/napi_generator_5/napi_vs_plugin/src$ npx vsce package + WARNING A 'repository' field is missing from the 'package.json' manifest file. + Do you want to continue? [y/N] y + WARNING Using '*' activation is usually a bad idea as it impacts performance. + More info: https://code.visualstudio.com/api/references/activation-events#Start-up + Do you want to continue? [y/N] y + WARNING LICENSE.md, LICENSE.txt or LICENSE not found + Do you want to continue? [y/N] y + This extension consists of 3370 files, out of which 1627 are JavaScript files. For performance reasons, you should bundle your extension: https://aka.ms/vscode-bundle-extension . You should also exclude unnecessary files by adding them to your .vscodeignore: https://aka.ms/vscode-vscodeignore + DONE Packaged: /home/harmony/napi/napi_generator_5/napi_vs_plugin/src/gnapi-0.0.1.vsix (3370 files, 44.42MB) + +#### Windows + +1.将napi_generator目录下的napi_generator-win.exe可执行文件复制到napi_generator/napi_vs_plugin/src/目录下。 + +2.在napi_generator/napi_vs_plugin/src目录下执行命令: + + npm i + +3.在napi_generator/napi_vs_plugin/src目录下执行命令: + + npm i typescript + +4.在napi_generator/napi_vs_plugin/src目录下执行命令: + + npm i vsce + +5.在napi_generator/napi_vs_plugin/src目录下执行命令: + + npx vsce package + + 每个选项都选择y,然后回车,最终会在当前目录下打包生成一个插件gnapi-0.0.1.vsix。结果如下: + + E:\napi_generator\napi_generator-master\napi_vs_plugin\src>npx vsce package + WARNING A 'repository' field is missing from the 'package.json' manifest file. + Do you want to continue? [y/N] y + WARNING Using '*' activation is usually a bad idea as it impacts performance. + More info: https://code.visualstudio.com/api/references/activation-events#Start-up + Do you want to continue? [y/N] y + WARNING LICENSE.md, LICENSE.txt or LICENSE not found + Do you want to continue? [y/N] y + This extension consists of 3467 files, out of which 1692 are JavaScript files. For performance reasons, you should bundle your extension: https://aka.ms/vscode-bundle-extension . You should also exclude unnecessary files by adding them to your .vscodeignore: https://aka.ms/vscode-vscodeignore + DONE Packaged: E:\napi_generator\napi_generator-master\napi_vs_plugin\src\gnapi-0.0.1.vsix (3467 files, 42.3MB) + +### IntelliJ插件开发说明 + +#### 环境说明 + +系统:建议Windows 10 + +#### 开发步骤 + +1.将napi_generator目录下的可执行文件分别放置在napi_generator\src\generator\resources\cmds目录下对应系统的文件夹下。 + +2.通过IntelliJ IDEA打开napi_generator/src/generator目录下的代码。 + +![](../figures/IntelliJ_develop_one.png) + +3.基础环境配置按照IDEA插件开发环境配置操作,确保项目可运行,且.d.ts文件可正常生成框架代码。 + +[IDEA插件开发环境配置](https://gitee.com/openharmony/napi_generator/blob/master/src/generator/README_zh.md) + +4.点击Intellij IDEA工具右上角Built Project按钮,等待工程built完成。 + +![](../figures/IntelliJ_env_built_pro.png) + +5.在IDEA Community中依次点击Build>Prepare All Plugin Modules for development",然后在Select Modules框中点击ok,jar包生成完成后在工具右下角提示jar包生成成功,且包含jar包存放位置。 + +![](../figures/IntelliJ_env_built_jar.png) + +![](../figures/IntelliJ_env_select_moudles.png) + +![](../figures/IntelliJ_env_built_jar_success.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..f87eef76c2c1b03affc13609c914029a85654ac2 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) 下载文件说明如下: @@ -52,24 +51,44 @@ napi_generator的可执行程序方式和插件方式都具有预检查的功能 ### 可执行程序使用方法 #### Linux -1) 将要转换的.d.ts文件放到任意目录下,建议放到可执行程序napi_generator-linux同级目录下,并且检查需要转换的d.ts文件中是否声明了import的d.ts文件,如果存在需要将import的d.ts文件也放入到待转换的d.ts文件相同的目录下。例如: +1.将要转换的.d.ts文件放到任意目录下,建议放到可执行程序napi_generator-linux同级目录下,并且检查需要转换的d.ts文件中是否声明了import的d.ts文件,如果存在需要将import的d.ts文件也放入到待转换的d.ts文件相同的目录下。此处新建out文件,用于存放生成框架代码。整体目录文件如下: - xudong@xudong:~/napi_tool$ ls - napi_generator-linux @ohos.napitest.d.ts basic.d.ts - xudong@xudong:~/napi_tool$ + harmony@Ubuntu-64:~/napi/napi_generator_5/examples/gen$ ls + basic.d.ts napi_generator-linux @ohos.napitest.d.ts out -2) 在终端中进入到之前可执行程序napi_generator-linux所在的目录,并运行napi_generator-linux,在napi_generator-linux后面要加参数-f,后面再加要对应的.d.ts文件名,如果不加参数-o,输出文件就默认在当前目录下。例如: +2.在终端中进入到之前可执行程序napi_generator-linux所在的目录,并运行napi_generator-linux。在napi_generator-linux后面要加参数-f,后面再加要对应的.d.ts文件名;然后添加参数-o,后面再加输出文件目录。若不添加参数-o,则输出文件默认存放在当前目录下。此处以添加参数-o为例,命令如下: - 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文件说在的目录下生成对应的文件。例如: + harmony@Ubuntu-64:~/napi/napi_generator_5/examples/gen$ ./napi_generator-linux -f @ohos.napitest.d.ts -o out + +3.运行成功后会在out目录下生成对应的文件。例如: + + harmony@Ubuntu-64:~/napi/napi_generator_5/examples/gen$ cd out/ + harmony@Ubuntu-64:~/napi/napi_generator_5/examples/gen/out$ ls + binding.gyp BUILD.gn napi_gen.log napitest.cpp napitest.h napitest_middle.cpp test.sh x_napi_tool.cpp x_napi_tool.h + +4.此外,工具还支持指定路径下.d.ts文件转换、同一目录下多个.d.ts文件同时转换、多级模块.d.ts文件转换等场景。 + +1)指定路径下.d.ts文件转换(可转换路径下所有.d.ts文件)。napi_generator-linux文件存放在~/napi/napi_generator_5/examples/gen目录下,.d.ts文件存放在~/napi/napi_generator_5/examples/ts目录下,框架代码转换过程如下: + + harmony@Ubuntu-64:~/napi/napi_generator_5/examples/gen$ ./napi_generator-linux -d '../ts' -o out + harmony@Ubuntu-64:~/napi/napi_generator_5/examples/gen$ cd out/ + harmony@Ubuntu-64:~/napi/napi_generator_5/examples/gen/out$ ls + binding.gyp BUILD.gn napi_gen.log power.cpp power.h power_middle.cpp test.sh x_napi_tool.cpp x_napi_tool.h + +2)同一目录下多个.d.ts文件同时转换。.../gen目录下存在两个.d.ts文件,分别为@ohos.napitest.d.ts和@ohos.power.d.ts,多个文件中间以“,”隔开,注意文件中namespace后的名称不可相同。框架代码转换过程如下: + + harmony@Ubuntu-64:~/napi/napi_generator_5/examples/gen$ ./napi_generator-linux -f @ohos.napitest.d.ts,@ohos.power.d.ts -o out + harmony@Ubuntu-64:~/napi/napi_generator_5/examples/gen$ cd out/ + harmony@Ubuntu-64:~/napi/napi_generator_5/examples/gen/out$ ls + binding.gyp BUILD.gn napi_gen.log napitest.cpp napitest.h napitest_middle.cpp power.cpp power.h power_middle.cpp test.sh x_napi_tool.cpp x_napi_tool.h + +3)多级模块.d.ts文件转换。.../gen目录下存在@ohos.napi_.test.A.d.ts文件,转换过程如下: + + harmony@Ubuntu-64:~/napi/napi_generator_5/examples/gen$ ./napi_generator-linux -f @ohos.napi_.test.A.d.ts -o out + harmony@Ubuntu-64:~/napi/napi_generator_5/examples/gen$ cd out/ + harmony@Ubuntu-64:~/napi/napi_generator_5/examples/gen/out$ ls + binding.gyp BUILD.gn napi_gen.log napitest.cpp napitest.h napitest_middle.cpp test.sh x_napi_tool.cpp x_napi_tool.h - 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,14 +107,29 @@ 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.运行成功后会在当前目录下生成对应的文件。例如: ![](../figures/pic-d-ts-transition.png) +4.此外,工具还支持指定路径下.d.ts文件转换、同一目录下多个.d.ts文件同时转换、多级模块.d.ts文件转换等场景。 + +1)指定路径下.d.ts文件转换(可转换路径下所有.d.ts文件)。napi_generator-win.exe文件存放在E:\napi_generator\napi_generator-master\examples\gen>目录下,.d.ts文件存放在E:\demo目录下。命令执行成功后,gen目录中生成对应的文件如上图所示。框架代码转换命令如下: + + E:\napi_generator\napi_generator-master\examples\gen>napi_generator-win.exe -d "E:\demo" + +2)同一目录下多个.d.ts文件同时转换。.../gen目录下存在两个.d.ts文件,分别为@ohos.napitest.d.ts和@ohos.power.d.ts,多个文件中间以“,”隔开,注意文件中namespace后的名称不可相同。框架代码转换命令如下: + + E:\napi_generator\napi_generator-master\examples\gen>napi_generator-win.exe -f @ohos.napitest.d.ts,@ohos.power.d.ts +![](../figures/pic-d-ts-files-transition.png) + +3)多级模块.d.ts文件转换。.../gen目录下存在@ohos.napi_.test.A.d.ts文件。命令执行成功后,gen目录中成功生成对应的文件,与指定路径下.d.ts文件转换效果图一致,转换命令如下: + + + E:\napi_generator\napi_generator-master\examples\gen>napi_generator-win.exe -f @ohos.napi_.test.A.d.ts #### Mac 方法步骤参考windows、Linux的使用方法。 @@ -106,79 +140,106 @@ 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) + +4.在VS Code中找到需要转换的.d.ts文件,并且检查需要转换的d.ts文件中是否声明了import的d.ts文件,如果存在需要将import的d.ts文件也放入到待转换的d.ts文件相同的目录下,例如: + +![](../figures/pic-plug-in-select-d-ts.png) + +5.鼠标在.d.ts上单击右键,选择“ Generate Napi Frame”选项,工具打开 Generate Napi Frame窗口。选择方式有.d.ts文件、文件夹两种方式,此处以.d.ts文件为例;选择接口文件文本框中默认填写.d.ts文件路径,此处不修改;生成框架路径文本框填写生成文件所放文件夹绝对路径;编译脚本路径文本框选填,此处不填写,然后点击ok。 + +![](../figures/pic-plug-in-gen-c++.png) + +![](../figures/pic-generator-napi-frame.png) - ![](../figures/pic-plug-in-gnapi.png) +6.转换成功工具右下角就会提示“Generated successfully”的信息,并且在.d.ts文件当前目录下生成对应文件,例如: -4. 在VS Code中找到需要转换的.d.ts文件,并且检查需要转换的d.ts文件中是否声明了import的d.ts文件,如果存在需要将import的d.ts文件也放入到待转换的d.ts文件相同的目录下,例如: +![](../figures/pic-plug-in-gen-sucess.png) - ![](../figures/pic-plug-in-select-d-ts.png) +7.此外,工具还支持指定路径下.d.ts文件转换、同一目录下多个.d.ts文件同时转换、多级模块.d.ts文件转换等场景。 -5. 鼠标在.d.ts上单击右键,选择.d.ts生成c++选项。 +1)指定路径下.d.ts文件转换(可转换路径下所有.d.ts文件)。Generate Napi Frame窗口中,选择方式修改为文件夹;选择接口文件文本框中填写待转换.d.ts文件路径,此处为E:\demo;生成框架路径填写生成文件所放路径,此处为项目当前路径;编译脚本路径选填,此处不填写,然后点击ok。Generate Napi Frame窗口填写与生成文件如下图所示: - ![](../figures/pic-plug-in-gen-c++.png) +![](../figures/pic-plug-in-gen-dir-sucess.png) -6. 转换成功就会提示“生成成功”的信息,并且在该目录下生成对应文件,例如: +2)同一目录下多个.d.ts文件同时转换。项目中存在@ohos.napitest.d.ts和@ohos.power.d.ts两个文件,且声明了import的d.ts文件。Generate Napi Frame窗口中,选择方式修改为.d.ts文件;选择接口文件文本框中填写待转换.d.ts文件,此处为“E:\napi_tool_new\@ohos.napitest.d.ts,E:\napi_tool_new\@ohos.power.d.ts”;生成框架路径填写生成文件所放路径,此处为项目当前路径;编译脚本路径选填,此处不填写,然后点击ok。Generate Napi Frame窗口填写与生成文件如下图所示: - ![](../figures/pic-plug-in-gen-sucess.png) +![](../figures/pic-plug-in-gen-files-sucess.png) - ![](../figures/pic-plug-in-gen-result.png) +3)多级模块.d.ts文件转换。项目中存在@ohos.napi_.test.A.d.ts文件,Generate Napi Frame窗口中,选择方为.d.ts文件;选择接口文件文本框中填写待转换.d.ts文件,此处为“E:\napi_tool_new\@ohos.napi_.test.A.d.ts”;生成框架路径填写生成文件所放路径,此处为项目当前路径;编译脚本路径选填,此处不填写,然后点击ok。Generate Napi Frame窗口填写与生成文件如下图所示: +![](../figures/pic-plug-in-gen-module-sucess.png) ### IntelliJ插件使用方法 + #### 依赖 系统:不限 -开发工具: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/DevEco_step_newFile.png) + +Ability Template选择Empty Ability,单击Next。 + +![](../figures/DevEco_step_firstNext.png) + +填写Project name、Save location,其他选项可不修改,单击Finish,新的工程就创建好了。 + +![](../figures/DevEco_step_finish.png) + +2.把需要转换的.d.ts文件放在DevEco stdio新建项目的src目录下,并且检查需要转换的d.ts文件中是否声明了import的d.ts文件,如果存在需要将import的d.ts文件也放入到待转换的d.ts文件相同的目录下。 + +![](../figures/DevEco_step_project.png) -![](../figures/IntelliJ_step_newFile.png) +3.安装插件,File->Settings->Plugins->Installed->Install Plugin from Disk...,选择下载的generator.jar,安装成功之后重启IDE。 -左侧栏选择Java,右侧默认选择Groovy,单击Next,继续单击Next,单击Finish,新的工程就创建好了。 +![](../figures/DevEco_step_pluginsOk.png) -![](../figures/IntelliJ_step_firstNext.png) +![](../figures/DevEco_step_applyPlugins.png) -2.复制本地napi_generator/test/unittest/basic.d.ts文件,进入IntelliJ新建项目中选中src粘贴,将basic.d.ts文件放入src目录。 +4.选择.d.ts文件,右键选择 Generate Napi Frame选项,工具弹出 Generate Napi Frame弹窗。接口文件文本框填写.d.ts文件路径;生成框架路径文本框填写转换后生成文件存放文件夹路径,此处为src下新增out文件夹,生成文件存放在out中;编译脚本路径默认填写不修改,点击ok。 -![](../figures/IntelliJ_step_upload.png) +![](../figures/DevEco_step_generate.png) -3.把需要转换的.d.ts文件放到项目中。 +![](../figures/DevEco_step_generate_ok.png) +5.执行结束后会在目录下生成对应的文件。 -![](../figures/IntelliJ_step_project.png) +![](../figures/DevEco_step_generateSuccess.png) -4.安装插件,File->Settings->Plugins->Installed->Install Plugin from Disk...,选择下载的generator.jar,安装成功之后重启IDE。 +6.此外,工具还支持指定路径下.d.ts文件转换、同一目录下多个.d.ts文件同时转换等场景。 -![](../figures/IntelliJ_step_pluginsOk.png) +1)指定路径下.d.ts文件转换(可转换路径下所有.d.ts文件)。Generate Napi Frame窗口中,接口文件文本框中填写待转换.d.ts文件路径,此处为E:\demo;生成框架路径填写生成文件所放路径,此处为E:\deveco_project\entry\src\out;编译脚本路径为E:\deveco_project\entry\src写,然后点击ok。Generate Napi Frame窗口填写与生成文件如下图所示: -![](../figures/IntelliJ_step_applyPlugins.png) +![](../figures/DevEco_converse_dir.png) -5.选择.d.ts文件,右键选择Generate NAPI Frame选项,生成文件。 +![](../figures/DevEco_converse_dir_succ.png) -![](../figures/IntelliJ_step_generate.png) +2)同一目录下多个.d.ts文件同时转换。项目中存在@ohos.napitest.d.ts和@ohos.power.d.ts两个文件,且声明了import的d.ts文件。Generate Napi Frame窗口中,接口文件文本框中填写待转换.d.ts文件夹,此处为“E:\deveco_project\entry\src”;生成框架路径填写生成文件所放路径,此处为E:\deveco_project\entry\src\out;编译脚本路径为E:\deveco_project\entry\src写,然后点击ok。Generate Napi Frame窗口填写与生成文件如下图所示: -6.执行结束后会在目录下生成对应的文件。 +![](../figures/DevEco_converse_file.png) -![](../figures/IntelliJ_step_generateSuccess.png) +![](../figures/DevEco_converse_file_succ.png) ### 注意 diff --git a/figures/DevEco_converse_dir.png b/figures/DevEco_converse_dir.png new file mode 100755 index 0000000000000000000000000000000000000000..fde09c3b165b9bcce8466366fabc35bfd04760f4 Binary files /dev/null and b/figures/DevEco_converse_dir.png differ diff --git a/figures/DevEco_converse_dir_succ.png b/figures/DevEco_converse_dir_succ.png new file mode 100755 index 0000000000000000000000000000000000000000..1ecaec55f03e73e61e1a52b93d972b5a7db47166 Binary files /dev/null and b/figures/DevEco_converse_dir_succ.png differ diff --git a/figures/DevEco_converse_file.png b/figures/DevEco_converse_file.png new file mode 100755 index 0000000000000000000000000000000000000000..299e98d8fa7ebc663987f68dc452fab9b3112b59 Binary files /dev/null and b/figures/DevEco_converse_file.png differ diff --git a/figures/DevEco_converse_file_succ.png b/figures/DevEco_converse_file_succ.png new file mode 100755 index 0000000000000000000000000000000000000000..b316b6945500b95fac32e2ba9d45eb261cd7e3e8 Binary files /dev/null and b/figures/DevEco_converse_file_succ.png differ 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..d2b10a20689788e88622ea9931d07c0e8051534a 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/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_one.png b/figures/IntelliJ_develop_one.png index adda2da8574495519aa9ec22986309d76f23c9ef..b6df697a50d7710a00f912d541dc705a70a19153 100644 Binary files a/figures/IntelliJ_develop_one.png and b/figures/IntelliJ_develop_one.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_develop_two.png b/figures/IntelliJ_develop_two.png index 3eebe7cb90d9d3c6300baf29c27249f72cccdc30..20e103f4d5286735273cb74a1dafb8f7d8508fbc 100644 Binary files a/figures/IntelliJ_develop_two.png and b/figures/IntelliJ_develop_two.png differ diff --git a/figures/IntelliJ_env_built_jar.png b/figures/IntelliJ_env_built_jar.png new file mode 100755 index 0000000000000000000000000000000000000000..c58a2e7c8212ca39f4fc83f8df3d5b682a2c995d Binary files /dev/null and b/figures/IntelliJ_env_built_jar.png differ diff --git a/figures/IntelliJ_env_built_jar_success.png b/figures/IntelliJ_env_built_jar_success.png new file mode 100755 index 0000000000000000000000000000000000000000..8a523e27f4636bb2832b62f4e04a282879e06e92 Binary files /dev/null and b/figures/IntelliJ_env_built_jar_success.png differ diff --git a/figures/IntelliJ_env_built_pro.png b/figures/IntelliJ_env_built_pro.png new file mode 100755 index 0000000000000000000000000000000000000000..706d14a767e5a8a0d7d680fab8fcfd99c7b6b1ee Binary files /dev/null and b/figures/IntelliJ_env_built_pro.png differ diff --git a/figures/IntelliJ_env_configurations.png b/figures/IntelliJ_env_configurations.png new file mode 100755 index 0000000000000000000000000000000000000000..b7b59e971a29f7569dc256e896aee5d303b9f917 Binary files /dev/null and b/figures/IntelliJ_env_configurations.png differ diff --git a/figures/IntelliJ_env_new_project.png b/figures/IntelliJ_env_new_project.png new file mode 100755 index 0000000000000000000000000000000000000000..d0be28037694699028c411ce5f8fa81008ef4435 Binary files /dev/null and b/figures/IntelliJ_env_new_project.png differ diff --git a/figures/IntelliJ_env_plugin_newpro.png b/figures/IntelliJ_env_plugin_newpro.png new file mode 100755 index 0000000000000000000000000000000000000000..6613616cc4eb198f05d1e554396bb5fd1bf4bb0b Binary files /dev/null and b/figures/IntelliJ_env_plugin_newpro.png differ diff --git a/figures/IntelliJ_env_run_debug.png b/figures/IntelliJ_env_run_debug.png new file mode 100755 index 0000000000000000000000000000000000000000..2a66273f815c18a2c616a37d376937b640e679eb Binary files /dev/null and b/figures/IntelliJ_env_run_debug.png differ diff --git a/figures/IntelliJ_env_select_moudles.png b/figures/IntelliJ_env_select_moudles.png new file mode 100755 index 0000000000000000000000000000000000000000..b1b1295736cd98f8274014b5c5764c439930fd5b Binary files /dev/null and b/figures/IntelliJ_env_select_moudles.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-d-ts-files-transition.png b/figures/pic-d-ts-files-transition.png new file mode 100755 index 0000000000000000000000000000000000000000..2c32429acb25833d8534c297c94ce776e2a5defe Binary files /dev/null and b/figures/pic-d-ts-files-transition.png differ diff --git a/figures/pic-d-ts-transition.png b/figures/pic-d-ts-transition.png index 6bcf99a4fd8ed44b235e6835878c96109f0fa8d5..8df892e392d34971e9ada2d320a2b2238d1fa851 100755 Binary files a/figures/pic-d-ts-transition.png and b/figures/pic-d-ts-transition.png differ diff --git a/figures/pic-generator-napi-frame.png b/figures/pic-generator-napi-frame.png new file mode 100755 index 0000000000000000000000000000000000000000..06b5bdbc1ec9b3dcb5b6617724463563a587b0af 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..66229089a33b35e954c540b6db5df71a8193a94f 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-dir-sucess.png b/figures/pic-plug-in-gen-dir-sucess.png new file mode 100755 index 0000000000000000000000000000000000000000..f7c23a1f1c6eefb5de9a05af949e2925d618e99b Binary files /dev/null and b/figures/pic-plug-in-gen-dir-sucess.png differ diff --git a/figures/pic-plug-in-gen-files-sucess.png b/figures/pic-plug-in-gen-files-sucess.png new file mode 100755 index 0000000000000000000000000000000000000000..1495bcc3a178846772f3b774ccb7f577454865c8 Binary files /dev/null and b/figures/pic-plug-in-gen-files-sucess.png differ diff --git a/figures/pic-plug-in-gen-module-sucess.png b/figures/pic-plug-in-gen-module-sucess.png new file mode 100755 index 0000000000000000000000000000000000000000..77d037b4dcf4bfd99f3afe5ac2a816298a784623 Binary files /dev/null and b/figures/pic-plug-in-gen-module-sucess.png differ diff --git a/figures/pic-plug-in-gen-sucess.png b/figures/pic-plug-in-gen-sucess.png index 7d766c697677cfa5b88dac8be1a69b6318246445..066faf8a7c5194868664502dfa8ae7e6fcff677d 100755 Binary files a/figures/pic-plug-in-gen-sucess.png and b/figures/pic-plug-in-gen-sucess.png differ diff --git a/figures/pic-plug-in-search.png b/figures/pic-plug-in-search.png index f1e0ed1396ff4511806056770aee956a9d840ae5..e37db358f625276a615fdcec2ac2267c4545d3ae 100755 Binary files a/figures/pic-plug-in-search.png and b/figures/pic-plug-in-search.png differ diff --git a/figures/pic-plug-in-select-d-ts.png b/figures/pic-plug-in-select-d-ts.png index 46723ac8fa25bc9edc6864b102d70b1abd949beb..432ce66c9989a43415c2e19636239aa43eb5279b 100755 Binary files a/figures/pic-plug-in-select-d-ts.png and b/figures/pic-plug-in-select-d-ts.png differ diff --git a/figures/pic-plug-in-select.png b/figures/pic-plug-in-select.png index d6e4af228aa25ba9b778effd2b5c944e1cb57f02..ace010678d2e332bf6303994787818ae167ac8cc 100755 Binary files a/figures/pic-plug-in-select.png and b/figures/pic-plug-in-select.png differ diff --git a/src/generator/README_zh.md b/src/generator/README_zh.md index a3202496d6206cb58831fbbf27fd1c3ba90d90f9..7f5e8f8317ecb808e78bdb6726942b8141599da9 100644 --- a/src/generator/README_zh.md +++ b/src/generator/README_zh.md @@ -1,42 +1,65 @@ -# 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完成安装 -![](../../figures/IntelliJ_env_deveco_install.png) \ No newline at end of file +# IDEA插件开发环境配置 + +## 基础环境准备 + +### 约束 +JDK 11 ,IDEA Community 2021.3.3 + +### 步骤 + +1.将napi_generator目录下的可执行文件分别放置在napi_generator\src\generator\resources\cmds目录下对应系统的文件夹下。 + +2.下载IDEA Community 与 JDK11 配置好环境。 +点击 https://www.jetbrains.com/idea/download/ 下载Community版本,并完成安装。 + +3.打开IDEA Community 应用程序。 +依次点击项目File>Open 选择napi_generator/src/generator项目文件夹。 +![](../../figures/IntelliJ_env_config_open_proj.png) + +4.项目配置 +项目打开完成,点击File>Project Structure。 +![](../../figures/IntelliJ_env_proj_structure.png) + +5.配置Modules +Project Settings > Modules 新建Modules。点击上方“-”删除原有的Modules,然后点击“+”选择 New Module。 +![](../../figures/IntelliJ_env_Proj_Module.png) + +6.配置Module SDK. +在New Module对话框中,选择IntelliJ Platform Plugin。若为首次环境配置,请在Module SDK 下拉框中点击 Add IntelliJ Platform Plugin SDK 选择IDEA Community安装目录,点击OK,在Select Internal Java Platform 选择 JAVA SDK 11(213版本只支持 11),点击New Module对话框中Next。 +![](../../figures/IntelliJ_env_Proj_Module_New.png) + +7.配置Content root. + +Content root选择napi_generator/src/generator文件夹,module name会自动变为generator。点击Finish,若出现提示已存在是否覆盖的提示,请点“Yes”完成配置。 +![](../../figures/IntelliJ_env_module_root.png) + +8.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) + +9.若完成步骤7配置,点击OK完成配置。Rebuild项目,若IDEA不能点击右上角的运行,点击Plugin后下三角选择Edit Configurations...选项,Run/Debug Configurations框中Use classpath of moudle选择generator,点击ok,等待安装完成,即可点击运行按钮。若IDEA依然不能点击右上角的运行,请重复以上全部操作。 + +![](../../figures/IntelliJ_env_configurations.png) + +![](../../figures/IntelliJ_env_run_debug.png) + +## 配置开发调试环境 + +1.IntelliJ IDEA工具进入上述generator项目页面,执行右上角的run。 + +![](../../figures/IntelliJ_develop_two.png) + +2.IntelliJ IDEA会自动拉起一个应用程序,首次运行若没有项目,可选择Welcome to IntelliJ IDEA框中点击New Project新建项目。然后在New Project框中左侧选择Gradle,右侧Project SDK选择11,点击next;根据需要修改Location,最后点击Finish,完成配置。 + +![](../../figures/IntelliJ_env_plugin_newpro.png) + +![](../../figures/IntelliJ_env_new_project.png) + +3.在新打开项目中,将.d.ts文件放入untitled\src\main\resources路径下。并且检查需要转换的d.ts文件中是否声明了import的d.ts文件,如果存在需要将import的d.ts文件也放入到untitled\src\main\resources路径下。选择.d.ts文件,右键选择generate Napi Frame选项,工具打开generate Napi Frame弹窗。接口文件路径默认填写,此处不修改;生成框架路径默认填写,此处修改为新增out文件夹下;编译脚本路径默认填写,不修改。点击ok,生成文件。 + +![](../../figures/IntelliJ_develop_four.png) + +![](../../figures/IntelliJ_develop_six.png) + +4.执行结束后会在目录下生成对应的文件。 + +![](../../figures/IntelliJ_develop_five.png) \ No newline at end of file