Adjust directory structure
Signed-off-by: sunzhongyi <sunzhongyi@kaihongdigi.com>
0
napi_tool/.idea/.gitignore → .idea/.gitignore
generated
vendored
0
napi_tool/.idea/misc.xml → .idea/misc.xml
generated
0
napi_tool/.idea/vcs.xml → .idea/vcs.xml
generated
153
README.md
@ -1,19 +1,148 @@
|
||||
# assist_tools
|
||||
# napi_tool
|
||||
|
||||
#### Description
|
||||
This warehouse is used to incubate the assist tools of openharmony system, so that developers can improve development efficiency.Currently NAPI framework code generation tool has been implemented.Other similar tools can be incubated in this warehouse.
|
||||
## Introduction
|
||||
This paper mainly introduces the NAPi framework code generation tool, which can generate NAPi framework code, business code framework and designed.the GN file according to the TS interface file in the path specified by the user. So developers need to focus on Nodejs related grammar framework layer, interface between c + + with JS type conversion, data type conversion, etc.. This tool is mainly used in the scenario of JS application calling NaPi interface, can focus on business logic implementation, Thus, the development efficiency can be greatly improved. Currently, the tool supports command line and VScode plug-in.
|
||||
|
||||
## Software architecture
|
||||
![](figures/pic-frm-en.png)
|
||||
|
||||
## Directory Structure
|
||||
|
||||
#### Directory Structure
|
||||
```
|
||||
/assist_tools/
|
||||
├── napi_tool # NAPI framework code generation tool
|
||||
│ ├── doc # Current capability and version planning
|
||||
│ ├── image # image resource
|
||||
│ ├── output # Executable program and plug-in program corresponding to the tool
|
||||
│ ├── code # Source code of tool
|
||||
│ └── README # Instructions of tool
|
||||
│ ├── docs # Plan the current tool capabilities and versions
|
||||
│ ├── figures # Image resource file
|
||||
│ ├── code # Tool source
|
||||
| | ├── tool_code # Tool source
|
||||
│ | ├── gen
|
||||
│ | |── analyze # Parser
|
||||
│ │ |── extend # Extension module, including GN file generation, Linux environment adaptation code, etc
|
||||
│ │ |── generate # Generator
|
||||
│ │ └── tools # Public module code, including message body check, file read and write, regular expression
|
||||
│ | └── test # Plug-in test cases
|
||||
| | └──ts_test # Example ts files required by the tool
|
||||
│ └── README
|
||||
└──README
|
||||
```
|
||||
|
||||
#### Repositories Involved
|
||||
no
|
||||
### code directory source code introduction
|
||||
This directory is the source code corresponding to the NAPI framework code generation tool, developers can be based on this code for secondary development.
|
||||
|
||||
## Software environment preparation
|
||||
|
||||
System: Ubuntu 20.04 or windows 10 is recommended
|
||||
|
||||
Dependent version: vscode 1.62.0
|
||||
|
||||
## Development description
|
||||
|
||||
Developers can use the source code to compile and package the corresponding executable files and plug-ins for type conversion between JS and C + +. The development instructions of executable files and plug-ins are as follows:
|
||||
|
||||
### Source code
|
||||
|
||||
Through the command: git clone git@gitee.com :openharmony-sig/assist_ tools.git to download the corresponding source code.
|
||||
|
||||
### pack
|
||||
|
||||
#### Executable file development instructions
|
||||
1.Install pkg :execute the command sudo npm i -g pkg
|
||||
|
||||
2.Package three versions : execute the command pkg vscode_plugin/gnapi/gen/cmd_gen.js
|
||||
|
||||
After performing the preceding steps,ou can generate Windows, Linux, and MAC executable programs in the Gen directory:cmd_gen-win.exe、cmd_gen-linux、cmd_gen-macos.
|
||||
|
||||
#### Plug-in development Instructions
|
||||
1. Install yo : execute the command npm install -g yo generator-code.
|
||||
|
||||
2. Use yo : execute the command yo code,gnapi is a plug-in code framework generated by Yo Code, in which gnAPI/Gen directory is the source code of the automatic generation of NAPI program we developed.
|
||||
|
||||
![](figures/pic-gen-source-code.png)
|
||||
|
||||
3. Run npm i vsce in the napi_generator/vscode_plugin/gnapi directory.
|
||||
|
||||
4. Execute the command./node_modules/vsce/vsce package command,The final package generates a plugin, gnapI-0.0.1.vsix.
|
||||
|
||||
![](figures/pic-gen-vsix.png)
|
||||
|
||||
## instructions
|
||||
|
||||
1. Copy the Windows executable program cmd_gen-win.exe from the gen directory to the corresponding directory. You do not need to install the program.
|
||||
2. Copy the Linux executable program cmd_gen-linux from the gen directory to the corresponding directory, and run it directly on the terminal.
|
||||
|
||||
### Usage
|
||||
|
||||
#### Windows
|
||||
|
||||
1) The.d.ts files to be converted should be placed in any directory. It is recommended to put them in the same directory as the executable program cmd_gen-win.exe, for example:
|
||||
|
||||
![](figures/pic-d-ts-location.png)
|
||||
|
||||
2) Right-click Windows Start menu, click Run, enter CMD, and click OK.
|
||||
|
||||
![](figures/pic-cmd.png)
|
||||
|
||||
3) In the command line interface (CLI), go to the directory where the previous executable program cmd_gen-win.exe resides and run cmd_gen-win.exe. After cmd_gen-win.exe, the corresponding.
|
||||
|
||||
![](figures/pic-cmd-execute.png)
|
||||
|
||||
4) After successful operation, the corresponding file will be generated in the directory where the. D. ts file says, for example:
|
||||
|
||||
![](figures/pic-d-ts-transition.png)
|
||||
|
||||
#### Linux
|
||||
|
||||
1) Put the.d.ts files to be converted in any directory. It is recommended to put them in the same directory as the executable program cmd_gen-linux, for example:
|
||||
|
||||
![](figures/pic-d-ts-location-linux.png)
|
||||
|
||||
2) In the terminal, go to the directory where the previous executable program cmd_gen-linux resides and run cmd_gen-linux. After cmd_gen-linux, the corresponding. D. s file name, for example:
|
||||
|
||||
![](figures/pic-cmd-execute-linux.png)
|
||||
|
||||
3) After successful operation, the corresponding file will be generated in the directory where the. D. ts file says, for example:
|
||||
|
||||
![](figures/pic-d-ts-transition-linux.png)
|
||||
|
||||
#### Mac
|
||||
Method Step For details about how to use Windows and Linux
|
||||
|
||||
## Plug-in usage
|
||||
### Instruction
|
||||
Visual Studio Code version 1.62.0 or later
|
||||
|
||||
### Steps
|
||||
|
||||
1) Open vscode and select plug-in installation in the left sidebar.
|
||||
|
||||
![](figures/pic-plug-in-search.png)
|
||||
|
||||
2) Click the three buttons above, select the install from VSIX option, then select the gnapI-0.0.1. VSIX plug-in file you just generated, and click Install.
|
||||
|
||||
![](figures/pic-plug-in-select.png)
|
||||
|
||||
3) After installation, the gnapi plugin should be visible in vscode's plugin manager.
|
||||
|
||||
![](figures/pic-plug-in-gnapi.png)
|
||||
|
||||
4) Find the.d.ts file to convert in vscode, for example:
|
||||
|
||||
![](figures/pic-plug-in-select-d-ts.png)
|
||||
|
||||
5) Right click on.d.ts and select.d.ts to generate c++ options.
|
||||
|
||||
![](figures/pic-plug-in-gen-c++.png)
|
||||
|
||||
6) The corresponding files will be generated in this directory, for example:
|
||||
|
||||
![](figures/pic-plug-in-gen-result.png)
|
||||
|
||||
## Matters needing attention
|
||||
The examples above are for Windows. The methods for Linux and MAC are similar.
|
||||
|
||||
## Participate in the contribution
|
||||
|
||||
Not yet.
|
||||
|
||||
## Related to the storehouse
|
||||
|
||||
Not yet.
|
148
README_ZH.md
@ -1,23 +1,147 @@
|
||||
# assist_tools
|
||||
# napi_tool
|
||||
|
||||
#### 仓名
|
||||
assist_tools
|
||||
#### 简介
|
||||
此仓用于孵化OpenHarmony系统的辅助工具,以便开发者提升开发效率。当前已实现的工具有NAPI框架代码生成工具,后续其他类似工具均可在此仓孵化。
|
||||
## 概述
|
||||
本文主要介绍NAPI框架代码生成工具,它可以根据用户指定路径下的ts接口文件一键生成NAPI框架代码、业务代码框架、GN文件等。在开发JS应用与NAPI间接口时,底层框架开发者无需关注Nodejs语法、C++与JS之间的数据类型转换等上层应用转换逻辑,只关注底层业务逻辑即可,专业的人做专业的事,从而可以大大提高开发效率。目前工具支持命令行、VScode插件两种入口。
|
||||
|
||||
## 软件架构
|
||||
![](figures/pic-frm.png)
|
||||
|
||||
## 目录
|
||||
|
||||
#### 目录
|
||||
```
|
||||
/assist_tools/
|
||||
├── napi_tool # NAPI框架代码生成工具
|
||||
│ ├── doc # 工具当前能力、版本规划
|
||||
│ ├── image # 图片资源文件
|
||||
│ ├── output # 工具对应的可执行程序与插件程序
|
||||
│ ├── docs # 工具当前能力、版本规划
|
||||
│ ├── figures # 图片资源文件
|
||||
│ ├── code # 工具源码
|
||||
| | ├── tool_code # 工具源码
|
||||
│ | ├── gen
|
||||
│ | |── analyze # 解析器
|
||||
│ │ |── extend # 扩展模块,包括gn文件生成、linux环境适配代码等
|
||||
│ │ |── generate # 生成器
|
||||
│ │ └── tools # 公共模块代码,包括消息体校验、文件读写、正则表达式转换等
|
||||
│ | └── test # 插件测试用例
|
||||
| | └──ts_test # 工具需要的ts文件样例
|
||||
│ └── README # 工具使用指导
|
||||
└──README
|
||||
```
|
||||
### code目录源码介绍
|
||||
此目录为NAPI框架代码生成工具对应的源码,开发者可基于此代码进行二次开发。
|
||||
|
||||
#### 相关仓
|
||||
无
|
||||
## 软件环境准备
|
||||
|
||||
系统:建议Ubuntu 20.04或者Windows 10
|
||||
|
||||
依赖版本:vscode 1.62.0
|
||||
|
||||
## 开发说明
|
||||
|
||||
开发者可以利用源码来编译打包生成对应的可执行文件和插件,用于在JS和c++之间进行类型转换。可执行文件和插件的开发说明如下:
|
||||
|
||||
### 源码
|
||||
|
||||
通过命令:git clone git@gitee.com:openharmony-sig/assist_tools.git 下载对应的源码。
|
||||
|
||||
### 打包
|
||||
|
||||
#### 可执行文件开发说明
|
||||
1.安装pkg : 执行命令sudo npm i -g pkg
|
||||
|
||||
2.打包三个版本 : 执行命令pkg vscode_plugin/gnapi/gen/cmd_gen.js
|
||||
|
||||
执行以上步骤后,即可在gen目录下生成Windows、linux、mac系统下的可执行程序:cmd_gen-win.exe、cmd_gen-linux、cmd_gen-macos。
|
||||
|
||||
#### 插件开发说明
|
||||
1. 安装yo : 执行命令npm install -g yo generator-code。
|
||||
|
||||
2. 使用yo : 执行命令yo code,gnapi是使用yo code生成的插件代码框架,其中gnapi/gen目录下是我们开发的自动化生成napi程序的源代码。
|
||||
|
||||
![](figures/pic-gen-source-code.png)
|
||||
|
||||
3. 在napi_generator/vscode_plugin/gnapi这个目录中执行命令npm i vsce。
|
||||
|
||||
4. 执行命令./node_modules/vsce/vsce package命令,最终会打包生成一个插件gnapi-0.0.1.vsix。
|
||||
|
||||
![](figures/pic-gen-vsix.png)
|
||||
|
||||
## 使用说明
|
||||
|
||||
1. 将gen目录下Windows可执行程序cmd_gen-win.exe拷贝到对应目录下,不需要安装,可以在cmd命令行中直接运行。
|
||||
2. 将gen目录下Linux可执行程序cmd_gen-linux拷贝到对应目录下,可以在终端下直接运行。
|
||||
|
||||
### 可执行程序使用方法
|
||||
|
||||
#### Windows
|
||||
|
||||
1) 将要转换的.d.ts文件放到任意目录下,建议放到可执行程序cmd_gen-win.exe同级目录下,例如:
|
||||
|
||||
![](figures/pic-d-ts-location.png)
|
||||
|
||||
2) 右键windows开始菜单,点击运行,输入cmd,点击确定。
|
||||
|
||||
![](figures/pic-cmd.png)
|
||||
|
||||
3) 在命令行中进入到之前可执行程序cmd_gen-win.exe所在的目录,并运行cmd_gen-win.exe,在cmd_gen-win.exe后面要对应的.d.ts文件名,例如:
|
||||
|
||||
![](figures/pic-cmd-execute.png)
|
||||
|
||||
4) 运行成功后会在.d.ts文件说在的目录下生成对应的文件,例如:
|
||||
|
||||
![](figures/pic-d-ts-transition.png)
|
||||
|
||||
#### Linux
|
||||
|
||||
1) 将要转换的.d.ts文件放到任意目录下,建议放到可执行程序cmd_gen-linux同级目录下,例如:
|
||||
|
||||
![](figures/pic-d-ts-location-linux.png)
|
||||
|
||||
2) 在终端中进入到之前可执行程序cmd_gen-linux所在的目录,并运行cmd_gen-linux,在cmd_gen-linux后面要对应的.d.ts文件名,例如:
|
||||
|
||||
![](figures/pic-cmd-execute-linux.png)
|
||||
|
||||
3) 运行成功后会在.d.ts文件说在的目录下生成对应的文件,例如:
|
||||
|
||||
![](figures/pic-d-ts-transition-linux.png)
|
||||
|
||||
#### Mac
|
||||
方法步骤参考windows、Linux的使用方法
|
||||
|
||||
## 插件使用方法
|
||||
### 说明
|
||||
visual studio code 版本需1.62.0及以上
|
||||
|
||||
### 步骤
|
||||
|
||||
1) 打开vscode,在左侧边栏中选择插件安装。
|
||||
|
||||
![](figures/pic-plug-in-search.png)
|
||||
|
||||
2) 点击上面三个点的按钮,选择从VSIX安装选项,然后选择刚才生成的gnapi-0.0.1.vsix插件文件,再点击安装。
|
||||
|
||||
![](figures/pic-plug-in-select.png)
|
||||
|
||||
3) 安装完成后就会在vscode的插件管理器中能看到gnapi这个插件了。
|
||||
|
||||
![](figures/pic-plug-in-gnapi.png)
|
||||
|
||||
4) 在vscode中找到需要转换的.d.ts文件,例如:
|
||||
|
||||
![](figures/pic-plug-in-select-d-ts.png)
|
||||
|
||||
5) 鼠标在.d.ts上点击右键,选择.d.ts生成c++选项。
|
||||
|
||||
![](figures/pic-plug-in-gen-c++.png)
|
||||
|
||||
6) 之后就会在该目录下生成对应文件,例如:
|
||||
|
||||
![](figures/pic-plug-in-gen-result.png)
|
||||
|
||||
## 注意事项
|
||||
以上插件使用示例为windows的,linux、mac的使用方法类似。
|
||||
|
||||
## 参与贡献
|
||||
|
||||
暂无
|
||||
|
||||
## 相关仓
|
||||
|
||||
暂无
|
||||
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 192 KiB After Width: | Height: | Size: 192 KiB |
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 54 KiB |
@ -1,148 +0,0 @@
|
||||
# napi_tool
|
||||
|
||||
## Introduction
|
||||
This paper mainly introduces the NAPi framework code generation tool, which can generate NAPi framework code, business code framework and designed.the GN file according to the TS interface file in the path specified by the user. So developers need to focus on Nodejs related grammar framework layer, interface between c + + with JS type conversion, data type conversion, etc.. This tool is mainly used in the scenario of JS application calling NaPi interface, can focus on business logic implementation, Thus, the development efficiency can be greatly improved. Currently, the tool supports command line and VScode plug-in.
|
||||
|
||||
## Software architecture
|
||||
![](figures/pic-frm-en.png)
|
||||
|
||||
## Directory Structure
|
||||
|
||||
```
|
||||
├── napi_tool # NAPI framework code generation tool
|
||||
│ ├── docs # Plan the current tool capabilities and versions
|
||||
│ ├── figures # Image resource file
|
||||
│ ├── code # Tool source
|
||||
| | ├── tool_code # Tool source
|
||||
│ | ├── gen
|
||||
│ | |── analyze # Parser
|
||||
│ │ |── extend # Extension module, including GN file generation, Linux environment adaptation code, etc
|
||||
│ │ |── generate # Generator
|
||||
│ │ └── tools # Public module code, including message body check, file read and write, regular expression
|
||||
│ | └── test # Plug-in test cases
|
||||
| | └──ts_test # Example ts files required by the tool
|
||||
│ └── README
|
||||
└──README
|
||||
```
|
||||
|
||||
### code directory source code introduction
|
||||
This directory is the source code corresponding to the NAPI framework code generation tool, developers can be based on this code for secondary development.
|
||||
|
||||
## Software environment preparation
|
||||
|
||||
System: Ubuntu 20.04 or windows 10 is recommended
|
||||
|
||||
Dependent version: vscode 1.62.0
|
||||
|
||||
## Development description
|
||||
|
||||
Developers can use the source code to compile and package the corresponding executable files and plug-ins for type conversion between JS and C + +. The development instructions of executable files and plug-ins are as follows:
|
||||
|
||||
### Source code
|
||||
|
||||
Through the command: git clone git@gitee.com :openharmony-sig/assist_ tools.git to download the corresponding source code.
|
||||
|
||||
### pack
|
||||
|
||||
#### Executable file development instructions
|
||||
1.Install pkg :execute the command sudo npm i -g pkg
|
||||
|
||||
2.Package three versions : execute the command pkg vscode_plugin/gnapi/gen/cmd_gen.js
|
||||
|
||||
After performing the preceding steps,ou can generate Windows, Linux, and MAC executable programs in the Gen directory:cmd_gen-win.exe、cmd_gen-linux、cmd_gen-macos.
|
||||
|
||||
#### Plug-in development Instructions
|
||||
1. Install yo : execute the command npm install -g yo generator-code.
|
||||
|
||||
2. Use yo : execute the command yo code,gnapi is a plug-in code framework generated by Yo Code, in which gnAPI/Gen directory is the source code of the automatic generation of NAPI program we developed.
|
||||
|
||||
![](figures/pic-gen-source-code.png)
|
||||
|
||||
3. Run npm i vsce in the napi_generator/vscode_plugin/gnapi directory.
|
||||
|
||||
4. Execute the command./node_modules/vsce/vsce package command,The final package generates a plugin, gnapI-0.0.1.vsix.
|
||||
|
||||
![](figures/pic-gen-vsix.png)
|
||||
|
||||
## instructions
|
||||
|
||||
1. Copy the Windows executable program cmd_gen-win.exe from the gen directory to the corresponding directory. You do not need to install the program.
|
||||
2. Copy the Linux executable program cmd_gen-linux from the gen directory to the corresponding directory, and run it directly on the terminal.
|
||||
|
||||
### Usage
|
||||
|
||||
#### Windows
|
||||
|
||||
1) The.d.ts files to be converted should be placed in any directory. It is recommended to put them in the same directory as the executable program cmd_gen-win.exe, for example:
|
||||
|
||||
![](figures/pic-d-ts-location.png)
|
||||
|
||||
2) Right-click Windows Start menu, click Run, enter CMD, and click OK.
|
||||
|
||||
![](figures/pic-cmd.png)
|
||||
|
||||
3) In the command line interface (CLI), go to the directory where the previous executable program cmd_gen-win.exe resides and run cmd_gen-win.exe. After cmd_gen-win.exe, the corresponding.
|
||||
|
||||
![](figures/pic-cmd-execute.png)
|
||||
|
||||
4) After successful operation, the corresponding file will be generated in the directory where the. D. ts file says, for example:
|
||||
|
||||
![](figures/pic-d-ts-transition.png)
|
||||
|
||||
#### Linux
|
||||
|
||||
1) Put the.d.ts files to be converted in any directory. It is recommended to put them in the same directory as the executable program cmd_gen-linux, for example:
|
||||
|
||||
![](figures/pic-d-ts-location-linux.png)
|
||||
|
||||
2) In the terminal, go to the directory where the previous executable program cmd_gen-linux resides and run cmd_gen-linux. After cmd_gen-linux, the corresponding. D. s file name, for example:
|
||||
|
||||
![](figures/pic-cmd-execute-linux.png)
|
||||
|
||||
3) After successful operation, the corresponding file will be generated in the directory where the. D. ts file says, for example:
|
||||
|
||||
![](figures/pic-d-ts-transition-linux.png)
|
||||
|
||||
#### Mac
|
||||
Method Step For details about how to use Windows and Linux
|
||||
|
||||
## Plug-in usage
|
||||
### Instruction
|
||||
Visual Studio Code version 1.62.0 or later
|
||||
|
||||
### Steps
|
||||
|
||||
1) Open vscode and select plug-in installation in the left sidebar.
|
||||
|
||||
![](figures/pic-plug-in-search.png)
|
||||
|
||||
2) Click the three buttons above, select the install from VSIX option, then select the gnapI-0.0.1. VSIX plug-in file you just generated, and click Install.
|
||||
|
||||
![](figures/pic-plug-in-select.png)
|
||||
|
||||
3) After installation, the gnapi plugin should be visible in vscode's plugin manager.
|
||||
|
||||
![](figures/pic-plug-in-gnapi.png)
|
||||
|
||||
4) Find the.d.ts file to convert in vscode, for example:
|
||||
|
||||
![](figures/pic-plug-in-select-d-ts.png)
|
||||
|
||||
5) Right click on.d.ts and select.d.ts to generate c++ options.
|
||||
|
||||
![](figures/pic-plug-in-gen-c++.png)
|
||||
|
||||
6) The corresponding files will be generated in this directory, for example:
|
||||
|
||||
![](figures/pic-plug-in-gen-result.png)
|
||||
|
||||
## Matters needing attention
|
||||
The examples above are for Windows. The methods for Linux and MAC are similar.
|
||||
|
||||
## Participate in the contribution
|
||||
|
||||
Not yet.
|
||||
|
||||
## Related to the storehouse
|
||||
|
||||
Not yet.
|
@ -1,147 +0,0 @@
|
||||
# napi_tool
|
||||
|
||||
## 概述
|
||||
本文主要介绍NAPI框架代码生成工具,它可以根据用户指定路径下的ts接口文件一键生成NAPI框架代码、业务代码框架、GN文件等。在开发JS应用与NAPI间接口时,底层框架开发者无需关注Nodejs语法、C++与JS之间的数据类型转换等上层应用转换逻辑,只关注底层业务逻辑即可,专业的人做专业的事,从而可以大大提高开发效率。目前工具支持命令行、VScode插件两种入口。
|
||||
|
||||
## 软件架构
|
||||
![](figures/pic-frm.png)
|
||||
|
||||
## 目录
|
||||
|
||||
```
|
||||
├── napi_tool # NAPI框架代码生成工具
|
||||
│ ├── docs # 工具当前能力、版本规划
|
||||
│ ├── figures # 图片资源文件
|
||||
│ ├── code # 工具源码
|
||||
| | ├── tool_code # 工具源码
|
||||
│ | ├── gen
|
||||
│ | |── analyze # 解析器
|
||||
│ │ |── extend # 扩展模块,包括gn文件生成、linux环境适配代码等
|
||||
│ │ |── generate # 生成器
|
||||
│ │ └── tools # 公共模块代码,包括消息体校验、文件读写、正则表达式转换等
|
||||
│ | └── test # 插件测试用例
|
||||
| | └──ts_test # 工具需要的ts文件样例
|
||||
│ └── README # 工具使用指导
|
||||
└──README
|
||||
```
|
||||
### code目录源码介绍
|
||||
此目录为NAPI框架代码生成工具对应的源码,开发者可基于此代码进行二次开发。
|
||||
|
||||
## 软件环境准备
|
||||
|
||||
系统:建议Ubuntu 20.04或者Windows 10
|
||||
|
||||
依赖版本:vscode 1.62.0
|
||||
|
||||
## 开发说明
|
||||
|
||||
开发者可以利用源码来编译打包生成对应的可执行文件和插件,用于在JS和c++之间进行类型转换。可执行文件和插件的开发说明如下:
|
||||
|
||||
### 源码
|
||||
|
||||
通过命令:git clone git@gitee.com:openharmony-sig/assist_tools.git 下载对应的源码。
|
||||
|
||||
### 打包
|
||||
|
||||
#### 可执行文件开发说明
|
||||
1.安装pkg : 执行命令sudo npm i -g pkg
|
||||
|
||||
2.打包三个版本 : 执行命令pkg vscode_plugin/gnapi/gen/cmd_gen.js
|
||||
|
||||
执行以上步骤后,即可在gen目录下生成Windows、linux、mac系统下的可执行程序:cmd_gen-win.exe、cmd_gen-linux、cmd_gen-macos。
|
||||
|
||||
#### 插件开发说明
|
||||
1. 安装yo : 执行命令npm install -g yo generator-code。
|
||||
|
||||
2. 使用yo : 执行命令yo code,gnapi是使用yo code生成的插件代码框架,其中gnapi/gen目录下是我们开发的自动化生成napi程序的源代码。
|
||||
|
||||
![](figures/pic-gen-source-code.png)
|
||||
|
||||
3. 在napi_generator/vscode_plugin/gnapi这个目录中执行命令npm i vsce。
|
||||
|
||||
4. 执行命令./node_modules/vsce/vsce package命令,最终会打包生成一个插件gnapi-0.0.1.vsix。
|
||||
|
||||
![](figures/pic-gen-vsix.png)
|
||||
|
||||
## 使用说明
|
||||
|
||||
1. 将gen目录下Windows可执行程序cmd_gen-win.exe拷贝到对应目录下,不需要安装,可以在cmd命令行中直接运行。
|
||||
2. 将gen目录下Linux可执行程序cmd_gen-linux拷贝到对应目录下,可以在终端下直接运行。
|
||||
|
||||
### 可执行程序使用方法
|
||||
|
||||
#### Windows
|
||||
|
||||
1) 将要转换的.d.ts文件放到任意目录下,建议放到可执行程序cmd_gen-win.exe同级目录下,例如:
|
||||
|
||||
![](figures/pic-d-ts-location.png)
|
||||
|
||||
2) 右键windows开始菜单,点击运行,输入cmd,点击确定。
|
||||
|
||||
![](figures/pic-cmd.png)
|
||||
|
||||
3) 在命令行中进入到之前可执行程序cmd_gen-win.exe所在的目录,并运行cmd_gen-win.exe,在cmd_gen-win.exe后面要对应的.d.ts文件名,例如:
|
||||
|
||||
![](figures/pic-cmd-execute.png)
|
||||
|
||||
4) 运行成功后会在.d.ts文件说在的目录下生成对应的文件,例如:
|
||||
|
||||
![](figures/pic-d-ts-transition.png)
|
||||
|
||||
#### Linux
|
||||
|
||||
1) 将要转换的.d.ts文件放到任意目录下,建议放到可执行程序cmd_gen-linux同级目录下,例如:
|
||||
|
||||
![](figures/pic-d-ts-location-linux.png)
|
||||
|
||||
2) 在终端中进入到之前可执行程序cmd_gen-linux所在的目录,并运行cmd_gen-linux,在cmd_gen-linux后面要对应的.d.ts文件名,例如:
|
||||
|
||||
![](figures/pic-cmd-execute-linux.png)
|
||||
|
||||
3) 运行成功后会在.d.ts文件说在的目录下生成对应的文件,例如:
|
||||
|
||||
![](figures/pic-d-ts-transition-linux.png)
|
||||
|
||||
#### Mac
|
||||
方法步骤参考windows、Linux的使用方法
|
||||
|
||||
## 插件使用方法
|
||||
### 说明
|
||||
visual studio code 版本需1.62.0及以上
|
||||
|
||||
### 步骤
|
||||
|
||||
1) 打开vscode,在左侧边栏中选择插件安装。
|
||||
|
||||
![](figures/pic-plug-in-search.png)
|
||||
|
||||
2) 点击上面三个点的按钮,选择从VSIX安装选项,然后选择刚才生成的gnapi-0.0.1.vsix插件文件,再点击安装。
|
||||
|
||||
![](figures/pic-plug-in-select.png)
|
||||
|
||||
3) 安装完成后就会在vscode的插件管理器中能看到gnapi这个插件了。
|
||||
|
||||
![](figures/pic-plug-in-gnapi.png)
|
||||
|
||||
4) 在vscode中找到需要转换的.d.ts文件,例如:
|
||||
|
||||
![](figures/pic-plug-in-select-d-ts.png)
|
||||
|
||||
5) 鼠标在.d.ts上点击右键,选择.d.ts生成c++选项。
|
||||
|
||||
![](figures/pic-plug-in-gen-c++.png)
|
||||
|
||||
6) 之后就会在该目录下生成对应文件,例如:
|
||||
|
||||
![](figures/pic-plug-in-gen-result.png)
|
||||
|
||||
## 注意事项
|
||||
以上插件使用示例为windows的,linux、mac的使用方法类似。
|
||||
|
||||
## 参与贡献
|
||||
|
||||
暂无
|
||||
|
||||
## 相关仓
|
||||
|
||||
暂无
|
@ -1,19 +0,0 @@
|
||||
# napi_tool_code
|
||||
|
||||
#### 介绍
|
||||
此目录为NAPI框架代码生成工具对应的源码,开发者可基于此代码进行二次开发。
|
||||
|
||||
#### 目录
|
||||
```
|
||||
/napi_tool/code
|
||||
├── tool_code # 工具源码
|
||||
│ ├── gen
|
||||
│ | |── analyze # 解析器
|
||||
│ │ |── extend # 扩展模块,包括gn文件生成、linux环境适配代码等
|
||||
│ │ |── generate # 生成器
|
||||
│ │ └── tools # 公共模块代码,包括消息体校验、文件读写、正则表达式转换等
|
||||
│ └── test # 插件测试用例
|
||||
└──ts_test # 工具需要的ts文件样例
|
||||
```
|
||||
|
||||
|
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 192 KiB |
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
const path = require('path');
|
||||
|
||||
const { runTests } = require('@vscode/test-electron');
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
// The folder containing the Extension Manifest package.json
|
||||
// Passed to `--extensionDevelopmentPath`
|
||||
const extensionDevelopmentPath = path.resolve(__dirname, '../');
|
||||
|
||||
// The path to the extension test script
|
||||
// Passed to --extensionTestsPath
|
||||
const extensionTestsPath = path.resolve(__dirname, './suite/index');
|
||||
|
||||
// Download VS Code, unzip it and run the integration test
|
||||
await runTests({ extensionDevelopmentPath, extensionTestsPath });
|
||||
} catch (err) {
|
||||
console.error('Failed to run tests');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
const assert = require('assert');
|
||||
|
||||
// You can import and use all API from the 'vscode' module
|
||||
// as well as import your extension to test it
|
||||
const vscode = require('vscode');
|
||||
// const myExtension = require('../extension');
|
||||
|
||||
suite('Extension Test Suite', () => {
|
||||
vscode.window.showInformationMessage('Start all tests.');
|
||||
|
||||
test('Sample test', () => {
|
||||
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
|
||||
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
|
||||
});
|
||||
});
|