From cb0f30ccc181fb062060b6d52cf290e9b43b314f Mon Sep 17 00:00:00 2001 From: gou-jingjing Date: Wed, 15 May 2024 18:12:59 +0800 Subject: [PATCH] refactor directory Signed-off-by: gou-jingjing --- README.md | 118 ++++++++++++++++++++++++++++ docs/develop.md | 1 + docs/log/meeting.md | 1 + docs/log/release-notes.md | 67 ++++++++++++++++ docs/readme.md | 33 ++++++++ docs/usage.md | 110 ++++++++++++++++++++++++++ test/dts2cpp/README.md | 5 ++ test/dts2cpp/ts/@ohos.mtTest.d.ts | 46 +++++++++++ test/dts2cpp/ts/@ohos.napitest.d.ts | 71 +++++++++++++++++ test/dts2cpp/ts/basic.d.ts | 30 +++++++ 10 files changed, 482 insertions(+) create mode 100644 README.md create mode 100644 docs/develop.md create mode 100644 docs/log/meeting.md create mode 100644 docs/log/release-notes.md create mode 100644 docs/readme.md create mode 100644 docs/usage.md create mode 100644 test/dts2cpp/README.md create mode 100644 test/dts2cpp/ts/@ohos.mtTest.d.ts create mode 100644 test/dts2cpp/ts/@ohos.napitest.d.ts create mode 100644 test/dts2cpp/ts/basic.d.ts diff --git a/README.md b/README.md new file mode 100644 index 00000000..72688fc5 --- /dev/null +++ b/README.md @@ -0,0 +1,118 @@ +# Readme + +## 简介 + +napi_generator仓包含以下工具:NAPI框架代码生成工具(dts2cpp)可以根据用户指定路径下的ts(typescript)接口文件一键生成NAPI框架代码、业务代码框架、GN文件等。TS接口生成工具(h2dts)可以根据定义在c++头文件中的接口,生成type-script语言的ts接口文件。GN脚本生成工具(cmake2gn),它可以根据三方库的CMakeLists.txt文件,编译转换生成BUILD.gn脚本文件。SERVICE框架生成工具(h2sa),它可以根据一个定义远程方法的.h头文件,生成整个Service框架的代码,包含Ability注册、proxy/stub类实现、MessageParcel数据包构造、Service子系统编译及开机自启动相关配置文件。NATIVE生成工具(h2dtscpp),它可以根据定义在c++头文件中的接口,生成type-script语言的ts接口文件、NAPI框架代码、和自动化测试用例代码。dts2ets工具,它可以根据用户指定路径下的ts(typescript)接口文件生成ets页面代码。API扫描工具,它可以扫描三方库中包含OpenHarmony源码不包含的接口,并输出result.xlsx文档。 + +## 目录 + +``` +├── napi_generator # 工具集 +│ ├── docs # 工具索引文档 +│ │ ├── readme.md # 所有工具 readme 索引 +│ │ ├── develop.md # 工具设计文档索引 +│ │ ├── usage.md # 工具使用文档索引 +│ │ ├── log +│ │ │ ├── meeting.md # 会议纪要 +│ │ │ ├── release-notes.md # 工具版本说明和规划索引 +│ ├── src # 工具源码 +│ │ ├── cli # 脚手架源码 +│ │ | ├── cmake2gn # gn脚本生成工具 +│ │ | | ├── docs +│ │ | | | ├── figures # 文档图片资源 +│ │ | | | ├── guide # 开发文档 +│ │ | | | ├── usage # 使用文档 +│ │ | | | ├── release-notes # 版本说明文档 +│ │ | | ├── src # 源码 +│ │ | | ├── README_ZH.md +│ │ | |── dts2cpp # napi框架生成工具 +│ │ | | ├── docs +│ │ | | | ├── figures # 文档图片资源 +│ │ | | | ├── guide # 开发文档 +│ │ | | | ├── usage # 使用文档 +│ │ | | | ├── release-notes # 版本说明文档 +│ │ | | | ├── requirement # roadmap.md +│ │ | | ├── src # 源码 +│ │ | | ├── README_ZH.md +│ │ | |── dts2ets # ets页面生成工具 +│ │ | | ├── appCodeGen # 源码 +│ │ | |── h2dts # ts生成工具 +│ │ | | ├── docs +│ │ | | | ├── figures # 文档图片资源 +│ │ | | | ├── guide # 开发文档 +│ │ | | | ├── usage # 使用文档 +│ │ | | | ├── release-notes # 版本说明文档 +│ │ | | | ├── requirement # roadmap.md +│ │ | | ├── src # 源码 +│ │ | | ├── examples # 工具输入示例.h文件 +│ │ | | ├── README_ZH.md +│ │ | |── h2dtscpp # native生成工具 +│ │ | | ├── docs +│ │ | | | ├── figures # 文档图片资源 +│ │ | | | ├── guide # 开发文档 +│ │ | | | ├── usage # 使用文档 +│ │ | | ├── src # 源码 +│ │ | | ├── README_ZH.md +│ │ | |── h2sa # service生成工具 +│ │ | | ├── docs +│ │ | | | ├── figures # 文档图片资源 +│ │ | | | ├── guide # 开发文档 +│ │ | | | ├── usage # 使用文档 +│ │ | | | ├── release-notes # 版本说明文档 +│ │ | | | ├── requirement # roadmap.md +│ │ | | ├── src # 源码 +│ │ | | ├── examples # 工具输入示例.h文件 +│ │ | | ├── README_ZH.md +│ │ ├── intellij_plugin +│ │ | ├── cmake2gn # gn脚本生成工具 +│ │ | | | ├── gn_IntelliJ_plugin # IntelliJ插件 +│ │ | |── dts2cpp # napi框架生成工具 +│ │ | | | ├── napi_IntelliJ_plugin # IntelliJ插件 +│ │ | |── h2dts # ts生成工具 +│ │ | | | ├── ts_IntelliJ_plugin # IntelliJ插件 +│ │ | |── h2dtscpp # native生成工具 +│ │ | | | ├── native_IntelliJ_plugin # IntelliJ插件 +│ │ | |── h2sa # service生成工具 +│ │ | | | ├── service_IntelliJ_plugin # IntelliJ插件 +│ │ | |── assist # 统一入口插件 +│ │ | | | ├── assist_tools_IntelliJ_plugin # IntelliJ插件 +│ │ ├── vscode_plugin +│ │ | ├── cmake2gn # gn脚本生成工具 +│ │ | | | ├── gn_vs_plugin # vs插件 +│ │ | |── dts2cpp # napi框架生成工具 +│ │ | | | ├── napi_vs_plugin # vs插件 +│ │ | |── h2dts # ts生成工具 +│ │ | | | ├── ts_vs_plugin # vs插件 +│ │ | |── h2sa # service生成工具 +│ │ | | | ├── service_vs_plugin # vs插件 +│ │ | |── assist # 统一入口插件 +│ │ | | | ├── assist_tools_vs_plugin # vs插件 +│ │ ├── tool +│ │ | |── api # api扫描工具 +│ │ | | ├── api_scan_IntelliJ_plugin # api扫描工具IntelliJ插件 +│ │ | | ├── api_scan_vs_plugin # api扫描工具vs插件 +│ │ | | ├── docs # 文档 +│ │ | | ├── figures # 文档图片资源 +│ │ | | ├── src # api扫描工具源码 +│ │ | | ├── FAQ.md +│ │ | | ├── README_ZH.md +│ ├── test +│ │ ├── dts2cpp # dts2cpp工具使用example +│ │ | |── ts +│ │ | |── README.md +│ │ ├── storytest # dts2cpp工具st +│ │ ├── unittest # dts2cpp工具ut +│ │ ├── debug_entry.js +│ │ ├── README_zh.md +│ ├── sample # 样例 +│ │ ├── napitutorials +│ └── README.md # readme +``` + +## 工具介绍 + +所有工具相关文档介绍如下所示: +[readme索引](https://gitee.com/openharmony/napi_generator/blob/master/docs/readme.md) +[usage索引](https://gitee.com/openharmony/napi_generator/blob/master/docs/usage.md) +[develop索引](https://gitee.com/openharmony/napi_generator/blob/master/docs/develop.md) +[release-notes索引](https://gitee.com/openharmony/napi_generator/blob/master/docs/log/release-notes.md) \ No newline at end of file diff --git a/docs/develop.md b/docs/develop.md new file mode 100644 index 00000000..b4a6f00f --- /dev/null +++ b/docs/develop.md @@ -0,0 +1 @@ +# Develop(暂无) \ No newline at end of file diff --git a/docs/log/meeting.md b/docs/log/meeting.md new file mode 100644 index 00000000..a91e35df --- /dev/null +++ b/docs/log/meeting.md @@ -0,0 +1 @@ +# Meeting(暂无) \ No newline at end of file diff --git a/docs/log/release-notes.md b/docs/log/release-notes.md new file mode 100644 index 00000000..eb8a2e41 --- /dev/null +++ b/docs/log/release-notes.md @@ -0,0 +1,67 @@ +# release-notes + +## dts2cpp(NAPI框架代码生成工具) + +[版本说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/dts2cpp/docs/release-notes) + +## h2dts(TS接口生成工具) + +[版本说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/h2dts/docs/release-notes/ts_Gen-1.0.md) + +## h2sa(SERVICE框架生成工具) + +[版本说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/h2sa/docs/release-notes/Service-1.0.md) + +## cmake2gn(GN脚本生成工具) + +[版本说明](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/cmake2gn/docs/release-notes/gn-gen-release-notes-0.0.2.md) + +## h2dtscpp(NATIVE生成工具) + +暂无 + +## h2ets + +暂无 + +## scan(API扫描工具) + +暂无 + +## hdf(HCS可视化工具) + +暂无 + +# roadmap + +## dts2cpp(NAPI框架代码生成工具) + +[roadmap](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/dts2cpp/docs/requirement/ROADMAP_ZH.md) + +## h2dts(TS接口生成工具) + +[roadmap](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/h2dts/docs/requirement/ROADMAP_ZH.md) + +## h2sa(SERVICE框架生成工具) + +[roadmap](https://gitee.com/openharmony/napi_generator/tree/master/src/cli/h2sa/docs/requirement/ROADMAP_ZH.md) + +## cmake2gn(GN脚本生成工具) + +暂无 + +## h2dtscpp(NATIVE生成工具) + +暂无 + +## h2ets + +暂无 + +## scan(API扫描工具) + +暂无 + +## hdf(HCS可视化工具) + +暂无 \ No newline at end of file diff --git a/docs/readme.md b/docs/readme.md new file mode 100644 index 00000000..77c6ae6d --- /dev/null +++ b/docs/readme.md @@ -0,0 +1,33 @@ +# Readme + +## dts2cpp(NAPI框架代码生成工具) + +[readme](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/README_zh.md) + +## h2dts(TS接口生成工具) + +[readme](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2dts/README_zh.md) + +## cmake2gn(GN脚本生成工具) + +[readme](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/cmake2gn/README_zh.md) + +## h2sa(SERVICE框架生成工具) + +[readme](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2sa/README_zh.md) + +## dts2ets + +暂无 + +## h2dtscpp(NATIVE生成工具) + +[readme](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2dtscpp/README.md) + +## scan(API扫描工具) + +[readme](https://gitee.com/openharmony/napi_generator/blob/master/src/tool/api/README_zh.md) + +## hdf(HCS可视化工具) + +[readme](https://gitee.com/openharmony/drivers_hdf_core/tree/master/framework/tools/hcs-view/README_zh.md) \ No newline at end of file diff --git a/docs/usage.md b/docs/usage.md new file mode 100644 index 00000000..d366fc26 --- /dev/null +++ b/docs/usage.md @@ -0,0 +1,110 @@ +# Usage + +## dts2cpp(NAPI框架代码生成工具) + +**开发说明** + +可执行程序开发说明:[可执行程序开发说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/docs/guide/DEVELOP_ZH.md) + +intelliJ插件开发说明:[intelliJ插件开发说明](https://gitee.com/openharmony/napi_generator/blob/master/src/intellij_plugin/dts2cpp/napi_IntelliJ_plugin/docs/guide/DEVELOP_zh.md) + +vscode插件开发说明:[vscode插件开发说明](https://gitee.com/openharmony/napi_generator/blob/master/src/vscode_plugin/dts2cpp/napi_vs_plugin/docs/guide/DEVELOP_ZH.md) + +**使用说明** + +可执行程序使用说明:[可执行程序使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/dts2cpp/docs/usage/INSTRUCTION_ZH.md) + +intelliJ插件使用说明:[intelliJ插件使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/intellij_plugin/dts2cpp/napi_IntelliJ_plugin/docs/usage/INSTRUCTION_ZH.md) + +vscode插件使用说明:[vscode插件使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/vscode_plugin/dts2cpp/napi_vs_plugin/docs/usage/INSTRUCTION_ZH.md) + +## h2dts(TS接口生成工具) + +**开发说明** + +可执行程序开发说明:[可执行程序开发说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2dts/docs/guide/DEVELOP_ZH.md) + +intelliJ插件开发说明:[intelliJ插件开发说明](https://gitee.com/openharmony/napi_generator/blob/master/src/intellij_plugin/h2dts/ts_IntelliJ_plugin/docs/guide/DEVELOP_zh.md) + +// vscode 是否支持? + +vscode插件开发说明:[vscode插件开发说明](https://gitee.com/openharmony/napi_generator/blob/master/src/vscode_plugin/h2dts/ts_vs_plugin/docs/guide/DEVELOP_zh.md) + +**使用说明** + +可执行程序使用说明:[可执行程序使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2dts/docs/usage/INSTRUCTION_ZH.md) + +intelliJ插件使用说明:[intelliJ插件使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/intellij_plugin/h2dts/ts_IntelliJ_plugin/docs/usage/INSTRUCTION_ZH.md) + +vscode插件使用说明:[vscode插件使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/vscode_plugin/h2dts/ts_vs_plugin/docs/usage/INSTRUCTION_ZH.md) + +## h2sa(SERVICE框架生成工具) + +**开发说明** + +可执行程序开发说明:[可执行程序开发说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2sa/docs/guide/DEVELOP_ZH.md) + +vscode插件开发说明:暂无 + +**使用说明** + +可执行程序使用说明:[可执行程序使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2sa/docs/usage/INSTRUCTION_ZH.md) + +vscode插件使用说明:[vscode插件使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/vscode_plugin/h2sa/service_vs_plugin/docs/usage/INSTRUCTION_ZH.md) + +## cmake2gn(GN脚本生成工具) + +**开发说明** + +可执行程序开发说明:[可执行程序开发说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/cmake2gn/docs/guide/DEVELOP_ZH.md) + +vscode插件开发说明:[vscode插件开发说明](https://gitee.com/openharmony/napi_generator/blob/master/src/vscode_plugin/cmake2gn/gn_vs_plugin/docs/guide/DEVELOP_zh.md) + +**使用说明** + +可执行程序使用说明:[可执行程序使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/cmake2gn/docs/usage/INSTRUCTION_ZH.md) + +vscode插件使用说明:[vscode插件使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/vscode_plugin/cmake2gn/gn_vs_plugin/docs/usage/INSTRUCTION_ZH.md) + +## h2dtscpp(NATIVE生成工具) + +**开发说明** + +可执行程序开发说明:暂无 + +intelliJ插件开发说明:暂无 + +**使用说明** + +可执行程序使用说明:[可执行程序使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cli/h2dtscpp/docs/usage/INSTRUCTION_ZH.md) + +intelliJ插件使用说明:暂无 + + +## dts2ets + +暂无 + +## scan(API扫描工具) + +**开发说明** + +暂无 + +**使用说明** + +可执行程序使用说明:[可执行程序使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/tool/api/docs/INSTRUCTION_ZH.md) + +intelliJ插件使用说明:暂无 + +vscode插件使用说明:[vscode插件使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/tool/api/api_scan_vs_plugin/docs/INSTRUCTION_ZH.md) + +## hdf(HCS可视化工具) + +**开发说明** + +工具开发说明:[开发说明](https://gitee.com/openharmony/drivers_hdf_core/blob/master/framework/tools/hcs-view/docs/DEVELOP_zh.md) + +**使用说明** + +工具使用说明:[使用说明](https://gitee.com/openharmony/drivers_hdf_core/blob/master/framework/tools/hcs-view/docs/INSTRUCTION_zh.md) \ No newline at end of file diff --git a/test/dts2cpp/README.md b/test/dts2cpp/README.md new file mode 100644 index 00000000..36b9a96f --- /dev/null +++ b/test/dts2cpp/README.md @@ -0,0 +1,5 @@ +# Readme + +以 ts/@ohos.napitest.d.ts 为例,如何根据dts声明文件,通过工具生成napi框架代码;然后增加业务代码与测试页面之后成功调用接口的流程如下所示: + +[使用说明](https://gitee.com/openharmony/napi_generator/blob/master/src/cml/dts2cpp/docs/INSTRUCTION_ZH.md) \ No newline at end of file diff --git a/test/dts2cpp/ts/@ohos.mtTest.d.ts b/test/dts2cpp/ts/@ohos.mtTest.d.ts new file mode 100644 index 00000000..7a53490e --- /dev/null +++ b/test/dts2cpp/ts/@ohos.mtTest.d.ts @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2023 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. +*/ +import { AsyncCallback, Callback } from './basic'; + +declare namespace napitest { + + export class A { + a: string; + } + + export interface InterfaceA { + // callFunction: (result: number) => void; + onCallFunction(res: number): void; + } + + // export const addByClass: (a: A, b: number, callback: (result: number) => void, c: InterfaceA) => number; + + export interface InterfaceB { + // register形式注册回调 + registerInterfaceB(callback: (dd: number) => void); + // unRegister形式注销回调 + unRegisterInterfaceB(callback: (dd: number) => void); + + // object注册回调 + addInterfaceAListener(listener: InterfaceA); + removeInterfaceAListener(listener: InterfaceA); + + // 调用回调 + gByClass: (a: A, b: number) => number; + } + +} + +export default napitest; diff --git a/test/dts2cpp/ts/@ohos.napitest.d.ts b/test/dts2cpp/ts/@ohos.napitest.d.ts new file mode 100644 index 00000000..d169a261 --- /dev/null +++ b/test/dts2cpp/ts/@ohos.napitest.d.ts @@ -0,0 +1,71 @@ +/* +* 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. +*/ +import { AsyncCallback, Callback } from './basic'; +declare namespace napitest { + +// 测试普通方法 +function funcTest(v: boolean): string; + +// 测试注册回调与调用回调 +export class NodeISayHello +{ + // 注册object回调 + addSayHelloListener(listener: NodeISayHelloListener); + // 注销object回调 + removeSayHelloListener(listener: NodeISayHelloListener); + + // register注册回调 + registerCallbackfunc(cb : (wid: number) => string); + // unRegister注销回调 + unRegisterCallbackfunc(cb : (wid: number) => string); + + // 调用注册的object回调 + sayHello(from: string, to: string, sayType: SayType); + // 调用register注册的回调 + sayHi(from: string, to: string, sayType: SayType); + + // promise回调 + sayHelloWithResponse(from: string, to: string, sayType: SayType): Promise<{result: number, errMsg: string, response: string}>; + +} + +export class NodeISayHelloListener +{ + onSayHelloStart(info: SayInfo); + onSayHelloEnd(info: SayInfo); +} + +export enum SayType +{ + /** 0 主动说话 */ + kInitiative, + /** 1 回应对方 */ + kResponse, +} + +export type SayInfo = +{ + from: string; + fromId?: number; + to: string; + toId?: number; + content: string; + saidTime: string; + isEnd: boolean; +} + +} + +export default napitest; diff --git a/test/dts2cpp/ts/basic.d.ts b/test/dts2cpp/ts/basic.d.ts new file mode 100644 index 00000000..ecf2fd84 --- /dev/null +++ b/test/dts2cpp/ts/basic.d.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021 Huawei Device 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. + */ + +export interface Callback { + (data: T): void; +} + +export interface ErrorCallback { + (err: T): void; +} + +export interface AsyncCallback { + (err: BusinessError, data: T): void; +} + +export interface BusinessError extends Error { + code: number; +}