@hadss/hmrouter-plugin 1.2.2 → 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 +7 -1
- 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/package.json +1 -1
- 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,6 +440,10 @@ 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
|
+
|
|
441
447
|
### 1.2.2 (2025.10.24)
|
|
442
448
|
|
|
443
449
|
- [修复系统路由表合并异常的问题](https://gitcode.com/openharmony-sig/ohrouter/issues/215)
|
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -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
|
+
}
|