@hadss/hmrouter-plugin 1.2.1 → 1.2.3-rc.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.
- package/README.md +12 -2
- package/dist/HMRouterPluginManager.d.ts +2 -1
- package/dist/HMRouterPluginManager.js +7 -4
- package/dist/Index.js +6 -5
- package/dist/framework/core/PluginExecutionController.d.ts +1 -1
- package/dist/framework/core/PluginExecutionController.js +2 -1
- package/dist/framework/extension/context/ExtensionContextImpl.d.ts +1 -0
- package/dist/framework/extension/context/Interface.d.ts +1 -0
- package/dist/hmrouter_extension/HMRouterExtension.js +12 -0
- package/dist/hmrouter_extension/constants/FilePathConstants.d.ts +1 -0
- package/dist/hmrouter_extension/constants/FilePathConstants.js +1 -0
- package/dist/hmrouter_extension/constants/TemplateConstants.d.ts +1 -0
- package/dist/hmrouter_extension/constants/TemplateConstants.js +1 -0
- package/dist/hmrouter_extension/constants/VersionConstants.d.ts +2 -0
- package/dist/hmrouter_extension/constants/VersionConstants.js +2 -0
- package/dist/hmrouter_extension/processor/CodeGenerationProcessor.d.ts +4 -0
- package/dist/hmrouter_extension/processor/CodeGenerationProcessor.js +95 -14
- package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.d.ts +1 -0
- package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.js +9 -1
- package/dist/hmrouter_extension/processor/InitializerProcessor.js +4 -0
- package/dist/hmrouter_extension/processor/ObfuscationProcessor.js +8 -1
- package/dist/hmrouter_extension/processor/ResourceProcessor.js +9 -2
- package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.js +8 -3
- package/package.json +3 -3
- package/template/viewBuilder_v1_1.ejs +51 -0
package/README.md
CHANGED
|
@@ -16,12 +16,14 @@ HMRouter编译插件是一个基于hvigor的编译插件,用于:
|
|
|
16
16
|
|
|
17
17
|
### 工程级配置
|
|
18
18
|
|
|
19
|
+
***插件版本建议和库的版本保持一致***
|
|
20
|
+
|
|
19
21
|
在工程的`hvigor/hvigor-config.json`文件中添加路由编译插件:
|
|
20
22
|
|
|
21
23
|
```json5
|
|
22
24
|
{
|
|
23
25
|
"dependencies": {
|
|
24
|
-
"@hadss/hmrouter-plugin": "^1.2.
|
|
26
|
+
"@hadss/hmrouter-plugin": "^1.2.3-rc.0" // 使用最新版本
|
|
25
27
|
},
|
|
26
28
|
// ...其余配置
|
|
27
29
|
}
|
|
@@ -438,9 +440,17 @@ hvigor 5.7.3及以上
|
|
|
438
440
|
|
|
439
441
|
## 更新日志
|
|
440
442
|
|
|
443
|
+
### 1.2.3-rc.0 (2025.12.11)
|
|
444
|
+
|
|
445
|
+
- [修复库版本与插件版本不匹配时编译报错的问题](https://gitcode.com/openharmony-sig/ohrouter/issues/250)
|
|
446
|
+
|
|
447
|
+
### 1.2.2 (2025.10.24)
|
|
448
|
+
|
|
449
|
+
- [修复系统路由表合并异常的问题](https://gitcode.com/openharmony-sig/ohrouter/issues/215)
|
|
450
|
+
|
|
441
451
|
### 1.2.1 (2025.10.20)
|
|
442
452
|
|
|
443
|
-
- [修复低版本IDE
|
|
453
|
+
- [修复低版本IDE编译错误的问题](https://gitcode.com/openharmony-sig/ohrouter/issues/206)
|
|
444
454
|
|
|
445
455
|
### 1.2.0 (2025.09.28)
|
|
446
456
|
|
|
@@ -4,8 +4,9 @@ export declare class HMRouterPluginManager {
|
|
|
4
4
|
private static instance;
|
|
5
5
|
private controllerMap;
|
|
6
6
|
private moduleNodes;
|
|
7
|
+
private nodeIgnored;
|
|
7
8
|
private constructor();
|
|
8
9
|
static getInstance(): HMRouterPluginManager;
|
|
9
10
|
registerPlugin(node: HvigorNode, pluginId: string, options: PluginParam): void;
|
|
10
|
-
addModuleNode(node: HvigorNode): void;
|
|
11
|
+
addModuleNode(node: HvigorNode, isIgnored: boolean): void;
|
|
11
12
|
}
|
|
@@ -9,6 +9,7 @@ class HMRouterPluginManager {
|
|
|
9
9
|
constructor() {
|
|
10
10
|
this.controllerMap = new Map();
|
|
11
11
|
this.moduleNodes = [];
|
|
12
|
+
this.nodeIgnored = new Set();
|
|
12
13
|
framework_1.Logger.info('', 'HMRouterPlugin starting...');
|
|
13
14
|
(0, framework_1.registerPluginExtension)(new HMRouterExtension_1.HMRouterDefaultExtension());
|
|
14
15
|
hvigor_1.hvigor.nodesEvaluated(() => {
|
|
@@ -16,7 +17,6 @@ class HMRouterPluginManager {
|
|
|
16
17
|
if (this.controllerMap.has(node.getNodeName())) {
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
|
-
;
|
|
20
20
|
node.getAllPluginIds().forEach((pluginId) => {
|
|
21
21
|
this.registerPlugin(node, pluginId, {});
|
|
22
22
|
});
|
|
@@ -47,7 +47,7 @@ class HMRouterPluginManager {
|
|
|
47
47
|
if (!moduleContext) {
|
|
48
48
|
throw PluginError_1.PluginError.create(PluginError_1.ErrorCode.ERROR_CONFIG, node.getNodeName(), node.getNodePath());
|
|
49
49
|
}
|
|
50
|
-
const controller = new framework_1.PluginExecutionController(node, moduleContext, options.extensions);
|
|
50
|
+
const controller = new framework_1.PluginExecutionController(node, moduleContext, this.nodeIgnored.has(node.getNodeName()), options.extensions);
|
|
51
51
|
this.controllerMap.set(node.getNodeName(), controller);
|
|
52
52
|
if ((0, framework_1.isHspModule)(node)) {
|
|
53
53
|
let packageJsonPath = framework_1.PluginFileUtil.pathResolve(node.getNodePath(), 'oh-package.json5');
|
|
@@ -63,12 +63,15 @@ class HMRouterPluginManager {
|
|
|
63
63
|
framework_1.PluginStore.getInstance().get('hspModuleNames')?.push(packageJson.name);
|
|
64
64
|
framework_1.PluginStore.getInstance().get('hspModulesInfo')?.push({
|
|
65
65
|
moduleName: node.getNodeName(),
|
|
66
|
-
packageName: packageJson.name
|
|
66
|
+
packageName: packageJson.name,
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
addModuleNode(node) {
|
|
70
|
+
addModuleNode(node, isIgnored) {
|
|
71
71
|
this.moduleNodes.push(node);
|
|
72
|
+
if (isIgnored) {
|
|
73
|
+
this.nodeIgnored.add(node.getNodeName());
|
|
74
|
+
}
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
exports.HMRouterPluginManager = HMRouterPluginManager;
|
package/dist/Index.js
CHANGED
|
@@ -65,16 +65,17 @@ function appPlugin(options) {
|
|
|
65
65
|
if (!options) {
|
|
66
66
|
throw new Error('No options provided');
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
handleNode(options, node);
|
|
69
69
|
},
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
exports.appPlugin = appPlugin;
|
|
73
|
-
function
|
|
74
|
-
node.subNodes(subNode => {
|
|
73
|
+
function handleNode(options, node) {
|
|
74
|
+
node.subNodes((subNode) => {
|
|
75
|
+
let isIgnored = false;
|
|
75
76
|
if (options.ignoreModuleNames.includes(subNode.getNodeName())) {
|
|
76
|
-
|
|
77
|
+
isIgnored = true;
|
|
77
78
|
}
|
|
78
|
-
HMRouterPluginManager_1.HMRouterPluginManager.getInstance().addModuleNode(subNode);
|
|
79
|
+
HMRouterPluginManager_1.HMRouterPluginManager.getInstance().addModuleNode(subNode, isIgnored);
|
|
79
80
|
});
|
|
80
81
|
}
|
|
@@ -7,7 +7,7 @@ export declare class PluginExecutionController {
|
|
|
7
7
|
private readonly taskManager;
|
|
8
8
|
private readonly baseContext;
|
|
9
9
|
private originalBuilderDir?;
|
|
10
|
-
constructor(node: HvigorNode, moduleContext: OhosModuleContext, moduleExtensions?: PluginExtension[]);
|
|
10
|
+
constructor(node: HvigorNode, moduleContext: OhosModuleContext, moduleIgnored: boolean, moduleExtensions?: PluginExtension[]);
|
|
11
11
|
start(): void;
|
|
12
12
|
complete(): void;
|
|
13
13
|
private initializeContext;
|
|
@@ -7,10 +7,11 @@ const constants_1 = require("../constants");
|
|
|
7
7
|
const extension_1 = require("../extension");
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
9
|
class PluginExecutionController {
|
|
10
|
-
constructor(node, moduleContext, moduleExtensions) {
|
|
10
|
+
constructor(node, moduleContext, moduleIgnored, moduleExtensions) {
|
|
11
11
|
this.node = node;
|
|
12
12
|
this.moduleContext = moduleContext;
|
|
13
13
|
this.baseContext = this.initializeContext();
|
|
14
|
+
this.baseContext.moduleIgnored = moduleIgnored;
|
|
14
15
|
this.taskManager = new TaskManager_1.TaskManager(this.baseContext, moduleExtensions);
|
|
15
16
|
}
|
|
16
17
|
start() {
|
|
@@ -5,6 +5,7 @@ export declare class ExtensionContextImpl implements ExtensionContext {
|
|
|
5
5
|
node: HvigorNode;
|
|
6
6
|
moduleContext: OhosModuleContext;
|
|
7
7
|
currentTarget?: Target;
|
|
8
|
+
moduleIgnored?: boolean;
|
|
8
9
|
private moduleScanFilesMaster;
|
|
9
10
|
private templateMetadata;
|
|
10
11
|
private perTargetState;
|
|
@@ -10,6 +10,7 @@ export interface BaseExtensionContext {
|
|
|
10
10
|
readonly moduleContext: OhosModuleContext;
|
|
11
11
|
readonly currentView: ReadonlyArray<BaseAnalyzeResult>;
|
|
12
12
|
currentTarget?: Target;
|
|
13
|
+
moduleIgnored?: boolean;
|
|
13
14
|
scanFiles: string[];
|
|
14
15
|
}
|
|
15
16
|
export interface ExtensionContext extends BaseExtensionContext {
|
|
@@ -15,6 +15,10 @@ class HMRouterDefaultExtension extends framework_1.PluginExtension {
|
|
|
15
15
|
initializer.execute();
|
|
16
16
|
}
|
|
17
17
|
afterAnnotationAnalysis(sourceFile, filePath, context) {
|
|
18
|
+
if (context.moduleIgnored) {
|
|
19
|
+
framework_2.Logger.debug(this.name, 'module ignored: annotationAnalysis');
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
18
22
|
AnnotationAnalyzerRegistry_1.AnnotationAnalyzerRegistry.getInstance().initialize(context.config.modulePath);
|
|
19
23
|
const analyzers = AnnotationAnalyzerRegistry_1.AnnotationAnalyzerRegistry.getInstance().getAnalyzers();
|
|
20
24
|
for (const analyzer of analyzers) {
|
|
@@ -78,6 +82,10 @@ class HMRouterDefaultExtension extends framework_1.PluginExtension {
|
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
afterCodeGeneration(context) {
|
|
85
|
+
if (context.moduleIgnored) {
|
|
86
|
+
framework_2.Logger.debug(this.name, 'module ignored: codeGeneration');
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
81
89
|
const generator = new processor_1.CodeGenerationProcessor(context);
|
|
82
90
|
generator.execute();
|
|
83
91
|
}
|
|
@@ -90,6 +98,10 @@ class HMRouterDefaultExtension extends framework_1.PluginExtension {
|
|
|
90
98
|
processor.execute();
|
|
91
99
|
}
|
|
92
100
|
afterObfuscationProcess(context) {
|
|
101
|
+
if (context.moduleIgnored) {
|
|
102
|
+
framework_2.Logger.debug(this.name, 'module ignored: obfuscationProcess');
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
93
105
|
const processor = new processor_1.ObfuscationProcessor(context);
|
|
94
106
|
processor.execute();
|
|
95
107
|
}
|
|
@@ -12,6 +12,7 @@ export default class FilePathConstants {
|
|
|
12
12
|
static readonly CURRENT_DELIMITER = "./";
|
|
13
13
|
static readonly OH_MODULE_PATH = "oh_modules";
|
|
14
14
|
static readonly OH_PACKAGE_FILE_NAME = "oh-package.json5";
|
|
15
|
+
static readonly OH_PACKAGE_LOCK_FILE_NAME = "oh-package-lock.json5";
|
|
15
16
|
static readonly LINE_BREAK = "\n";
|
|
16
17
|
static readonly BUILD_PROFILE = "build-profile.json5";
|
|
17
18
|
static readonly SDK_HOME = "default/openharmony/ets/oh-uni-package.json";
|
|
@@ -20,6 +20,7 @@ FilePathConstants.PARENT_DELIMITER = '../';
|
|
|
20
20
|
FilePathConstants.CURRENT_DELIMITER = './';
|
|
21
21
|
FilePathConstants.OH_MODULE_PATH = 'oh_modules';
|
|
22
22
|
FilePathConstants.OH_PACKAGE_FILE_NAME = 'oh-package.json5';
|
|
23
|
+
FilePathConstants.OH_PACKAGE_LOCK_FILE_NAME = 'oh-package-lock.json5';
|
|
23
24
|
FilePathConstants.LINE_BREAK = '\n';
|
|
24
25
|
FilePathConstants.BUILD_PROFILE = 'build-profile.json5';
|
|
25
26
|
FilePathConstants.SDK_HOME = 'default/openharmony/ets/oh-uni-package.json';
|
|
@@ -2,5 +2,6 @@ export default class TemplateConstants {
|
|
|
2
2
|
static readonly CUSTOM_BUILDER_TEMPLATE = "template/customBuilder.ejs";
|
|
3
3
|
static readonly VIEW_BUILDER_TEMPLATE = "template/viewBuilder.ejs";
|
|
4
4
|
static readonly V1_TEMPLATE = "template/viewBuilder_v1.ejs";
|
|
5
|
+
static readonly V1_1_TEMPLATE = "template/viewBuilder_v1_1.ejs";
|
|
5
6
|
static readonly WARP_BUILDER = "WrapBuilder";
|
|
6
7
|
}
|
|
@@ -6,4 +6,5 @@ exports.default = TemplateConstants;
|
|
|
6
6
|
TemplateConstants.CUSTOM_BUILDER_TEMPLATE = 'template/customBuilder.ejs';
|
|
7
7
|
TemplateConstants.VIEW_BUILDER_TEMPLATE = 'template/viewBuilder.ejs';
|
|
8
8
|
TemplateConstants.V1_TEMPLATE = 'template/viewBuilder_v1.ejs';
|
|
9
|
+
TemplateConstants.V1_1_TEMPLATE = 'template/viewBuilder_v1_1.ejs';
|
|
9
10
|
TemplateConstants.WARP_BUILDER = 'WrapBuilder';
|
|
@@ -3,4 +3,6 @@ export default class VersionConstants {
|
|
|
3
3
|
static readonly HMROUTER_LIB_NAME = "hmrouter";
|
|
4
4
|
static readonly HMROUTER_VERSION_KEY = "version";
|
|
5
5
|
static readonly HMROUTER_VERSION_V1 = "1.0.0";
|
|
6
|
+
static readonly HMROUTER_MIN_VERSION_FOR_NAV_HELPER = "1.1.0";
|
|
7
|
+
static readonly HMROUTER_MIN_VERSION_FOR_SDK_API = "1.2.0";
|
|
6
8
|
}
|
|
@@ -7,3 +7,5 @@ VersionConstants.HMROUTER_ORGANIZATION = '@hadss';
|
|
|
7
7
|
VersionConstants.HMROUTER_LIB_NAME = 'hmrouter';
|
|
8
8
|
VersionConstants.HMROUTER_VERSION_KEY = 'version';
|
|
9
9
|
VersionConstants.HMROUTER_VERSION_V1 = '1.0.0';
|
|
10
|
+
VersionConstants.HMROUTER_MIN_VERSION_FOR_NAV_HELPER = '1.1.0';
|
|
11
|
+
VersionConstants.HMROUTER_MIN_VERSION_FOR_SDK_API = '1.2.0';
|
|
@@ -11,8 +11,12 @@ export declare class CodeGenerationProcessor {
|
|
|
11
11
|
private matchedPath;
|
|
12
12
|
private prepareTemplateModel;
|
|
13
13
|
private determineTemplatePath;
|
|
14
|
+
private determineTemplateType;
|
|
14
15
|
private generateFile;
|
|
15
16
|
private detectLibraryVersion;
|
|
16
17
|
private detectLibraryVersion2;
|
|
18
|
+
private extractHMRouterVersion;
|
|
17
19
|
private getLibraryPossiblePaths;
|
|
20
|
+
private parseVersion;
|
|
21
|
+
private compareVersions;
|
|
18
22
|
}
|
|
@@ -125,14 +125,43 @@ class CodeGenerationProcessor {
|
|
|
125
125
|
determineTemplatePath(analyzeResult, defaultTemplatePath) {
|
|
126
126
|
const libraryVersion = this.detectLibraryVersion();
|
|
127
127
|
framework_1.Logger.debug(this.context.node.getNodeName(), `Library version: ${libraryVersion}`);
|
|
128
|
-
|
|
129
|
-
if (useV1Template) {
|
|
130
|
-
return framework_1.PluginFileUtil.pathResolve(__dirname, constants_1.FilePathConstants.PARENT_DELIMITER.repeat(3) + constants_1.TemplateConstants.V1_TEMPLATE);
|
|
131
|
-
}
|
|
132
|
-
else if (analyzeResult.useNavDst === true) {
|
|
128
|
+
if (analyzeResult.useNavDst === true) {
|
|
133
129
|
return framework_1.PluginFileUtil.pathResolve(__dirname, constants_1.FilePathConstants.PARENT_DELIMITER.repeat(3), constants_1.TemplateConstants.CUSTOM_BUILDER_TEMPLATE);
|
|
134
130
|
}
|
|
135
|
-
|
|
131
|
+
const templateType = this.determineTemplateType(libraryVersion);
|
|
132
|
+
if (templateType !== 'latest' && libraryVersion) {
|
|
133
|
+
framework_1.Logger.warn(this.context.node.getNodeName(), `[HMRouter Version Compatibility] Detected library version ${libraryVersion}, ` +
|
|
134
|
+
`which is below the minimum recommended version ${constants_1.VersionConstants.HMROUTER_MIN_VERSION_FOR_SDK_API}. ` +
|
|
135
|
+
`Automatically switched to compatible template (${templateType}). ` +
|
|
136
|
+
`Please upgrade @hadss/hmrouter to ${constants_1.VersionConstants.HMROUTER_MIN_VERSION_FOR_SDK_API} or higher for full feature support.`);
|
|
137
|
+
}
|
|
138
|
+
switch (templateType) {
|
|
139
|
+
case 'v1':
|
|
140
|
+
return framework_1.PluginFileUtil.pathResolve(__dirname, constants_1.FilePathConstants.PARENT_DELIMITER.repeat(3) + constants_1.TemplateConstants.V1_TEMPLATE);
|
|
141
|
+
case 'v1_1':
|
|
142
|
+
return framework_1.PluginFileUtil.pathResolve(__dirname, constants_1.FilePathConstants.PARENT_DELIMITER.repeat(3) + constants_1.TemplateConstants.V1_1_TEMPLATE);
|
|
143
|
+
case 'latest':
|
|
144
|
+
default:
|
|
145
|
+
return defaultTemplatePath;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
determineTemplateType(libraryVersion) {
|
|
149
|
+
if (!libraryVersion) {
|
|
150
|
+
return 'v1';
|
|
151
|
+
}
|
|
152
|
+
const currentVersion = this.parseVersion(libraryVersion);
|
|
153
|
+
const v1_1Version = this.parseVersion(constants_1.VersionConstants.HMROUTER_MIN_VERSION_FOR_NAV_HELPER);
|
|
154
|
+
const v1_2Version = this.parseVersion(constants_1.VersionConstants.HMROUTER_MIN_VERSION_FOR_SDK_API);
|
|
155
|
+
if (!currentVersion || !v1_1Version || !v1_2Version) {
|
|
156
|
+
return 'v1';
|
|
157
|
+
}
|
|
158
|
+
if (this.compareVersions(currentVersion, v1_2Version) >= 0) {
|
|
159
|
+
return 'latest';
|
|
160
|
+
}
|
|
161
|
+
if (this.compareVersions(currentVersion, v1_1Version) >= 0) {
|
|
162
|
+
return 'v1_1';
|
|
163
|
+
}
|
|
164
|
+
return 'v1';
|
|
136
165
|
}
|
|
137
166
|
generateFile(templateModel, templatePath) {
|
|
138
167
|
if (!framework_1.PluginFileUtil.exist(templatePath)) {
|
|
@@ -158,26 +187,78 @@ class CodeGenerationProcessor {
|
|
|
158
187
|
}
|
|
159
188
|
return libraryVersion;
|
|
160
189
|
}
|
|
161
|
-
detectLibraryVersion2(
|
|
162
|
-
let libraryVersion = '';
|
|
190
|
+
detectLibraryVersion2(lockFilePath) {
|
|
163
191
|
try {
|
|
164
|
-
if (framework_1.PluginFileUtil.exist(
|
|
165
|
-
|
|
166
|
-
libraryVersion = packageJson[constants_1.VersionConstants.HMROUTER_VERSION_KEY] || '';
|
|
192
|
+
if (!framework_1.PluginFileUtil.exist(lockFilePath)) {
|
|
193
|
+
return '';
|
|
167
194
|
}
|
|
195
|
+
const lockFileData = framework_1.PluginFileUtil.readJson5(lockFilePath);
|
|
196
|
+
return this.extractHMRouterVersion(lockFileData.packages);
|
|
168
197
|
}
|
|
169
198
|
catch (error) {
|
|
199
|
+
return '';
|
|
170
200
|
}
|
|
171
|
-
|
|
201
|
+
}
|
|
202
|
+
extractHMRouterVersion(packages) {
|
|
203
|
+
if (!packages) {
|
|
204
|
+
return '';
|
|
205
|
+
}
|
|
206
|
+
const hmrouterPrefix = `${constants_1.VersionConstants.HMROUTER_ORGANIZATION}/${constants_1.VersionConstants.HMROUTER_LIB_NAME}@`;
|
|
207
|
+
for (const key of Object.keys(packages)) {
|
|
208
|
+
if (!key.startsWith(hmrouterPrefix)) {
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
const packageInfo = packages[key];
|
|
212
|
+
if (packageInfo && packageInfo[constants_1.VersionConstants.HMROUTER_VERSION_KEY]) {
|
|
213
|
+
return packageInfo[constants_1.VersionConstants.HMROUTER_VERSION_KEY];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return '';
|
|
172
217
|
}
|
|
173
218
|
getLibraryPossiblePaths() {
|
|
174
219
|
const paths = [];
|
|
175
|
-
paths.push(framework_1.PluginFileUtil.pathResolve(this.context.config.modulePath, constants_1.FilePathConstants.
|
|
220
|
+
paths.push(framework_1.PluginFileUtil.pathResolve(this.context.config.modulePath, constants_1.FilePathConstants.OH_PACKAGE_LOCK_FILE_NAME));
|
|
176
221
|
const projectRoot = framework_1.PluginStore.getInstance().get('projectFilePath');
|
|
177
222
|
if (projectRoot && projectRoot !== this.context.config.modulePath) {
|
|
178
|
-
paths.push(framework_1.PluginFileUtil.pathResolve(projectRoot, constants_1.FilePathConstants.
|
|
223
|
+
paths.push(framework_1.PluginFileUtil.pathResolve(projectRoot, constants_1.FilePathConstants.OH_PACKAGE_LOCK_FILE_NAME));
|
|
179
224
|
}
|
|
180
225
|
return paths;
|
|
181
226
|
}
|
|
227
|
+
parseVersion(version) {
|
|
228
|
+
const match = version.match(/^(\d+)\.(\d+)\.(\d+)(-.*)?/);
|
|
229
|
+
if (!match) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
major: parseInt(match[1], 10),
|
|
234
|
+
minor: parseInt(match[2], 10),
|
|
235
|
+
patch: parseInt(match[3], 10),
|
|
236
|
+
preRelease: match[4] || '',
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
compareVersions(v1, v2) {
|
|
240
|
+
if (v1.major !== v2.major) {
|
|
241
|
+
return v1.major < v2.major ? -1 : 1;
|
|
242
|
+
}
|
|
243
|
+
if (v1.minor !== v2.minor) {
|
|
244
|
+
return v1.minor < v2.minor ? -1 : 1;
|
|
245
|
+
}
|
|
246
|
+
if (v1.patch !== v2.patch) {
|
|
247
|
+
return v1.patch < v2.patch ? -1 : 1;
|
|
248
|
+
}
|
|
249
|
+
if (v1.preRelease && !v2.preRelease) {
|
|
250
|
+
return -1;
|
|
251
|
+
}
|
|
252
|
+
if (!v1.preRelease && v2.preRelease) {
|
|
253
|
+
return 1;
|
|
254
|
+
}
|
|
255
|
+
if (v1.preRelease < v2.preRelease) {
|
|
256
|
+
return -1;
|
|
257
|
+
}
|
|
258
|
+
if (v1.preRelease > v2.preRelease) {
|
|
259
|
+
return 1;
|
|
260
|
+
}
|
|
261
|
+
return 0;
|
|
262
|
+
}
|
|
182
263
|
}
|
|
183
264
|
exports.CodeGenerationProcessor = CodeGenerationProcessor;
|
|
@@ -5,13 +5,21 @@ const framework_1 = require("../../framework");
|
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
class ConfigUpdateProcessor {
|
|
7
7
|
constructor(context) {
|
|
8
|
+
this.context = context;
|
|
8
9
|
this.moduleContext = context.moduleContext;
|
|
9
10
|
this.routerMap = context.routerMap;
|
|
10
11
|
this.nodeName = context.node.getNodeName();
|
|
11
12
|
}
|
|
12
13
|
execute() {
|
|
13
14
|
framework_1.Logger.debug(this.nodeName, `Start to update module.json and build profile...`);
|
|
14
|
-
this.
|
|
15
|
+
const isHar = (0, framework_1.isHarModule)(this.context.node);
|
|
16
|
+
if (this.context.moduleIgnored && isHar) {
|
|
17
|
+
framework_1.Logger.info(this.nodeName, `skip update module.json and build profile...`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (this.routerMap.length > 0 || !isHar) {
|
|
21
|
+
this.updateModuleJson();
|
|
22
|
+
}
|
|
15
23
|
this.updateBuildProfile();
|
|
16
24
|
}
|
|
17
25
|
updateModuleJson() {
|
|
@@ -13,6 +13,10 @@ class InitializerProcessor {
|
|
|
13
13
|
this.context.config = this.initConfig(this.context.node);
|
|
14
14
|
this.context.routerMap = [];
|
|
15
15
|
framework_1.Logger.debug(this.context.node.getNodeName(), `read config finished, config: ${this.context.config}`);
|
|
16
|
+
if (this.context.moduleIgnored) {
|
|
17
|
+
framework_1.Logger.debug(this.context.node.getNodeName(), `module ignored: initialize`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
16
20
|
this.scanFiles();
|
|
17
21
|
framework_1.Logger.debug(this.context.node.getNodeName(), `Scanned ${this.context.scanFiles.length} files ${this.context.scanFiles}`);
|
|
18
22
|
}
|
|
@@ -9,6 +9,10 @@ class ObfuscationProcessor {
|
|
|
9
9
|
}
|
|
10
10
|
execute() {
|
|
11
11
|
framework_1.Logger.debug(this.context.node.getNodeName(), `Start to obfuscation...`);
|
|
12
|
+
if (!this.context.routerMap || this.context.routerMap.length === 0) {
|
|
13
|
+
framework_1.Logger.info(this.context.node.getNodeName(), 'Skip generating obfuscation files');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
12
16
|
const buildProfileOpt = this.context.moduleContext?.getBuildProfileOpt();
|
|
13
17
|
if (!this.isEnableObfuscation(buildProfileOpt)) {
|
|
14
18
|
framework_1.Logger.info(this.context.node.getNodeName(), 'This compilation does not turn on code obfuscation, skip hmrouter_obfuscation_rules.txt file generation');
|
|
@@ -20,7 +24,10 @@ class ObfuscationProcessor {
|
|
|
20
24
|
}
|
|
21
25
|
generateObfuscationRuleFile() {
|
|
22
26
|
const obfuscationFilePath = framework_1.PluginFileUtil.pathResolve(this.context.config.modulePath, constants_1.FilePathConstants.OBFUSCATION_FILE_NAME);
|
|
23
|
-
|
|
27
|
+
let routerMap = [];
|
|
28
|
+
if (framework_1.PluginFileUtil.exist(this.context.config.getRouterMapDir())) {
|
|
29
|
+
routerMap = JSON.parse(framework_1.PluginFileUtil.readFileSync(this.context.config.getRouterMapDir()).toString()).routerMap;
|
|
30
|
+
}
|
|
24
31
|
const obfuscationString = this.buildObfuscatedStrings(routerMap);
|
|
25
32
|
framework_1.PluginFileUtil.ensureFileSync(obfuscationFilePath);
|
|
26
33
|
framework_1.PluginFileUtil.writeFileSync(obfuscationFilePath, obfuscationString);
|
|
@@ -9,6 +9,11 @@ class ResourceProcessProcessor {
|
|
|
9
9
|
}
|
|
10
10
|
execute() {
|
|
11
11
|
framework_1.Logger.debug(this.context.node.getNodeName(), `Start to copy router map to raw file...`);
|
|
12
|
+
const isHar = (0, framework_1.isHarModule)(this.context.node);
|
|
13
|
+
if ((isHar && !this.context.routerMap) || (isHar && this.context.routerMap.length === 0)) {
|
|
14
|
+
framework_1.Logger.info(this.context.node.getNodeName(), 'Skip copy router map');
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
12
17
|
this.copyRouterMapToRawFile();
|
|
13
18
|
this.processHspModuleName();
|
|
14
19
|
}
|
|
@@ -16,7 +21,9 @@ class ResourceProcessProcessor {
|
|
|
16
21
|
let routerMapFilePath = framework_1.PluginFileUtil.pathResolve(this.context.currentTarget?.getBuildTargetOutputPath(), constants_1.FilePathConstants.TEMP_ROUTER_MAP_PATH, this.context.currentTarget?.getTargetName(), constants_1.RouterMapConstants.ROUTER_MAP_NAME);
|
|
17
22
|
let rawFilePath = this.context.config.getRawFilePath();
|
|
18
23
|
framework_1.PluginFileUtil.ensureFileSync(rawFilePath);
|
|
19
|
-
framework_1.PluginFileUtil.
|
|
24
|
+
if (framework_1.PluginFileUtil.exist(routerMapFilePath)) {
|
|
25
|
+
framework_1.PluginFileUtil.copyFileSync(routerMapFilePath, rawFilePath);
|
|
26
|
+
}
|
|
20
27
|
framework_1.Logger.info(this.context.node.getNodeName(), `Copy router map to raw file successfully, filePath: ${rawFilePath}`);
|
|
21
28
|
}
|
|
22
29
|
processHspModuleName() {
|
|
@@ -38,7 +45,7 @@ class ResourceProcessProcessor {
|
|
|
38
45
|
for (const remoteName of remoteHspModuleNames) {
|
|
39
46
|
rawFileRouterMap.hspModulesInfo.push({
|
|
40
47
|
moduleName: remoteName,
|
|
41
|
-
packageName: remoteName
|
|
48
|
+
packageName: remoteName,
|
|
42
49
|
});
|
|
43
50
|
}
|
|
44
51
|
framework_1.PluginFileUtil.writeFileSync(rawFilePath, JSON.stringify(rawFileRouterMap));
|
|
@@ -10,10 +10,15 @@ class RouterMapBuildingProcessor {
|
|
|
10
10
|
}
|
|
11
11
|
execute() {
|
|
12
12
|
framework_1.Logger.debug(this.context.node.getNodeName(), `Start to build router map...`);
|
|
13
|
-
this.readExistingRouterMap();
|
|
14
13
|
for (const result of this.context.getAnalyzeResults()) {
|
|
15
14
|
this.buildRouterMap(result);
|
|
16
15
|
}
|
|
16
|
+
const isHar = (0, framework_1.isHarModule)(this.context.node);
|
|
17
|
+
if ((isHar && !this.context.routerMap) || (isHar && this.context.routerMap.length === 0)) {
|
|
18
|
+
framework_1.Logger.info(this.context.node.getNodeName(), `Skip generating routerMap`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
this.readExistingRouterMap();
|
|
17
22
|
this.generateRouterMapFile();
|
|
18
23
|
}
|
|
19
24
|
buildRouterMap(result) {
|
|
@@ -103,7 +108,7 @@ class RouterMapBuildingProcessor {
|
|
|
103
108
|
readExistingRouterMap() {
|
|
104
109
|
const moduleJsonOpt = this.context.moduleContext.getModuleJsonOpt();
|
|
105
110
|
if (!moduleJsonOpt?.module.routerMap) {
|
|
106
|
-
framework_1.Logger.
|
|
111
|
+
framework_1.Logger.info(this.context.node.getNodeName(), `No routerMap found in the module configuration`);
|
|
107
112
|
return;
|
|
108
113
|
}
|
|
109
114
|
const routerMapFileName = moduleJsonOpt.module.routerMap.split(':')[1];
|
|
@@ -113,7 +118,7 @@ class RouterMapBuildingProcessor {
|
|
|
113
118
|
const systemRouterMap = routerMapObj[constants_1.RouterMapConstants.ROUTER_MAP_KEY];
|
|
114
119
|
if (systemRouterMap && systemRouterMap.length > 0) {
|
|
115
120
|
this.context.routerMap.unshift(...systemRouterMap);
|
|
116
|
-
framework_1.Logger.
|
|
121
|
+
framework_1.Logger.info(this.context.node.getNodeName(), `System routerMap added to the current routerMap`);
|
|
117
122
|
}
|
|
118
123
|
}
|
|
119
124
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadss/hmrouter-plugin",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3-rc.0",
|
|
4
4
|
"description": "HMRouter Compiler Plugin",
|
|
5
5
|
"main": "dist/Index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,8 +8,8 @@
|
|
|
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": "rm -rf ./dist && tsc && npm pack",
|
|
12
|
-
"release": "rm -rf ./dist && npm i && tsc && npm publish --access public"
|
|
11
|
+
"package": "rm -rf ./dist && npm i && npx tsc && npm pack",
|
|
12
|
+
"release": "rm -rf ./dist && npm i && npx tsc && npm publish --access public"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
15
|
"hmrouter",
|
|
@@ -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.onWillShow()})
|
|
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
|
+
}
|