@hadss/hmrouter-plugin 1.0.0-rc.0 → 1.0.0-rc.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE +77 -77
  2. package/README.md +260 -37
  3. package/dist/HMRouterAnalyzer.d.ts +31 -0
  4. package/dist/HMRouterAnalyzer.js +293 -0
  5. package/dist/HMRouterHvigorPlugin.d.ts +15 -0
  6. package/dist/HMRouterHvigorPlugin.js +139 -0
  7. package/dist/HMRouterPluginConfig.d.ts +39 -0
  8. package/dist/HMRouterPluginConfig.js +73 -0
  9. package/dist/HMRouterPluginHandle.d.ts +23 -0
  10. package/dist/HMRouterPluginHandle.js +231 -0
  11. package/dist/Index.d.ts +4 -0
  12. package/dist/Index.js +124 -0
  13. package/dist/common/Constant.d.ts +27 -0
  14. package/dist/common/Constant.js +35 -0
  15. package/dist/common/Logger.d.ts +13 -0
  16. package/dist/common/Logger.js +55 -0
  17. package/dist/common/PluginModel.d.ts +50 -0
  18. package/dist/common/PluginModel.js +23 -0
  19. package/dist/constants/CommonConstants.d.ts +39 -0
  20. package/dist/constants/CommonConstants.js +46 -0
  21. package/dist/constants/ConfigConstants.d.ts +11 -0
  22. package/dist/constants/ConfigConstants.js +15 -0
  23. package/dist/constants/TaskConstants.d.ts +9 -0
  24. package/dist/constants/TaskConstants.js +13 -0
  25. package/dist/store/PluginStore.d.ts +12 -0
  26. package/dist/store/PluginStore.js +19 -0
  27. package/dist/utils/ConfusionUtil.d.ts +4 -0
  28. package/dist/utils/ConfusionUtil.js +27 -0
  29. package/dist/utils/FileUtil.d.ts +11 -0
  30. package/dist/utils/FileUtil.js +20 -0
  31. package/dist/utils/ObfuscationUtil.d.ts +4 -0
  32. package/dist/utils/ObfuscationUtil.js +34 -0
  33. package/dist/utils/StringUtil.d.ts +3 -0
  34. package/dist/utils/StringUtil.js +18 -0
  35. package/dist/utils/TsAstUtil.d.ts +9 -0
  36. package/dist/utils/TsAstUtil.js +89 -0
  37. package/package.json +46 -27
  38. package/viewBuilder.ejs +103 -0
  39. package/lib/HMRouterAnalyzer.js +0 -223
  40. package/lib/HMRouterHvigorPlugin.js +0 -175
  41. package/lib/HMRouterPluginConfig.js +0 -31
  42. package/lib/Index.js +0 -201
  43. package/lib/PluginModel.js +0 -33
  44. package/src/HMRouterAnalyzer.ts +0 -253
  45. package/src/HMRouterHvigorPlugin.ts +0 -246
  46. package/src/HMRouterPluginConfig.ts +0 -44
  47. package/src/Index.ts +0 -218
  48. package/src/PluginModel.ts +0 -50
  49. package/tsconfig.json +0 -14
  50. package/viewBuilder.tpl +0 -97
package/LICENSE CHANGED
@@ -1,78 +1,78 @@
1
- Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved.
2
-
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
-
7
- http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
14
-
15
- Apache License, Version 2.0
16
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
17
-
18
- 1. Definitions.
19
-
20
- "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
21
-
22
- "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
23
-
24
- "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
25
-
26
- "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
27
-
28
- "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
31
-
32
- "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
33
-
34
- "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
35
-
36
- "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
37
-
38
- "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
39
-
40
- 2. Grant of Copyright License.
41
-
42
- Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
43
-
44
- 3. Grant of Patent License.
45
-
46
- Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
47
-
48
- 4. Redistribution.
49
-
50
- You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
51
- 1.You must give any other recipients of the Work or Derivative Works a copy of this License; and
52
- 2.You must cause any modified files to carry prominent notices stating that You changed the files; and
53
- 3.You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
54
- 4.If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
55
-
56
- You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
57
-
58
- 5. Submission of Contributions.
59
-
60
- Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
61
-
62
- 6. Trademarks.
63
-
64
- This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
65
-
66
- 7. Disclaimer of Warranty.
67
-
68
- Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
69
-
70
- 8. Limitation of Liability.
71
-
72
- In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
73
-
74
- 9. Accepting Warranty or Additional Liability.
75
-
76
- While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
77
-
1
+ Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+ Apache License, Version 2.0
16
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
17
+
18
+ 1. Definitions.
19
+
20
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
21
+
22
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
23
+
24
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
25
+
26
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
31
+
32
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
33
+
34
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
35
+
36
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
37
+
38
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
39
+
40
+ 2. Grant of Copyright License.
41
+
42
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
43
+
44
+ 3. Grant of Patent License.
45
+
46
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
47
+
48
+ 4. Redistribution.
49
+
50
+ You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
51
+ 1.You must give any other recipients of the Work or Derivative Works a copy of this License; and
52
+ 2.You must cause any modified files to carry prominent notices stating that You changed the files; and
53
+ 3.You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
54
+ 4.If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
55
+
56
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
57
+
58
+ 5. Submission of Contributions.
59
+
60
+ Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
61
+
62
+ 6. Trademarks.
63
+
64
+ This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
65
+
66
+ 7. Disclaimer of Warranty.
67
+
68
+ Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
69
+
70
+ 8. Limitation of Liability.
71
+
72
+ In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
73
+
74
+ 9. Accepting Warranty or Additional Liability.
75
+
76
+ While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
77
+
78
78
  END OF TERMS AND CONDITIONS
package/README.md CHANGED
@@ -1,37 +1,260 @@
1
- ## 编译插件配置
2
-
3
- 1. 修改项目的`hvigor/hvigor-config.json`文件,加入路由编译插件
4
- ```json5
5
- {
6
- "dependencies": {
7
- "@hadss/hmrouter-plugin": "^1.0.0-rc.0" // 使用npm仓版本号
8
- },
9
- // ...其他配置
10
- }
11
- ```
12
-
13
- 2. 项目根目录或者模块目录创建路由编译插件配置文件`hmrouter_config.json`(推荐)
14
- ```json5
15
- {
16
- "scanDir": ["src/main/ets/components","src/main/ets/interceptors"],
17
- // 如果不传则扫描src/main/ets目录,对代码进行全量扫描,建议配置可缩短编译耗时
18
- "saveGeneratedFile": false, // 默认为false,改成true则不删除编译产物
19
- }
20
- ```
21
-
22
- 3. 在模块中引入路由编译插件,修改`hvigorfile.ts`
23
- ```typescript
24
- import { hapTasks } from '@ohos/hvigor-ohos-plugin';
25
- import { hapPlugin } from "@hadss/hmrouter-plugin";
26
-
27
- export default {
28
- system: hapTasks,
29
- plugins: [hapPlugin()]
30
- }
31
- ```
32
-
33
- > 如果是Har则使用`harPlugin()`, Hsp则使用`hspPlugin()`
34
-
35
- ## HMRouter使用
36
-
37
- 详见[@hadss/hmrouter](https://ohpm.openharmony.cn/#/cn/detail/@hadss%2Fhmrouter)
1
+ ## 编译插件配置
2
+
3
+ 1.修改项目的`hvigor/hvigor-config.json`文件,加入路由编译插件
4
+
5
+ ```json5
6
+ {
7
+ "dependencies": {
8
+ "@hadss/hmrouter-plugin": "^1.0.0-rc.10" // 使用npm仓版本号
9
+ },
10
+ // ...其他配置
11
+ }
12
+ ```
13
+
14
+ 2.在模块中引入路由编译插件,修改`hvigorfile.ts`
15
+
16
+ ```typescript
17
+ import { hapTasks } from "@ohos/hvigor-ohos-plugin";
18
+ import { hapPlugin } from "@hadss/hmrouter-plugin";
19
+
20
+ export default {
21
+ system: hapTasks,
22
+ plugins: [hapPlugin()], // 使用HMRouter框架中标签的模块均需要配置,与模块类型保持一致
23
+ };
24
+ ```
25
+
26
+ > 请使用与模块类型一致的插件方法,如果模块是 Har 则使用`harPlugin()`, 模块是 Hsp 则使用`hspPlugin()`
27
+
28
+ 3.项目根目录或者模块目录创建路由编译插件配置文件`hmrouter_config.json`(推荐)
29
+
30
+ ```json5
31
+ {
32
+ // 如果不配置则扫描src/main/ets目录,对代码进行全量扫描,如果配置则数组不能为空,建议配置指定目录可缩短编译耗时
33
+ "scanDir": [
34
+ "src/main/ets/components",
35
+ "src/main/ets/interceptors"
36
+ ],
37
+ // 默认为false,调试排除错误时可以改成true,不删除编译产物
38
+ "saveGeneratedFile": false,
39
+ // 默认为false,不自动配置混淆规则,只会生成hmrouter_obfuscation_rules.txt文件帮助开发者配置混淆文件;如果设置为true,会自动配置混淆规则,并删除hmrouter_obfuscation_rules.txt文件
40
+ "autoObfuscation": false,
41
+ // 默认模板文件,不配置时使用插件内置模板
42
+ "defaultPageTemplate": "./templates/defaultTemplate.ejs",
43
+ // 特殊页面模版文件,匹配原则支持文件通配符
44
+ "customPageTemplate": [
45
+ {
46
+ "srcPath": ["**/component/Home/**/*.ets"],
47
+ "templatePath": "./templates/home_shopping_template.ejs"
48
+ },
49
+ {
50
+ "srcPath": ["**/common/**/*.ets"],
51
+ "templatePath": "./templates/common_template.ejs"
52
+ },
53
+ {
54
+ "srcPath": ["**/live/**/*.ets"],
55
+ "templatePath": "./templates/live_template.ejs"
56
+ }
57
+ ]
58
+ }
59
+ ```
60
+
61
+ ### hmrouter_config.json 配置
62
+
63
+ `hmrouter_config.json`文件用于配置该插件在编译期的行为
64
+
65
+ > 配置文件读取规则为 模块 > 工程 > 默认
66
+ >
67
+ > 优先使用本模块内的配置,如果没有配置,则找模块目录的上级目录(最多找三层目录,找到则停止),若找不到则使用默认配置
68
+
69
+ > 1.0.0-rc.6 版本开始,支持混淆配置`autoObfuscation`
70
+ >
71
+ > 1.0.0-rc.9 版本开始,支持自定义模版配置`customPageTemplate`
72
+
73
+ | 配置项 | 类型 | 是否必填 | 说明 |
74
+ |---------------------|---------|------|----------------------------------------------------------------------------------------------------------------------------------------|
75
+ | scanDir | array | 否 | 指定扫描当前模块路径,默认值为`src/main/ets` |
76
+ | saveGeneratedFile | boolean | 否 | 默认为 false,不保留插件自动生成的代码,如果需要保留,需要设置为 true |
77
+ | autoObfuscation | boolean | 否 | 默认为 false,不自动配置混淆规则,只会生成`hmrouter_obfuscation_rules.txt`文件帮助开发者配置混淆规则;如果设置为 true,会自动配置混淆规则,并在编译完成后删除`hmrouter_obfuscation_rules.txt`文件 |
78
+ | defaultPageTemplate | string | 否 | 默认模版路径,相对于hmrouter_config.json文件,例如:`./templates/defaultTemplate.ejs` |
79
+ | customPageTemplate | object | 否 | srcPath为匹配的代码文件路径,支持通配符,templatePath为模版路径,可以实现不同的代码使用不同的模版来生成 |
80
+
81
+ ## 自定义模板使用
82
+
83
+ 在 `HMRouterPlugin` 中,EJS模板用于生成动态页面或组件,你可以在模板文件中使用 EJS 的语法
84
+
85
+ > EJS语法可阅读参考[官网链接](https://github.com/mde/ejs)
86
+
87
+ **模板文件示例:**
88
+
89
+ ```ejs
90
+ import { <%= componentName %> } from '<%= importPath %>'
91
+
92
+ @Builder
93
+ export function <%= componentName %>Builder(name: string, param: Object) {
94
+ <%= componentName %>Generated()
95
+ }
96
+
97
+ @Component
98
+ export struct <%= componentName %>Generated {
99
+ private pageUrl: string = '<%= pageUrl %>'
100
+
101
+ build() {
102
+ NavDestination() {
103
+ <%= componentName %>()
104
+ }
105
+ <% if(dialog){ %>.mode(NavDestinationMode.DIALOG)<% } %>
106
+ .hideTitleBar(true)
107
+ }
108
+ }
109
+ ```
110
+
111
+ > 模板文件中至少需要包含`NavDestination`组件代码和相对应的`build`函数,缺少会导致编译失败或者页面白屏,插件中会内置一套默认模板,其中包含了**页面展示、生命周期注册、转场动画注册**
112
+
113
+ ### 默认模板介绍
114
+
115
+ 插件默认会根据如下模板来生成`NavDestination`页面代码,如有自定义模板的需求,建议先阅读内置模板的介绍在做更改,书写自定义模板时建议在内置模板基础上添加代码,删除内置模板相关代码可能会导致**编译失败、生命周期生效、转场动画失效等问题**。
116
+
117
+ **默认模版`viewBuilder.ejs`:**
118
+
119
+ ```ejs
120
+ import { <%= componentName %> } from '<%= importPath %>'
121
+ import { TemplateService, TranslateOption, ScaleOption, OpacityOption } from '@hadss/hmrouter'
122
+
123
+ @Builder
124
+ export function <%= componentName %>Builder(name: string, param: Object) {
125
+ <%= componentName %>Generated()
126
+ }
127
+
128
+ @Component
129
+ export struct <%= componentName %>Generated {
130
+ @State translateOption: TranslateOption = new TranslateOption()
131
+ @State scaleOption: ScaleOption = new ScaleOption()
132
+ @State opacityOption: OpacityOption = new OpacityOption()
133
+ private pageUrl: string = '<%= pageUrl %>'
134
+ private ndId: string = ''
135
+ private navigationId: string = ''
136
+
137
+ aboutToAppear(): void {
138
+ this.navigationId = this.queryNavigationInfo()!.navigationId;
139
+ TemplateService.aboutToAppear(this.navigationId, this.pageUrl, <%= dialog %>,
140
+ this.translateOption, this.scaleOption, this.opacityOption)
141
+ }
142
+
143
+ aboutToDisappear(): void {
144
+ TemplateService.aboutToDisappear(this.navigationId, this.pageUrl, this.ndId)
145
+ }
146
+
147
+ build() {
148
+ NavDestination() {
149
+ <%= componentName %>()
150
+ }
151
+ <% if(dialog){ %>.mode(NavDestinationMode.DIALOG)<% } %>
152
+ .hideTitleBar(true)
153
+ .gesture(PanGesture()
154
+ .onActionStart((event: GestureEvent) => {
155
+ TemplateService.interactiveStart(this.navigationId, this.ndId, event)
156
+ })
157
+ .onActionUpdate((event: GestureEvent) =>{
158
+ TemplateService.interactiveProgress(this.navigationId, this.ndId, event)
159
+ })
160
+ .onActionEnd((event: GestureEvent) =>{
161
+ TemplateService.interactiveFinish(this.navigationId, this.ndId, event)
162
+ })
163
+ )
164
+ .translate(this.translateOption)
165
+ .scale(this.scaleOption)
166
+ .opacity(this.opacityOption.opacity)
167
+ .onAppear(() => {
168
+ TemplateService.onAppear(this.navigationId, this.pageUrl, this.ndId)
169
+ })
170
+ .onDisAppear(() => {
171
+ TemplateService.onDisAppear(this.navigationId, this.pageUrl, this.ndId)
172
+ })
173
+ .onShown(() => {
174
+ TemplateService.onShown(this.navigationId, this.pageUrl, this.ndId)
175
+ })
176
+ .onHidden(() => {
177
+ TemplateService.onHidden(this.navigationId, this.pageUrl, this.ndId)
178
+ })
179
+ .onWillAppear(() => {
180
+ TemplateService.onWillAppear(this.navigationId, this.pageUrl)
181
+ })
182
+ .onWillDisappear(() => {
183
+ TemplateService.onWillDisappear(this.navigationId, this.pageUrl, this.ndId)
184
+ })
185
+ .onWillShow(() => {
186
+ TemplateService.onWillShow(this.navigationId, this.pageUrl, this.ndId)
187
+ })
188
+ .onWillHide(() => {
189
+ TemplateService.onWillHide(this.navigationId, this.pageUrl, this.ndId)
190
+ })
191
+ .onReady((navContext: NavDestinationContext) => {
192
+ this.ndId = navContext.navDestinationId!
193
+ TemplateService.onReady(this.navigationId, this.pageUrl, navContext)
194
+ })
195
+ .onBackPressed(() => {
196
+ return TemplateService.onBackPressed(this.navigationId, this.pageUrl, this.ndId)
197
+ })
198
+ }
199
+ }
200
+ ```
201
+
202
+ ### 模板变量
203
+
204
+ | 属性 | 描述 |
205
+ |-------------------|-----------------|
206
+ | pageUrl | 标签中配置的pageUrl的值 |
207
+ | importPath | 原组件的导入路径 |
208
+ | componentName | 原组件名 |
209
+ | dialog | 是否dialog页面 |
210
+ | generatorViewName | 生成的文件名 |
211
+
212
+ ### TemplateService内置模版方法
213
+
214
+ 该类中封装了一系列在模板中需要用到的注册、初始化、事件回调接口
215
+
216
+ | 接口 | 参数 | 返回值 | 接口描述 |
217
+ |----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|------|-----------------------|
218
+ | static aboutToAppear | navigationId: string,pageUrl: string, dialog: boolean, translateOption: TranslateOption, scaleOption: ScaleOption, opacityOption: OpacityOption | void | 注册接口,用于模板代码中注册动画与生命周期 |
219
+ | static aboutToDisappear | navigationId: string, pageUrl: string, ndId: string | void | 销毁,用户销毁一个页面的动画与生命周期实例 |
220
+ | static onDisAppear | navigationId: string, pageUrl: string, navId: string | void | NavDestination生命周期 |
221
+ | static onAppear | navigationId: string, pageUrl: string, navId: string | void | NavDestination生命周期 |
222
+ | static onShown | navigationId: string, pageUrl: string, navId: string | void | NavDestination生命周期 |
223
+ | static onHidden | navigationId: string, pageUrl: string, navId: string | void | NavDestination生命周期 |
224
+ | static onWillAppear | navigationId: string, pageUrl: string | void | NavDestination生命周期 |
225
+ | static onWillDisappear | navigationId: string, pageUrl: string, navId: string | void | NavDestination生命周期 |
226
+ | static onWillShow | navigationId: string, pageUrl: string, navId: string | void | NavDestination生命周期 |
227
+ | static onWillHide | navigationId: string, pageUrl: string, navId: string | void | NavDestination生命周期 |
228
+ | static onReady | navigationId: string, pageUrl: string, navContext: NavDestinationContext | void | NavDestination生命周期 |
229
+ | static onBackPressed | navigationId: string, pageUrl: string, navId: string | void | NavDestination生命周期 |
230
+ | static interactiveStart | navigationId: string, ndId: string, event: GestureEvent | void | 手势转场动画触发 |
231
+ | static interactiveFinish | navigationId: string, ndId: string, event: GestureEvent | void | 手势转场动画更新 |
232
+ | static interactiveProgress | navigationId: string, ndId: string, event: GestureEvent | void | 手势转场动画结束 |
233
+
234
+ ## 依赖系统版本
235
+
236
+ 最低版本
237
+
238
+ ```text
239
+ HarmonyOS NEXT Developer Beta5版本及以上
240
+ DevEco Studio 5.0.3.700及以上
241
+ hvigor 5.5.1及以上
242
+ ```
243
+
244
+ **推荐使用**
245
+
246
+ ```text
247
+ HarmonyOS NEXT Beta1版本及以上
248
+ DevEco Studio 5.0.3.800及以上
249
+ hvigor 5.7.3及以上
250
+ ```
251
+
252
+ > 低于DevEco Studio 5.0.3.800(hvigor 5.7.3)可能会导致远程的 HSP 中定义的 HMRouter 标签与路由表失效,会有如下 WARN 日志
253
+ >
254
+ > ```
255
+ > [HMRouterPlugin] Your DevEco Studio version less than 5.0.3.800, may cause remote hsp dependencies get failed
256
+ > ```
257
+
258
+ ## HMRouter路由框架使用
259
+
260
+ 详见[@hadss/hmrouter](https://ohpm.openharmony.cn/#/cn/detail/@hadss%2Fhmrouter)
@@ -0,0 +1,31 @@
1
+ import { AnalyzerResultLike } from './common/PluginModel';
2
+ import { HMRouterPluginConfig } from './HMRouterPluginConfig';
3
+ export declare class AnalyzerController {
4
+ private analyzeResult;
5
+ analyzeFile(sourceFilePath: string, config: HMRouterPluginConfig): void;
6
+ parseConstants(): void;
7
+ private parsePropertyValue;
8
+ getAnalyzeResultSet(): Set<AnalyzerResultLike>;
9
+ clearAnalyzeResultSet(): void;
10
+ }
11
+ export declare class AnalyzerService {
12
+ private readonly sourceFilePath;
13
+ private sourceFile;
14
+ private config;
15
+ private analyzerResultSet;
16
+ private importMap;
17
+ constructor(sourceFilePath: string, config: HMRouterPluginConfig);
18
+ start(): void;
19
+ getResult(): Set<AnalyzerResultLike>;
20
+ private analyzeImport;
21
+ private analyzeRouter;
22
+ private parseFileByLineOrder;
23
+ private analyzeComponent;
24
+ private addToResultSet;
25
+ private parseDecorator;
26
+ private parseDecoratorArguments;
27
+ private parseIdentifierPropertyValue;
28
+ private parsePropertyValue;
29
+ private getVariableFilePath;
30
+ private getOtherModuleVariableFilePath;
31
+ }