@hadss/hmrouter-plugin 1.2.0 → 1.2.1

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 CHANGED
@@ -21,7 +21,7 @@ HMRouter编译插件是一个基于hvigor的编译插件,用于:
21
21
  ```json5
22
22
  {
23
23
  "dependencies": {
24
- "@hadss/hmrouter-plugin": "^1.2.0" // 使用最新版本
24
+ "@hadss/hmrouter-plugin": "^1.2.1" // 使用最新版本
25
25
  },
26
26
  // ...其余配置
27
27
  }
@@ -438,6 +438,14 @@ hvigor 5.7.3及以上
438
438
 
439
439
  ## 更新日志
440
440
 
441
+ ### 1.2.1 (2025.10.20)
442
+
443
+ - [修复低版本IDE编译错误](https://gitcode.com/openharmony-sig/ohrouter/issues/206)
444
+
445
+ ### 1.2.0 (2025.09.28)
446
+
447
+ - 支持API20新接口的生成
448
+
441
449
  ### 1.2.0-rc.0 (2025.09.02)
442
450
 
443
451
  - [修复多target工程下编译app的问题](https://gitcode.com/openharmony-sig/ohrouter/issues/131)
@@ -13,6 +13,9 @@ export default class FilePathConstants {
13
13
  static readonly OH_MODULE_PATH = "oh_modules";
14
14
  static readonly OH_PACKAGE_FILE_NAME = "oh-package.json5";
15
15
  static readonly LINE_BREAK = "\n";
16
+ static readonly BUILD_PROFILE = "build-profile.json5";
17
+ static readonly SDK_HOME = "default/openharmony/ets/oh-uni-package.json";
18
+ static readonly DEFAULT_VALUE = 10;
16
19
  static readonly DEFAULT_SCAN_DIR = "src/main/ets";
17
20
  static readonly DEFAULT_ROUTER_MAP_DIR = "src/main/resources/base/profile";
18
21
  static readonly DEFAULT_BUILD_DIR = "src/main/ets/generated";
@@ -21,6 +21,9 @@ FilePathConstants.CURRENT_DELIMITER = './';
21
21
  FilePathConstants.OH_MODULE_PATH = 'oh_modules';
22
22
  FilePathConstants.OH_PACKAGE_FILE_NAME = 'oh-package.json5';
23
23
  FilePathConstants.LINE_BREAK = '\n';
24
+ FilePathConstants.BUILD_PROFILE = 'build-profile.json5';
25
+ FilePathConstants.SDK_HOME = 'default/openharmony/ets/oh-uni-package.json';
26
+ FilePathConstants.DEFAULT_VALUE = 10;
24
27
  FilePathConstants.DEFAULT_SCAN_DIR = 'src/main/ets';
25
28
  FilePathConstants.DEFAULT_ROUTER_MAP_DIR = 'src/main/resources/base/profile';
26
29
  FilePathConstants.DEFAULT_BUILD_DIR = 'src/main/ets/generated';
@@ -1,4 +1,5 @@
1
1
  export interface TemplateModel {
2
+ sdkVersion: number;
2
3
  pageUrl: string;
3
4
  importPath: string;
4
5
  componentName: string;
@@ -1,8 +1,12 @@
1
1
  import { HMRouterExtensionContext } from '../HMRouterExtensionContext';
2
2
  export declare class CodeGenerationProcessor {
3
3
  private context;
4
+ private sdkVersion;
4
5
  constructor(context: HMRouterExtensionContext);
5
6
  execute(): void;
7
+ extractVersion(compatibleSdkVersion: string | number): number;
8
+ getCompileSdkVersion(): number;
9
+ getSdkVersion(json5FilePath: string, index: number): number;
6
10
  private generatePageFile;
7
11
  private matchedPath;
8
12
  private prepareTemplateModel;
@@ -11,9 +11,11 @@ const PluginError_1 = require("../error/PluginError");
11
11
  const constants_1 = require("../constants");
12
12
  class CodeGenerationProcessor {
13
13
  constructor(context) {
14
+ this.sdkVersion = 0;
14
15
  this.context = context;
15
16
  }
16
17
  execute() {
18
+ this.sdkVersion = this.getCompileSdkVersion();
17
19
  framework_1.Logger.debug(this.context.node.getNodeName(), `Start to code generation...`);
18
20
  this.context.generatedPaths = new Map();
19
21
  this.context.getAnalyzeResults().forEach((result) => {
@@ -28,6 +30,63 @@ class CodeGenerationProcessor {
28
30
  }
29
31
  });
30
32
  }
33
+ extractVersion(compatibleSdkVersion) {
34
+ if (typeof compatibleSdkVersion === 'number') {
35
+ return compatibleSdkVersion;
36
+ }
37
+ else {
38
+ const match = compatibleSdkVersion.match(/\((\d+)\)/);
39
+ if (match && match[1]) {
40
+ return parseInt(match[1], 10);
41
+ }
42
+ const num = parseFloat(compatibleSdkVersion);
43
+ if (!isNaN(num) && num > constants_1.FilePathConstants.DEFAULT_VALUE) {
44
+ return num;
45
+ }
46
+ return constants_1.FilePathConstants.DEFAULT_VALUE;
47
+ }
48
+ }
49
+ getCompileSdkVersion() {
50
+ let json5FilePath = '';
51
+ let sdkVersion = constants_1.FilePathConstants.DEFAULT_VALUE;
52
+ let arrData = ['DEVECO_SDK_HOME', 'HOS_SDK_HOME', 'OHOS_SDK_HOME'];
53
+ for (let index = 0; index <= 4; index++) {
54
+ if (index < 3 && process.env[arrData[index]]) {
55
+ json5FilePath = framework_1.PluginFileUtil.pathResolve(process.env[arrData[index]], constants_1.FilePathConstants.SDK_HOME);
56
+ }
57
+ else if (index === 3) {
58
+ json5FilePath = framework_1.PluginFileUtil.pathResolve(framework_1.PluginStore.getInstance().get('projectFilePath'), constants_1.FilePathConstants.BUILD_PROFILE);
59
+ }
60
+ else if (index === 4) {
61
+ json5FilePath = framework_1.PluginFileUtil.pathResolve(framework_1.PluginStore.getInstance().get('projectFilePath'), constants_1.FilePathConstants.BUILD_PROFILE);
62
+ }
63
+ const sdkVer = this.getSdkVersion(json5FilePath, index);
64
+ if (sdkVer > constants_1.FilePathConstants.DEFAULT_VALUE) {
65
+ sdkVersion = sdkVer;
66
+ break;
67
+ }
68
+ }
69
+ return sdkVersion;
70
+ }
71
+ getSdkVersion(json5FilePath, index) {
72
+ if (framework_1.PluginFileUtil.exist(json5FilePath)) {
73
+ const data = framework_1.PluginFileUtil.readJson5(json5FilePath);
74
+ if (index < 3) {
75
+ return this.extractVersion(data.apiVersion);
76
+ }
77
+ else if (index === 3) {
78
+ if (data.app.products[0].compileSdkVersion) {
79
+ return this.extractVersion(data.app.products[0].compileSdkVersion);
80
+ }
81
+ }
82
+ else if (index === 4) {
83
+ if (data.app.products[0].compatibleSdkVersion) {
84
+ return this.extractVersion(data.app.products[0].compatibleSdkVersion);
85
+ }
86
+ }
87
+ }
88
+ return constants_1.FilePathConstants.DEFAULT_VALUE;
89
+ }
31
90
  generatePageFile(result, pageSourceFile, tempFilePath) {
32
91
  const templateModel = this.prepareTemplateModel(result, pageSourceFile);
33
92
  tempFilePath = this.determineTemplatePath(result, tempFilePath);
@@ -53,6 +112,7 @@ class CodeGenerationProcessor {
53
112
  let generatorViewName = constants_1.PrefixConstants.VIEW_NAME_PREFIX + analyzeResult.name + framework_1.StringUtil.stringToHashCode(analyzeResult.pageUrl);
54
113
  let templateData = this.context.getTemplateData(analyzeResult.name);
55
114
  return {
115
+ sdkVersion: this.sdkVersion,
56
116
  pageUrl: analyzeResult.pageUrl,
57
117
  componentName: analyzeResult.name,
58
118
  dialog: !!analyzeResult.dialog,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hadss/hmrouter-plugin",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "HMRouter Compiler Plugin",
5
5
  "main": "dist/Index.js",
6
6
  "scripts": {
@@ -8,7 +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
- "release": "rm -rf ./dist && tsc && npm publish --access public"
11
+ "package": "rm -rf ./dist && tsc && npm pack",
12
+ "release": "rm -rf ./dist && npm i && tsc && npm publish --access public"
12
13
  },
13
14
  "keywords": [
14
15
  "hmrouter",
@@ -48,10 +48,10 @@ export struct <%= componentName %>Generated {
48
48
  .onDisAppear(()=>{this.helper.onDisAppear()})
49
49
  .onReady((ctx)=>{this.helper.onReady(ctx)})
50
50
  .onBackPressed(()=> this.helper.onBackPressed())
51
- .onResult((result:ESObject)=>{this.helper.onResult(result)})
52
- .onActive((activeReason:NavDestinationActiveReason)=>{this.helper.onActive(activeReason)})
53
- .onInactive((inactiveReason:NavDestinationActiveReason)=>{this.helper.onInactive(inactiveReason)})
54
- .onNewParam((newParam:ESObject)=>{this.helper.onNewParam(newParam)})
51
+ <% if(sdkVersion>=15){ %>.onResult((result:ESObject)=>{this.helper.onResult(result)})<% } %>
52
+ <% if(sdkVersion>=17){ %>.onActive((activeReason:NavDestinationActiveReason)=>{this.helper.onActive(activeReason)})<% } %>
53
+ <% if(sdkVersion>=17){ %>.onInactive((inactiveReason:NavDestinationActiveReason)=>{this.helper.onInactive(inactiveReason)})<% } %>
54
+ <% if(sdkVersion>=19){ %>.onNewParam((newParam:ESObject)=>{this.helper.onNewParam(newParam)})<% } %>
55
55
  }else if(this.helper.sdkApiVersion>=17){
56
56
  NavDestination() {
57
57
  <%= componentName %>()
@@ -70,9 +70,9 @@ export struct <%= componentName %>Generated {
70
70
  .onDisAppear(()=>{this.helper.onDisAppear()})
71
71
  .onReady((ctx)=>{this.helper.onReady(ctx)})
72
72
  .onBackPressed(()=> this.helper.onBackPressed())
73
- .onResult((result:ESObject)=>{this.helper.onResult(result)})
74
- .onActive((activeReason:NavDestinationActiveReason)=>{this.helper.onActive(activeReason)})
75
- .onInactive((inactiveReason:NavDestinationActiveReason)=>{this.helper.onInactive(inactiveReason)})
73
+ <% if(sdkVersion>=15){ %>.onResult((result:ESObject)=>{this.helper.onResult(result)})<% } %>
74
+ <% if(sdkVersion>=17){ %>.onActive((activeReason:NavDestinationActiveReason)=>{this.helper.onActive(activeReason)})<% } %>
75
+ <% if(sdkVersion>=17){ %>.onInactive((inactiveReason:NavDestinationActiveReason)=>{this.helper.onInactive(inactiveReason)})<% } %>
76
76
  }else if(this.helper.sdkApiVersion>=15){
77
77
  NavDestination() {
78
78
  <%= componentName %>()
@@ -91,7 +91,7 @@ export struct <%= componentName %>Generated {
91
91
  .onDisAppear(()=>{this.helper.onDisAppear()})
92
92
  .onReady((ctx)=>{this.helper.onReady(ctx)})
93
93
  .onBackPressed(()=> this.helper.onBackPressed())
94
- .onResult((result:ESObject)=>{this.helper.onResult(result)})
94
+ <% if(sdkVersion>=15){ %>.onResult((result:ESObject)=>{this.helper.onResult(result)})<% } %>
95
95
  }else{
96
96
  NavDestination() {
97
97
  <%= componentName %>()