@hadss/hmrouter-plugin 1.0.0-rc.9 → 1.1.1-alpha.0

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 (147) hide show
  1. package/LICENSE +176 -77
  2. package/NOTICE +1365 -0
  3. package/README.md +254 -71
  4. package/dist/HMRouterAnalyzer.d.ts +24 -1
  5. package/dist/HMRouterAnalyzer.js +154 -55
  6. package/dist/HMRouterHvigorPlugin.js +23 -4
  7. package/dist/HMRouterPluginConfig.d.ts +1 -0
  8. package/dist/HMRouterPluginConfig.js +7 -3
  9. package/dist/HMRouterPluginHandle.d.ts +1 -0
  10. package/dist/HMRouterPluginHandle.js +81 -55
  11. package/dist/HMRouterPluginManager.d.ts +9 -0
  12. package/dist/HMRouterPluginManager.js +55 -0
  13. package/dist/Index.d.ts +9 -3
  14. package/dist/Index.js +33 -103
  15. package/dist/common/Logger.js +1 -1
  16. package/dist/common/PluginModel.d.ts +4 -1
  17. package/dist/common/PluginModel.js +2 -1
  18. package/dist/constants/CommonConstants.d.ts +10 -5
  19. package/dist/constants/CommonConstants.js +11 -6
  20. package/dist/constants/ConfigConstants.d.ts +2 -1
  21. package/dist/constants/ConfigConstants.js +3 -2
  22. package/dist/constants/TaskConstants.js +1 -1
  23. package/dist/framework/constants/TaskConstants.d.ts +8 -0
  24. package/dist/framework/constants/TaskConstants.js +12 -0
  25. package/dist/framework/constants/index.d.ts +1 -0
  26. package/dist/framework/constants/index.js +17 -0
  27. package/dist/framework/core/PluginExecutionController.d.ts +15 -0
  28. package/dist/framework/core/PluginExecutionController.js +62 -0
  29. package/dist/framework/core/TaskManager.d.ts +12 -0
  30. package/dist/framework/core/TaskManager.js +67 -0
  31. package/dist/framework/core/TaskStage.d.ts +10 -0
  32. package/dist/framework/core/TaskStage.js +14 -0
  33. package/dist/framework/core/index.d.ts +3 -0
  34. package/dist/framework/core/index.js +19 -0
  35. package/dist/framework/extension/ExtensionManager.d.ts +11 -0
  36. package/dist/framework/extension/ExtensionManager.js +33 -0
  37. package/dist/framework/extension/PluginExtension.d.ts +13 -0
  38. package/dist/framework/extension/PluginExtension.js +6 -0
  39. package/dist/framework/extension/context/ExtensionContextImpl.d.ts +23 -0
  40. package/dist/framework/extension/context/ExtensionContextImpl.js +64 -0
  41. package/dist/framework/extension/context/Interface.d.ts +21 -0
  42. package/dist/framework/extension/context/Interface.js +2 -0
  43. package/dist/framework/extension/context/TemplateMetadataImpl.d.ts +12 -0
  44. package/dist/framework/extension/context/TemplateMetadataImpl.js +22 -0
  45. package/dist/framework/extension/index.d.ts +4 -0
  46. package/dist/framework/extension/index.js +20 -0
  47. package/dist/framework/index.d.ts +4 -0
  48. package/dist/framework/index.js +20 -0
  49. package/dist/framework/utils/FileUtil.d.ts +13 -0
  50. package/dist/framework/utils/FileUtil.js +20 -0
  51. package/dist/framework/utils/Logger.d.ts +12 -0
  52. package/dist/framework/utils/Logger.js +31 -0
  53. package/dist/framework/utils/ModuleTypeUtil.d.ts +4 -0
  54. package/dist/framework/utils/ModuleTypeUtil.js +16 -0
  55. package/dist/framework/utils/ObjectUtils.d.ts +3 -0
  56. package/dist/framework/utils/ObjectUtils.js +14 -0
  57. package/dist/framework/utils/PluginStore.d.ts +10 -0
  58. package/dist/framework/utils/PluginStore.js +29 -0
  59. package/dist/framework/utils/StringUtil.d.ts +3 -0
  60. package/dist/framework/utils/StringUtil.js +18 -0
  61. package/dist/framework/utils/TsAstUtil.d.ts +6 -0
  62. package/dist/framework/utils/TsAstUtil.js +19 -0
  63. package/dist/framework/utils/index.d.ts +7 -0
  64. package/dist/framework/utils/index.js +23 -0
  65. package/dist/hmrouter_extension/HMRouterExtension.d.ts +14 -0
  66. package/dist/hmrouter_extension/HMRouterExtension.js +47 -0
  67. package/dist/hmrouter_extension/HMRouterExtensionContext.d.ts +8 -0
  68. package/dist/hmrouter_extension/HMRouterExtensionContext.js +2 -0
  69. package/dist/hmrouter_extension/analyzer/AnnotationAnalyzerRegistry.d.ts +14 -0
  70. package/dist/hmrouter_extension/analyzer/AnnotationAnalyzerRegistry.js +45 -0
  71. package/dist/hmrouter_extension/analyzer/ComponentAnalyzer.d.ts +12 -0
  72. package/dist/hmrouter_extension/analyzer/ComponentAnalyzer.js +52 -0
  73. package/dist/hmrouter_extension/analyzer/RouterAnalyzer.d.ts +11 -0
  74. package/dist/hmrouter_extension/analyzer/RouterAnalyzer.js +79 -0
  75. package/dist/hmrouter_extension/analyzer/interface/AbstractAnnotationAnalyzer.d.ts +9 -0
  76. package/dist/hmrouter_extension/analyzer/interface/AbstractAnnotationAnalyzer.js +9 -0
  77. package/dist/hmrouter_extension/analyzer/interface/IConstantResolver.d.ts +7 -0
  78. package/dist/hmrouter_extension/analyzer/interface/IConstantResolver.js +2 -0
  79. package/dist/hmrouter_extension/analyzer/utils/ConstantAnalyzer.d.ts +9 -0
  80. package/dist/hmrouter_extension/analyzer/utils/ConstantAnalyzer.js +32 -0
  81. package/dist/hmrouter_extension/analyzer/utils/ConstantResolver.d.ts +15 -0
  82. package/dist/hmrouter_extension/analyzer/utils/ConstantResolver.js +217 -0
  83. package/dist/hmrouter_extension/analyzer/utils/DecoratorParser.d.ts +7 -0
  84. package/dist/hmrouter_extension/analyzer/utils/DecoratorParser.js +41 -0
  85. package/dist/hmrouter_extension/analyzer/utils/ImportAnalyzer.d.ts +4 -0
  86. package/dist/hmrouter_extension/analyzer/utils/ImportAnalyzer.js +35 -0
  87. package/dist/hmrouter_extension/config/HMRouterPluginConfig.d.ts +38 -0
  88. package/dist/hmrouter_extension/config/HMRouterPluginConfig.js +64 -0
  89. package/dist/hmrouter_extension/constants/AnnotationConstants.d.ts +8 -0
  90. package/dist/hmrouter_extension/constants/AnnotationConstants.js +11 -0
  91. package/dist/hmrouter_extension/constants/FilePathConstants.d.ts +19 -0
  92. package/dist/hmrouter_extension/constants/FilePathConstants.js +26 -0
  93. package/dist/hmrouter_extension/constants/ObfuscationConstants.d.ts +5 -0
  94. package/dist/hmrouter_extension/constants/ObfuscationConstants.js +8 -0
  95. package/dist/hmrouter_extension/constants/PluginConstants.d.ts +6 -0
  96. package/dist/hmrouter_extension/constants/PluginConstants.js +9 -0
  97. package/dist/hmrouter_extension/constants/PrefixConstants.d.ts +8 -0
  98. package/dist/hmrouter_extension/constants/PrefixConstants.js +11 -0
  99. package/dist/hmrouter_extension/constants/RouterMapConstants.d.ts +5 -0
  100. package/dist/hmrouter_extension/constants/RouterMapConstants.js +8 -0
  101. package/dist/hmrouter_extension/constants/TemplateConstants.d.ts +6 -0
  102. package/dist/hmrouter_extension/constants/TemplateConstants.js +9 -0
  103. package/dist/hmrouter_extension/constants/VersionConstants.d.ts +6 -0
  104. package/dist/hmrouter_extension/constants/VersionConstants.js +9 -0
  105. package/dist/hmrouter_extension/constants/index.d.ts +8 -0
  106. package/dist/hmrouter_extension/constants/index.js +22 -0
  107. package/dist/hmrouter_extension/error/PluginError.d.ts +29 -0
  108. package/dist/hmrouter_extension/error/PluginError.js +75 -0
  109. package/dist/hmrouter_extension/model/HMAnnotationModel.d.ts +28 -0
  110. package/dist/hmrouter_extension/model/HMAnnotationModel.js +2 -0
  111. package/dist/hmrouter_extension/model/RouterInfo.d.ts +6 -0
  112. package/dist/hmrouter_extension/model/RouterInfo.js +2 -0
  113. package/dist/hmrouter_extension/model/TemplateModel.d.ts +8 -0
  114. package/dist/hmrouter_extension/model/TemplateModel.js +2 -0
  115. package/dist/hmrouter_extension/model/index.d.ts +3 -0
  116. package/dist/hmrouter_extension/model/index.js +19 -0
  117. package/dist/hmrouter_extension/processor/CodeGenerationProcessor.d.ts +13 -0
  118. package/dist/hmrouter_extension/processor/CodeGenerationProcessor.js +117 -0
  119. package/dist/hmrouter_extension/processor/CompletionProcessor.d.ts +11 -0
  120. package/dist/hmrouter_extension/processor/CompletionProcessor.js +59 -0
  121. package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.d.ts +11 -0
  122. package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.js +53 -0
  123. package/dist/hmrouter_extension/processor/InitializerProcessor.d.ts +15 -0
  124. package/dist/hmrouter_extension/processor/InitializerProcessor.js +95 -0
  125. package/dist/hmrouter_extension/processor/ObfuscationProcessor.d.ts +13 -0
  126. package/dist/hmrouter_extension/processor/ObfuscationProcessor.js +121 -0
  127. package/dist/hmrouter_extension/processor/ResourceProcessor.d.ts +9 -0
  128. package/dist/hmrouter_extension/processor/ResourceProcessor.js +53 -0
  129. package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.d.ts +9 -0
  130. package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.js +122 -0
  131. package/dist/hmrouter_extension/processor/index.d.ts +7 -0
  132. package/dist/hmrouter_extension/processor/index.js +23 -0
  133. package/dist/store/PluginStore.d.ts +14 -0
  134. package/dist/store/PluginStore.js +20 -0
  135. package/dist/utils/FileUtil.d.ts +2 -0
  136. package/dist/utils/ObfuscationUtil.js +7 -1
  137. package/dist/utils/TsAstUtil.d.ts +3 -2
  138. package/dist/utils/TsAstUtil.js +51 -11
  139. package/examples/CustomExtension.ts +256 -0
  140. package/package.json +8 -7
  141. package/template/customBuilder.ejs +25 -0
  142. package/template/viewBuilder.ejs +51 -0
  143. package/{viewBuilder.ejs → template/viewBuilder_v1.ejs} +11 -4
  144. package/dist/common/Constant.d.ts +0 -27
  145. package/dist/common/Constant.js +0 -35
  146. package/dist/utils/ConfusionUtil.d.ts +0 -4
  147. package/dist/utils/ConfusionUtil.js +0 -27
@@ -0,0 +1,256 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
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
+
16
+ import { appTasks } from '@ohos/hvigor-ohos-plugin';
17
+ import {
18
+ BaseAnalyzeResult,
19
+ ExtensionContext,
20
+ Logger,
21
+ PluginExtension,
22
+ registerPluginExtension
23
+ } from '@hadss/hmrouter-plugin';
24
+ import { ClassDeclaration, Expression, PropertyAssignment, SourceFile, SyntaxKind } from 'ts-morph';
25
+
26
+ interface RouterInfo {
27
+ name: string;
28
+ pageSourceFile: string;
29
+ buildFunction: string;
30
+ customData: Record<string, any>;
31
+ }
32
+
33
+ interface MyExtensionContext extends ExtensionContext {
34
+ customPages?: RouterInfo[];
35
+ routerMap: RouterInfo[];
36
+ }
37
+
38
+ interface MyAnalyzeResult extends BaseAnalyzeResult {
39
+ [key: string]: any;
40
+ }
41
+
42
+ // 示例1: RouterParam注解分析器
43
+ export class RouterParamAnalyzer {
44
+ readonly name = 'RouterParamAnalyzer';
45
+
46
+ analyze(sourceFile: SourceFile, filePath: string, context: MyExtensionContext): void {
47
+ Logger.debug('', `开始分析RouterParam注解: ${filePath}`);
48
+
49
+ // 获取所有ExpressionStatement以获取struct关键字后面的组件名称
50
+ const viewNameArr = sourceFile
51
+ .getChildrenOfKind(SyntaxKind.ExpressionStatement)
52
+ .map((node) => node.getText())
53
+ .filter((text) => text !== 'struct');
54
+
55
+ // 解析结构体声明中的RouterParam注解
56
+ sourceFile.getChildrenOfKind(SyntaxKind.MissingDeclaration).forEach((node, index) => {
57
+ node.getChildrenOfKind(SyntaxKind.Decorator).forEach((decorator) => {
58
+ if (decorator.getName() === "RouterParam") {
59
+ // 解析RouterParam注解的参数
60
+ const result: MyAnalyzeResult = {
61
+ name: viewNameArr[index],
62
+ annotation: decorator.getName(),
63
+ sourceFilePath: filePath
64
+ };
65
+
66
+ // 解析装饰器参数
67
+ decorator.getArguments().forEach((arg) => {
68
+ const objLiteral = arg.asKind(SyntaxKind.ObjectLiteralExpression);
69
+ if (objLiteral) {
70
+ objLiteral.getProperties().forEach((prop) => {
71
+ if (prop.getKind() === SyntaxKind.PropertyAssignment) {
72
+ const propertyAssignment = prop as PropertyAssignment;
73
+ const propertyName = propertyAssignment.getName();
74
+ const initializer = propertyAssignment.getInitializer();
75
+
76
+ if (initializer) {
77
+ // 将解析结果添加到result对象
78
+ result[propertyName] = this.parsePrimitiveValue(initializer);
79
+ }
80
+ }
81
+ });
82
+ }
83
+ });
84
+
85
+ // 如果需要后续保存到路由表中请调用addAnalyzeResults添加分析结果
86
+ // context.addAnalyzeResults(result);
87
+
88
+ // 为组件添加模板数据,用于代码生成
89
+ context.addTemplateData(result.name, {
90
+ paramType: result['paramType'] || 'default',
91
+ isCustomParam: true,
92
+ customParams: result['params'] || [],
93
+ sourceFile: filePath
94
+ });
95
+
96
+ Logger.debug('', `发现RouterParam注解: ${result.name}`);
97
+ }
98
+ });
99
+ });
100
+ }
101
+
102
+ private parsePrimitiveValue(value: Expression): any {
103
+ let propertyValue;
104
+ switch (value.getKind()) {
105
+ case SyntaxKind.StringLiteral:
106
+ propertyValue = value.asKind(SyntaxKind.StringLiteral)?.getLiteralValue();
107
+ break;
108
+ case SyntaxKind.NumericLiteral:
109
+ propertyValue = value.asKind(SyntaxKind.NumericLiteral)?.getLiteralValue();
110
+ break;
111
+ case SyntaxKind.TrueKeyword:
112
+ propertyValue = true;
113
+ break;
114
+ case SyntaxKind.FalseKeyword:
115
+ propertyValue = false;
116
+ break;
117
+ case SyntaxKind.ArrayLiteralExpression:
118
+ propertyValue = value
119
+ .asKind(SyntaxKind.ArrayLiteralExpression)
120
+ ?.getElements()
121
+ .map((item) => {
122
+ if (item.getKind() === SyntaxKind.StringLiteral) {
123
+ return item.asKind(SyntaxKind.StringLiteral)?.getLiteralValue();
124
+ }
125
+ return null;
126
+ })
127
+ .filter(item => item !== null);
128
+ break;
129
+ }
130
+ return propertyValue;
131
+ }
132
+ }
133
+
134
+ // 示例2: CustomPage注解分析器
135
+ export class CustomPageAnalyzer {
136
+ readonly name = 'CustomPageAnalyzer';
137
+
138
+ analyze(sourceFile: SourceFile, filePath: string, context: MyExtensionContext): void {
139
+ Logger.debug('', `开始分析CustomPage注解: ${filePath}`);
140
+
141
+ // 分析使用@CustomPage注解的类
142
+ sourceFile.getClasses().forEach((cls: ClassDeclaration) => {
143
+ cls.getDecorators().forEach(decorator => {
144
+ if (decorator.getName() === 'CustomPage') {
145
+ const className = cls.getName() || '';
146
+
147
+ // 创建分析结果
148
+ const result: MyAnalyzeResult = {
149
+ name: className,
150
+ annotation: 'CustomPage',
151
+ sourceFilePath: filePath
152
+ };
153
+
154
+ // 解析装饰器参数
155
+ decorator.getArguments().forEach((arg) => {
156
+ const objLiteral = arg.asKind(SyntaxKind.ObjectLiteralExpression);
157
+ if (objLiteral) {
158
+ objLiteral.getProperties().forEach((prop) => {
159
+ if (prop.getKind() === SyntaxKind.PropertyAssignment) {
160
+ const propertyAssignment = prop as PropertyAssignment;
161
+ const propertyName = propertyAssignment.getName();
162
+ const initializer = propertyAssignment.getInitializer();
163
+
164
+ if (initializer && initializer.getKind() === SyntaxKind.StringLiteral) {
165
+ result[propertyName] = initializer.asKind(SyntaxKind.StringLiteral)?.getLiteralValue();
166
+ }
167
+ }
168
+ });
169
+ }
170
+ });
171
+
172
+ // 添加分析结果
173
+ context.addAnalyzeResults(result);
174
+
175
+ // 存储自定义页面路径信息
176
+ const customPages = context.customPages || [];
177
+ customPages.push(result);
178
+ context.customPages = customPages;
179
+
180
+ Logger.debug('', `发现CustomPage注解: ${className}, pageUrl: ${result['pageUrl']}`);
181
+ }
182
+ });
183
+ });
184
+ }
185
+ }
186
+
187
+ // 插件扩展类
188
+ export class CustomPluginExtension extends PluginExtension<MyExtensionContext> {
189
+ get name(): string {
190
+ return 'CustomPluginExtension';
191
+ }
192
+
193
+ // 提供注解分析器
194
+ afterAnnotationAnalysis(sourceFile: SourceFile, filePath: string, context: MyExtensionContext): void {
195
+ const analyzers = [new RouterParamAnalyzer(), new CustomPageAnalyzer()];
196
+ for (const analyzer of analyzers) {
197
+ analyzer.analyze(sourceFile, filePath, context);
198
+ }
199
+ }
200
+
201
+ // 代码生成阶段,可以使用RouterParam注解分析结果
202
+ afterCodeGeneration(context: MyExtensionContext): void {
203
+ // 获取所有模板数据
204
+ const templateDataMap = context.getTemplateDataMap();
205
+
206
+ // 示例: 输出找到的RouterParam数据
207
+ for (const [componentName, templateData] of templateDataMap.entries()) {
208
+ if (templateData.isCustomParam) {
209
+ Logger.info(
210
+ this.name,
211
+ `组件 ${componentName} 将使用自定义参数类型: ${templateData.paramType}`
212
+ );
213
+ // 实际场景可以在此生成额外的代码
214
+ }
215
+ }
216
+ }
217
+
218
+ // 路由表构建阶段,将CustomPage注解分析结果添加到路由表
219
+ afterRouterMapBuilding(context: MyExtensionContext): void {
220
+ // 从私有存储获取CustomPage分析结果
221
+ const customPages = context.customPages || [];
222
+
223
+ // 将CustomPage添加到路由表
224
+ for (const page of customPages) {
225
+ const pageUrl = page.customData['pageUrl'];
226
+ if (pageUrl) {
227
+ // 检查路由表中是否已存在该路径
228
+ const existingRoute = context.routerMap.find(route => route.customData.pageUrl === pageUrl);
229
+ if (!existingRoute) {
230
+ // 创建新的路由项并添加到路由表
231
+ context.routerMap.push({
232
+ name: pageUrl,
233
+ buildFunction: page.name,
234
+ pageSourceFile: page.pageSourceFile,
235
+ customData: {
236
+ ...page.customData,
237
+ }
238
+ });
239
+
240
+ Logger.info(
241
+ this.name,
242
+ `添加自定义页面到路由表: ${pageUrl} -> ${page.name}`
243
+ );
244
+ }
245
+ }
246
+ }
247
+ }
248
+ }
249
+
250
+ // 注册扩展
251
+ registerPluginExtension(new CustomPluginExtension());
252
+
253
+ export default {
254
+ system: appTasks,
255
+ plugins: []
256
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hadss/hmrouter-plugin",
3
- "version": "1.0.0-rc.9",
3
+ "version": "1.1.1-alpha.0",
4
4
  "description": "HMRouter Compiler Plugin",
5
5
  "main": "dist/Index.js",
6
6
  "scripts": {
@@ -8,7 +8,6 @@
8
8
  "test": "cross-env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha",
9
9
  "dev": "tsc && node dist/index.js",
10
10
  "build": "tsc",
11
- "package": "tsc && npm pack && mv hadss*.tgz ../libs",
12
11
  "release": "tsc && npm publish --access public"
13
12
  },
14
13
  "keywords": [
@@ -24,8 +23,9 @@
24
23
  "ts-morph": "^23.0.0"
25
24
  },
26
25
  "devDependencies": {
27
- "@ohos/hvigor": "5.7.4",
28
- "@ohos/hvigor-ohos-plugin": "5.7.4",
26
+ "@ohos/hvigor": "^5.8.9",
27
+ "@ohos/hvigor-ohos-plugin": "^5.8.9",
28
+ "typescript": "4.9.5",
29
29
  "@types/chai": "^4.3.19",
30
30
  "@types/ejs": "^3.1.5",
31
31
  "@types/micromatch": "^4.0.9",
@@ -39,9 +39,10 @@
39
39
  "publishConfig": {
40
40
  "registry": "https://registry.npmjs.org"
41
41
  },
42
- "homepage": "https://gitee.com/hadss/hmrouter",
42
+ "homepage": "https://gitcode.com/openharmony-sig/ohrouter",
43
43
  "repository": {
44
44
  "type": "git",
45
- "url": "https://gitee.com/hadss/hmrouter"
45
+ "url": "https://gitcode.com/openharmony-sig/ohrouter.git",
46
+ "directory": "HMRouterPlugin"
46
47
  }
47
- }
48
+ }
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
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
+
16
+ // instrument ignore file
17
+ // auto-generated <%= componentName %>Builder.ets by HMRouter
18
+ import <%if(isDefaultExport) {%> <%= componentName %> <% } else {%> { <%= componentName %> } <% } %> from '<%= importPath %>'
19
+
20
+ @Builder
21
+ export function <%= componentName %>Builder(name: string, param: Object) {
22
+ <%= componentName %>()
23
+ }
24
+
25
+ export const <%= componentName %>BuilderWrapBuilder = wrapBuilder(<%= componentName %>Builder)
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
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
+
16
+ // instrument ignore file
17
+ // auto-generated <%= componentName %>Builder.ets by HMRouter
18
+ import <%if(isDefaultExport) {%> <%= componentName %> <% } else {%> { <%= componentName %> } <% } %> from '<%= importPath %>'
19
+ import { NavDestinationHelper } from '@hadss/hmrouter';
20
+
21
+ @Builder
22
+ export function <%= componentName %>Builder(name: string, param: Object) {
23
+ <%= componentName %>Generated()
24
+ }
25
+
26
+ export const <%= componentName %>BuilderWrapBuilder = wrapBuilder(<%= componentName %>Builder)
27
+
28
+ @Component
29
+ export struct <%= componentName %>Generated {
30
+ private helper: NavDestinationHelper = new NavDestinationHelper(this);
31
+
32
+ build() {
33
+ NavDestination() {
34
+ <%= componentName %>()
35
+ }
36
+ <% if(dialog){ %>.mode(NavDestinationMode.DIALOG)<% } %>
37
+ .hideTitleBar(true)
38
+ .attributeModifier(this.helper.modifier)
39
+ .gestureModifier(this.helper.gestureModifier)
40
+ .onWillAppear(()=>{this.helper.onWillAppear()})
41
+ .onAppear(() => {this.helper.onAppear()})
42
+ .onWillShow(()=>{this.helper.onWillAppear()})
43
+ .onShown(()=>{this.helper.onShown()})
44
+ .onWillHide(()=>{this.helper.onWillHide()})
45
+ .onHidden(()=>{this.helper.onHidden()})
46
+ .onWillDisappear(()=>{this.helper.onWillDisappear()})
47
+ .onDisAppear(()=>{this.helper.onDisAppear()})
48
+ .onReady((ctx)=>{this.helper.onReady(ctx)})
49
+ .onBackPressed(()=> this.helper.onBackPressed())
50
+ }
51
+ }
@@ -13,26 +13,31 @@
13
13
  * limitations under the License.
14
14
  */
15
15
 
16
+ // instrument ignore file
16
17
  // auto-generated <%= componentName %>Builder.ets by HMRouter
17
- import { <%= componentName %> } from '<%= importPath %>'
18
- import { TemplateService, TranslateOption, ScaleOption, OpacityOption } from '@hadss/hmrouter'
18
+ import <%if(isDefaultExport) {%> <%= componentName %> <% } else {%> { <%= componentName %> } <% } %> from '<%= importPath %>'
19
+ import { TemplateService, TranslateOption, ScaleOption, OpacityOption, HMRouterMgr } from '@hadss/hmrouter'
19
20
 
20
21
  @Builder
21
22
  export function <%= componentName %>Builder(name: string, param: Object) {
22
23
  <%= componentName %>Generated()
23
24
  }
24
25
 
26
+ export const <%= componentName %>BuilderWrapBuilder = wrapBuilder(<%= componentName %>Builder)
27
+
25
28
  @Component
26
29
  export struct <%= componentName %>Generated {
27
30
  @State translateOption: TranslateOption = new TranslateOption()
28
31
  @State scaleOption: ScaleOption = new ScaleOption()
29
32
  @State opacityOption: OpacityOption = new OpacityOption()
30
- private pageUrl: string = '<%= pageUrl %>'
33
+ private pageUrl: string = ''
31
34
  private ndId: string = ''
32
35
  private navigationId: string = ''
33
36
 
34
37
  aboutToAppear(): void {
35
38
  this.navigationId = this.queryNavigationInfo()!.navigationId;
39
+ const allPathName = HMRouterMgr.getPathStack(this.navigationId)?.getAllPathName();
40
+ this.pageUrl = allPathName ? allPathName[allPathName.length - 1] : '';
36
41
  TemplateService.aboutToAppear(this.navigationId, this.pageUrl, <%= dialog %>,
37
42
  this.translateOption, this.scaleOption, this.opacityOption)
38
43
  }
@@ -47,7 +52,6 @@ export struct <%= componentName %>Generated {
47
52
  }
48
53
  <% if(dialog){ %>.mode(NavDestinationMode.DIALOG)<% } %>
49
54
  .hideTitleBar(true)
50
- .hitTestBehavior(HitTestMode.Transparent)
51
55
  .gesture(PanGesture()
52
56
  .onActionStart((event: GestureEvent) => {
53
57
  TemplateService.interactiveStart(this.navigationId, this.ndId, event)
@@ -58,6 +62,9 @@ export struct <%= componentName %>Generated {
58
62
  .onActionEnd((event: GestureEvent) =>{
59
63
  TemplateService.interactiveFinish(this.navigationId, this.ndId, event)
60
64
  })
65
+ .onActionCancel(() =>{
66
+ TemplateService.interactiveCancel(this.navigationId, this.ndId)
67
+ })
61
68
  )
62
69
  .translate(this.translateOption)
63
70
  .scale(this.scaleOption)
@@ -1,27 +0,0 @@
1
- export declare class HMRouterPluginConstant {
2
- static readonly ANIMATOR_PREFIX = "__animator__";
3
- static readonly INTERCEPTOR_PREFIX = "__interceptor__";
4
- static readonly LIFECYCLE_PREFIX = "__lifecycle__";
5
- static readonly SERVICE_PREFIX = "__service__";
6
- static readonly PAGE_URL_PREFIX = "";
7
- static readonly FILE_SEPARATOR: "\\" | "/";
8
- static readonly DELIMITER = "/";
9
- static readonly MODULE_ROUTER_MAP_NAME = "$profile:hm_router_map";
10
- static readonly ROUTER_MAP_NAME = "hm_router_map.json";
11
- static readonly TEMP_ROUTER_MAP_PATH = "../../intermediates/router_map";
12
- static readonly RAWFILE_DIR = "src/main/resources/rawfile/hm_router_map.json";
13
- static readonly VIEW_NAME_PREFIX = "HM";
14
- static readonly VIEW_NAME_SUFFIX = ".ets";
15
- static readonly JSON_SUFFIX = ".json";
16
- static readonly HAP_PLUGIN_ID = "HAP_HMROUTER_PLUGIN";
17
- static readonly HSP_PLUGIN_ID = "HSP_HMROUTER_PLUGIN";
18
- static readonly HAR_PLUGIN_ID = "HAR_HMROUTER_PLUGIN";
19
- static readonly ROUTER_ANNOTATION = "HMRouter";
20
- static readonly ANIMATOR_ANNOTATION = "HMAnimator";
21
- static readonly INTERCEPTOR_ANNOTATION = "HMInterceptor";
22
- static readonly LIFECYCLE_ANNOTATION = "HMLifecycle";
23
- static readonly SERVICE_ANNOTATION = "HMService";
24
- static readonly CLASS_ANNOTATION_ARR: string[];
25
- static readonly CONFIG_FILE_NAME = "hmrouter_config.json";
26
- static readonly PARENT_DELIMITER = "../";
27
- }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.HMRouterPluginConstant = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- class HMRouterPluginConstant {
9
- }
10
- exports.HMRouterPluginConstant = HMRouterPluginConstant;
11
- HMRouterPluginConstant.ANIMATOR_PREFIX = '__animator__';
12
- HMRouterPluginConstant.INTERCEPTOR_PREFIX = '__interceptor__';
13
- HMRouterPluginConstant.LIFECYCLE_PREFIX = '__lifecycle__';
14
- HMRouterPluginConstant.SERVICE_PREFIX = '__service__';
15
- HMRouterPluginConstant.PAGE_URL_PREFIX = '';
16
- HMRouterPluginConstant.FILE_SEPARATOR = path_1.default.sep;
17
- HMRouterPluginConstant.DELIMITER = '/';
18
- HMRouterPluginConstant.MODULE_ROUTER_MAP_NAME = '$profile:hm_router_map';
19
- HMRouterPluginConstant.ROUTER_MAP_NAME = 'hm_router_map.json';
20
- HMRouterPluginConstant.TEMP_ROUTER_MAP_PATH = '../../intermediates/router_map';
21
- HMRouterPluginConstant.RAWFILE_DIR = 'src/main/resources/rawfile/hm_router_map.json';
22
- HMRouterPluginConstant.VIEW_NAME_PREFIX = 'HM';
23
- HMRouterPluginConstant.VIEW_NAME_SUFFIX = '.ets';
24
- HMRouterPluginConstant.JSON_SUFFIX = '.json';
25
- HMRouterPluginConstant.HAP_PLUGIN_ID = 'HAP_HMROUTER_PLUGIN';
26
- HMRouterPluginConstant.HSP_PLUGIN_ID = 'HSP_HMROUTER_PLUGIN';
27
- HMRouterPluginConstant.HAR_PLUGIN_ID = 'HAR_HMROUTER_PLUGIN';
28
- HMRouterPluginConstant.ROUTER_ANNOTATION = 'HMRouter';
29
- HMRouterPluginConstant.ANIMATOR_ANNOTATION = 'HMAnimator';
30
- HMRouterPluginConstant.INTERCEPTOR_ANNOTATION = 'HMInterceptor';
31
- HMRouterPluginConstant.LIFECYCLE_ANNOTATION = 'HMLifecycle';
32
- HMRouterPluginConstant.SERVICE_ANNOTATION = 'HMService';
33
- HMRouterPluginConstant.CLASS_ANNOTATION_ARR = ['HMAnimator', 'HMInterceptor', 'HMLifecycle'];
34
- HMRouterPluginConstant.CONFIG_FILE_NAME = 'hmrouter_config.json';
35
- HMRouterPluginConstant.PARENT_DELIMITER = '../';
@@ -1,4 +0,0 @@
1
- import { RouterInfo } from '../common/PluginModel';
2
- export default class ConfusionUtil {
3
- static buildObfuscatedStrings(routerMap: RouterInfo[]): string;
4
- }
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const CommonConstants_1 = __importDefault(require("../constants/CommonConstants"));
7
- class ConfusionUtil {
8
- static buildObfuscatedStrings(routerMap) {
9
- let srcPathArr = [...new Set(routerMap.map((routerInfo) => {
10
- return CommonConstants_1.default.CURRENT_DELIMITER + routerInfo.pageSourceFile;
11
- }))];
12
- let classNameArr = [...new Set(routerMap.filter((routerInfo) => {
13
- return routerInfo.name.includes('__');
14
- }).map((routerInfo) => {
15
- return routerInfo.customData.name;
16
- }))];
17
- let functionName = [...new Set(routerMap.filter((routerInfo) => {
18
- return routerInfo.name.includes(CommonConstants_1.default.SERVICE_PREFIX);
19
- }).map((routerInfo) => {
20
- return routerInfo.customData.functionName;
21
- }))];
22
- return CommonConstants_1.default.KEEP_FILE_NAME + CommonConstants_1.default.LINE_BREAK +
23
- srcPathArr.concat(CommonConstants_1.default.KEEP_PROPERTY_NAME, classNameArr, functionName)
24
- .join(CommonConstants_1.default.LINE_BREAK);
25
- }
26
- }
27
- exports.default = ConfusionUtil;