@hadss/hmrouter-plugin 1.2.3-rc.1 → 1.2.3

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 (46) hide show
  1. package/README.md +83 -2
  2. package/dist/HMRouterPluginManager.d.ts +1 -1
  3. package/dist/HMRouterPluginManager.js +17 -28
  4. package/dist/Index.js +6 -3
  5. package/dist/framework/constants/TaskConstants.d.ts +4 -1
  6. package/dist/framework/constants/TaskConstants.js +4 -1
  7. package/dist/framework/core/PluginExecutionController.d.ts +6 -1
  8. package/dist/framework/core/PluginExecutionController.js +70 -11
  9. package/dist/framework/core/TaskManager.d.ts +16 -0
  10. package/dist/framework/core/TaskManager.js +282 -8
  11. package/dist/framework/extension/context/ExtensionContextImpl.d.ts +3 -2
  12. package/dist/framework/extension/context/Interface.d.ts +1 -0
  13. package/dist/framework/utils/ModuleTypeUtil.d.ts +1 -0
  14. package/dist/framework/utils/ModuleTypeUtil.js +10 -1
  15. package/dist/framework/utils/ObjectUtils.d.ts +1 -1
  16. package/dist/framework/utils/PluginStore.d.ts +1 -1
  17. package/dist/framework/utils/StringUtil.d.ts +1 -0
  18. package/dist/framework/utils/StringUtil.js +13 -0
  19. package/dist/framework/utils/index.d.ts +0 -1
  20. package/dist/framework/utils/index.js +0 -1
  21. package/dist/hmrouter_extension/analyzer/RouterAnalyzer.js +1 -0
  22. package/dist/hmrouter_extension/analyzer/interface/IConstantResolver.d.ts +2 -0
  23. package/dist/hmrouter_extension/analyzer/utils/ConstantResolver.d.ts +11 -0
  24. package/dist/hmrouter_extension/analyzer/utils/ConstantResolver.js +139 -4
  25. package/dist/hmrouter_extension/config/HMRouterPluginConfig.d.ts +14 -8
  26. package/dist/hmrouter_extension/config/HMRouterPluginConfig.js +93 -23
  27. package/dist/hmrouter_extension/constants/FilePathConstants.d.ts +10 -0
  28. package/dist/hmrouter_extension/constants/FilePathConstants.js +10 -0
  29. package/dist/hmrouter_extension/constants/PluginConstants.d.ts +2 -0
  30. package/dist/hmrouter_extension/constants/PluginConstants.js +2 -0
  31. package/dist/hmrouter_extension/model/HMAnnotationModel.d.ts +1 -0
  32. package/dist/hmrouter_extension/model/TemplateModel.d.ts +1 -1
  33. package/dist/hmrouter_extension/processor/CodeGenerationProcessor.d.ts +1 -9
  34. package/dist/hmrouter_extension/processor/CodeGenerationProcessor.js +29 -148
  35. package/dist/hmrouter_extension/processor/CompletionProcessor.js +5 -5
  36. package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.d.ts +1 -0
  37. package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.js +29 -2
  38. package/dist/hmrouter_extension/processor/InitializerProcessor.js +0 -10
  39. package/dist/hmrouter_extension/processor/ObfuscationProcessor.js +10 -4
  40. package/dist/hmrouter_extension/processor/ResourceProcessor.d.ts +1 -0
  41. package/dist/hmrouter_extension/processor/ResourceProcessor.js +31 -19
  42. package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.d.ts +0 -3
  43. package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.js +0 -81
  44. package/package.json +2 -3
  45. package/dist/framework/utils/ArkAnalyzerUtil.d.ts +0 -24
  46. package/dist/framework/utils/ArkAnalyzerUtil.js +0 -208
@@ -1,27 +1,32 @@
1
+ import { HMRouterResult } from '../model';
1
2
  export declare class HMRouterPluginConfig {
2
3
  moduleName: string;
3
4
  modulePath: string;
4
5
  configDir: string;
5
6
  scanDir: string[];
7
+ commonScanFullDir: string;
6
8
  routerMapDir: string;
7
9
  builderDir: string;
8
10
  defaultPageTemplate: string;
9
11
  customPageTemplate: CustomPageTemplateImpl[];
10
12
  saveGeneratedFile: boolean;
11
13
  autoObfuscation: boolean;
14
+ incremental: boolean;
12
15
  constructor(moduleName: string, modulePath: string, configDir: string, param: HMRouterPluginConfigParam);
13
16
  getScanPath(dir: string): string;
14
17
  getRelativeSourcePath(filePath: string): string;
15
- getRelativeBuilderPath(filePath: string): string;
16
- getGeneratedFilePath(generatorViewName: string): string;
17
- getBuilderDir(): string;
18
- getBuilderFilePath(generatorViewName: string): string;
19
- getRouterMapDir(): string;
18
+ getRelativeShortSourcePath(analyzeResult: HMRouterResult): string;
19
+ getRelativeBuilderPath(filePath: string, relativeShortPath: string): string;
20
+ getGeneratedFilePath(relativeShortPath: string): string;
21
+ getBuilderDir(isDetele?: boolean): string;
22
+ getBuilderFilePath(relativeShortPath: string): string;
23
+ getRouterMapDir(isDetele?: boolean): string;
24
+ getDefaultRouterMapDir(): string;
20
25
  getModuleRouterMapFilePath(routerMapFileName: string): string;
21
- getRawFilePath(): string;
26
+ getRawFilePath(isDetele?: boolean): string;
22
27
  getDefaultTplFilePath(): string;
23
- getObfuscationFilePath(): string;
24
- getConsumerRulesFilePath(): string;
28
+ getObfuscationFilePath(isDetele?: boolean): string;
29
+ getConsumerRulesFilePath(isDetele?: boolean): string;
25
30
  }
26
31
  export interface HMRouterPluginConfigParam {
27
32
  scanDir?: string[];
@@ -31,6 +36,7 @@ export interface HMRouterPluginConfigParam {
31
36
  saveGeneratedFile?: boolean;
32
37
  defaultPageTemplate?: string;
33
38
  customPageTemplate?: CustomPageTemplateImpl[];
39
+ incremental?: boolean;
34
40
  }
35
41
  export interface CustomPageTemplateImpl {
36
42
  srcPath: string[];
@@ -7,18 +7,32 @@ exports.HMRouterPluginConfig = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const framework_1 = require("../../framework");
9
9
  const constants_1 = require("../constants");
10
+ const hvigor_1 = require("@ohos/hvigor");
10
11
  class HMRouterPluginConfig {
11
12
  constructor(moduleName, modulePath, configDir, param) {
12
13
  this.moduleName = moduleName;
13
14
  this.modulePath = modulePath;
14
15
  this.configDir = configDir;
15
- this.scanDir = param.scanDir ? [...new Set(param.scanDir)] : [];
16
- this.routerMapDir = param.routerMapDir || '';
17
- this.builderDir = param.builderDir || '';
18
- this.defaultPageTemplate = param.defaultPageTemplate || '';
19
- this.customPageTemplate = param.customPageTemplate || [];
20
- this.saveGeneratedFile = !!param.saveGeneratedFile;
21
- this.autoObfuscation = !!param.autoObfuscation;
16
+ this.scanDir = param.scanDir ? [...new Set(param.scanDir)] : [constants_1.FilePathConstants.DEFAULT_SCAN_DIR];
17
+ const scanFullDir = this.scanDir.map(item => framework_1.PluginFileUtil.pathResolve(modulePath, item));
18
+ this.commonScanFullDir = framework_1.StringUtil.longestCommonPrefixOpt(scanFullDir);
19
+ this.routerMapDir = param.routerMapDir ?? constants_1.FilePathConstants.DEFAULT_ROUTER_MAP_DIR;
20
+ this.builderDir = param.builderDir ?? constants_1.FilePathConstants.DEFAULT_BUILD_DIR;
21
+ this.defaultPageTemplate = param.defaultPageTemplate ?? constants_1.TemplateConstants.VIEW_BUILDER_TEMPLATE;
22
+ this.customPageTemplate = param.customPageTemplate ?? [];
23
+ this.saveGeneratedFile = param.saveGeneratedFile ?? false;
24
+ this.autoObfuscation = param.autoObfuscation ?? false;
25
+ const isSupportIncremental = hvigor_1.hvigor.getHvigorVersion?.() !== undefined;
26
+ if (param.incremental === undefined) {
27
+ this.incremental = isSupportIncremental && param.builderDir === undefined &&
28
+ this.customPageTemplate.length === 0 && this.defaultPageTemplate === constants_1.TemplateConstants.VIEW_BUILDER_TEMPLATE;
29
+ }
30
+ else if (param.incremental === false) {
31
+ this.incremental = false;
32
+ }
33
+ else {
34
+ this.incremental = isSupportIncremental;
35
+ }
22
36
  }
23
37
  getScanPath(dir) {
24
38
  return framework_1.PluginFileUtil.pathResolve(this.modulePath, dir);
@@ -26,26 +40,72 @@ class HMRouterPluginConfig {
26
40
  getRelativeSourcePath(filePath) {
27
41
  return path_1.default.relative(this.modulePath, filePath);
28
42
  }
29
- getRelativeBuilderPath(filePath) {
30
- return path_1.default.relative(this.builderDir, filePath);
43
+ getRelativeShortSourcePath(analyzeResult) {
44
+ if (this.incremental) {
45
+ const relativeShortPath = path_1.default.relative(this.commonScanFullDir, analyzeResult.sourceFilePath);
46
+ const ext = path_1.default.extname(relativeShortPath);
47
+ return relativeShortPath.replace(ext, `${framework_1.StringUtil.stringToHashCode(analyzeResult.name)}${ext}`);
48
+ }
49
+ else {
50
+ return constants_1.PrefixConstants.VIEW_NAME_PREFIX + analyzeResult.name + framework_1.StringUtil.stringToHashCode(analyzeResult.name) + constants_1.FilePathConstants.ETS_SUFFIX;
51
+ }
31
52
  }
32
- getGeneratedFilePath(generatorViewName) {
33
- return framework_1.PluginFileUtil.pathResolve(this.modulePath, this.builderDir, generatorViewName + constants_1.FilePathConstants.ETS_SUFFIX);
53
+ getRelativeBuilderPath(filePath, relativeShortPath) {
54
+ if (this.incremental) {
55
+ const absoluteFilePath = framework_1.PluginFileUtil.pathResolve(this.modulePath, filePath);
56
+ const isolatedEtsPath = this.getGeneratedFilePath(relativeShortPath);
57
+ const relativeBuilderPath = path_1.default.relative(path_1.default.dirname(isolatedEtsPath), absoluteFilePath);
58
+ return relativeBuilderPath;
59
+ }
60
+ else {
61
+ return path_1.default.relative(this.builderDir, filePath);
62
+ }
34
63
  }
35
- getBuilderDir() {
36
- return framework_1.PluginFileUtil.pathResolve(this.modulePath, this.builderDir);
64
+ getGeneratedFilePath(relativeShortPath) {
65
+ if (this.incremental) {
66
+ return framework_1.PluginFileUtil.pathResolve(this.modulePath, constants_1.FilePathConstants.ISOLATED_ETS_DIR, relativeShortPath);
67
+ }
68
+ else {
69
+ return framework_1.PluginFileUtil.pathResolve(this.modulePath, this.builderDir, relativeShortPath);
70
+ }
37
71
  }
38
- getBuilderFilePath(generatorViewName) {
39
- return path_1.default.join(this.builderDir, generatorViewName + constants_1.FilePathConstants.ETS_SUFFIX);
72
+ getBuilderDir(isDetele) {
73
+ if (this.incremental && !isDetele) {
74
+ return framework_1.PluginFileUtil.pathResolve(this.modulePath, constants_1.FilePathConstants.ISOLATED_ETS_DIR);
75
+ }
76
+ else {
77
+ return framework_1.PluginFileUtil.pathResolve(this.modulePath, this.builderDir);
78
+ }
40
79
  }
41
- getRouterMapDir() {
42
- return framework_1.PluginFileUtil.pathResolve(this.modulePath, this.routerMapDir, constants_1.RouterMapConstants.ROUTER_MAP_NAME);
80
+ getBuilderFilePath(relativeShortPath) {
81
+ if (this.incremental) {
82
+ return constants_1.FilePathConstants.ISOLATED_PAGE_SOURCE_PREFIX + constants_1.FilePathConstants.DELIMITER + relativeShortPath;
83
+ }
84
+ else {
85
+ return path_1.default.join(this.builderDir, relativeShortPath);
86
+ }
87
+ }
88
+ getRouterMapDir(isDetele) {
89
+ if (this.incremental && !isDetele) {
90
+ return framework_1.PluginFileUtil.pathResolve(this.modulePath, constants_1.FilePathConstants.ISOLATED_PROFILE_DIR, constants_1.RouterMapConstants.ROUTER_MAP_NAME);
91
+ }
92
+ else {
93
+ return framework_1.PluginFileUtil.pathResolve(this.modulePath, this.routerMapDir, constants_1.RouterMapConstants.ROUTER_MAP_NAME);
94
+ }
95
+ }
96
+ getDefaultRouterMapDir() {
97
+ return framework_1.PluginFileUtil.pathResolve(this.modulePath, this.routerMapDir);
43
98
  }
44
99
  getModuleRouterMapFilePath(routerMapFileName) {
45
100
  return framework_1.PluginFileUtil.pathResolve(this.modulePath, this.routerMapDir, routerMapFileName + constants_1.FilePathConstants.JSON_SUFFIX);
46
101
  }
47
- getRawFilePath() {
48
- return framework_1.PluginFileUtil.pathResolve(this.modulePath, constants_1.FilePathConstants.RAWFILE_DIR);
102
+ getRawFilePath(isDetele) {
103
+ if (this.incremental && !isDetele) {
104
+ return framework_1.PluginFileUtil.pathResolve(this.modulePath, constants_1.FilePathConstants.ISOLATED_RAWFILE_DIR);
105
+ }
106
+ else {
107
+ return framework_1.PluginFileUtil.pathResolve(this.modulePath, constants_1.FilePathConstants.RAWFILE_DIR);
108
+ }
49
109
  }
50
110
  getDefaultTplFilePath() {
51
111
  if (path_1.default.isAbsolute(this.defaultPageTemplate) && framework_1.PluginFileUtil.exist(this.defaultPageTemplate)) {
@@ -53,11 +113,21 @@ class HMRouterPluginConfig {
53
113
  }
54
114
  return framework_1.PluginFileUtil.pathResolve(__dirname, constants_1.FilePathConstants.PARENT_DELIMITER.repeat(3) + constants_1.TemplateConstants.VIEW_BUILDER_TEMPLATE);
55
115
  }
56
- getObfuscationFilePath() {
57
- return framework_1.PluginFileUtil.pathResolve(this.modulePath, constants_1.FilePathConstants.OBFUSCATION_FILE_NAME);
116
+ getObfuscationFilePath(isDetele) {
117
+ if (this.incremental && !isDetele) {
118
+ return framework_1.PluginFileUtil.pathResolve(this.modulePath, constants_1.FilePathConstants.ISOLATED_OBFUSCATION_FILE_NAME);
119
+ }
120
+ else {
121
+ return framework_1.PluginFileUtil.pathResolve(this.modulePath, constants_1.FilePathConstants.OBFUSCATION_FILE_NAME);
122
+ }
58
123
  }
59
- getConsumerRulesFilePath() {
60
- return framework_1.PluginFileUtil.pathResolve(this.modulePath, constants_1.FilePathConstants.CONSUMER_FILE_NAME);
124
+ getConsumerRulesFilePath(isDetele) {
125
+ if (this.incremental && !isDetele) {
126
+ return framework_1.PluginFileUtil.pathResolve(this.modulePath, constants_1.FilePathConstants.ISOLATED_CONSUMER_FILE_NAME);
127
+ }
128
+ else {
129
+ return framework_1.PluginFileUtil.pathResolve(this.modulePath, constants_1.FilePathConstants.CONSUMER_FILE_NAME);
130
+ }
61
131
  }
62
132
  }
63
133
  exports.HMRouterPluginConfig = HMRouterPluginConfig;
@@ -6,6 +6,7 @@ export default class FilePathConstants {
6
6
  static readonly TEMP_ROUTER_MAP_PATH = "../../intermediates/router_map";
7
7
  static readonly RAWFILE_DIR = "src/main/resources/rawfile/hm_router_map.json";
8
8
  static readonly ETS_SUFFIX = ".ets";
9
+ static readonly D_ETS_SUFFIX = ".d.ets";
9
10
  static readonly JSON_SUFFIX = ".json";
10
11
  static readonly CONFIG_FILE_NAME = "hmrouter_config.json";
11
12
  static readonly PARENT_DELIMITER = "../";
@@ -20,4 +21,13 @@ export default class FilePathConstants {
20
21
  static readonly DEFAULT_SCAN_DIR = "src/main/ets";
21
22
  static readonly DEFAULT_ROUTER_MAP_DIR = "src/main/resources/base/profile";
22
23
  static readonly DEFAULT_BUILD_DIR = "src/main/ets/generated";
24
+ static readonly ISOLATED_OBFUSCATION_FILE_NAME = "build/hmrouter/hmrouter-obfuscation-rules.txt";
25
+ static readonly ISOLATED_CONSUMER_FILE_NAME = "build/hmrouter/hmrouter-consumer-rules.txt";
26
+ static readonly ISOLATED_BUILD_DIR = "build/hmrouter";
27
+ static readonly ISOLATED_ETS_DIR = "build/hmrouter/ets";
28
+ static readonly ISOLATED_RESOURCES_DIR = "build/hmrouter/resources";
29
+ static readonly ISOLATED_PROFILE_DIR = "build/hmrouter/resources/base/profile";
30
+ static readonly ISOLATED_RAWFILE_DIR = "build/hmrouter/resources/rawfile/hm_router_map.json";
31
+ static readonly ISOLATED_PAGE_SOURCE_PREFIX = "src/../build/hmrouter/ets";
32
+ static readonly DEFAULT_RESOURCES_DIR = "./src/main/resources";
23
33
  }
@@ -14,6 +14,7 @@ FilePathConstants.DELIMITER = '/';
14
14
  FilePathConstants.TEMP_ROUTER_MAP_PATH = '../../intermediates/router_map';
15
15
  FilePathConstants.RAWFILE_DIR = 'src/main/resources/rawfile/hm_router_map.json';
16
16
  FilePathConstants.ETS_SUFFIX = '.ets';
17
+ FilePathConstants.D_ETS_SUFFIX = '.d.ets';
17
18
  FilePathConstants.JSON_SUFFIX = '.json';
18
19
  FilePathConstants.CONFIG_FILE_NAME = 'hmrouter_config.json';
19
20
  FilePathConstants.PARENT_DELIMITER = '../';
@@ -28,3 +29,12 @@ FilePathConstants.DEFAULT_VALUE = 10;
28
29
  FilePathConstants.DEFAULT_SCAN_DIR = 'src/main/ets';
29
30
  FilePathConstants.DEFAULT_ROUTER_MAP_DIR = 'src/main/resources/base/profile';
30
31
  FilePathConstants.DEFAULT_BUILD_DIR = 'src/main/ets/generated';
32
+ FilePathConstants.ISOLATED_OBFUSCATION_FILE_NAME = 'build/hmrouter/hmrouter-obfuscation-rules.txt';
33
+ FilePathConstants.ISOLATED_CONSUMER_FILE_NAME = 'build/hmrouter/hmrouter-consumer-rules.txt';
34
+ FilePathConstants.ISOLATED_BUILD_DIR = 'build/hmrouter';
35
+ FilePathConstants.ISOLATED_ETS_DIR = 'build/hmrouter/ets';
36
+ FilePathConstants.ISOLATED_RESOURCES_DIR = 'build/hmrouter/resources';
37
+ FilePathConstants.ISOLATED_PROFILE_DIR = 'build/hmrouter/resources/base/profile';
38
+ FilePathConstants.ISOLATED_RAWFILE_DIR = 'build/hmrouter/resources/rawfile/hm_router_map.json';
39
+ FilePathConstants.ISOLATED_PAGE_SOURCE_PREFIX = 'src/../build/hmrouter/ets';
40
+ FilePathConstants.DEFAULT_RESOURCES_DIR = './src/main/resources';
@@ -2,6 +2,8 @@ export default class PluginConstants {
2
2
  static readonly HAP_PLUGIN_ID = "HAP_HMROUTER_PLUGIN";
3
3
  static readonly HSP_PLUGIN_ID = "HSP_HMROUTER_PLUGIN";
4
4
  static readonly HAR_PLUGIN_ID = "HAR_HMROUTER_PLUGIN";
5
+ static readonly PLUGIN_ID = "HMROUTER_PLUGIN";
6
+ static readonly APP_PLUGIN_ID = "APP_HMROUTER_PLUGIN";
5
7
  static readonly HAR_MODULE_NAME = "har";
6
8
  static readonly STRUCT_KEYWORD = "struct";
7
9
  }
@@ -6,5 +6,7 @@ exports.default = PluginConstants;
6
6
  PluginConstants.HAP_PLUGIN_ID = 'HAP_HMROUTER_PLUGIN';
7
7
  PluginConstants.HSP_PLUGIN_ID = 'HSP_HMROUTER_PLUGIN';
8
8
  PluginConstants.HAR_PLUGIN_ID = 'HAR_HMROUTER_PLUGIN';
9
+ PluginConstants.PLUGIN_ID = 'HMROUTER_PLUGIN';
10
+ PluginConstants.APP_PLUGIN_ID = 'APP_HMROUTER_PLUGIN';
9
11
  PluginConstants.HAR_MODULE_NAME = 'har';
10
12
  PluginConstants.STRUCT_KEYWORD = 'struct';
@@ -7,6 +7,7 @@ export interface HMRouterResult extends BaseAnalyzeResult {
7
7
  animator?: string;
8
8
  lifecycle?: string;
9
9
  useNavDst?: boolean;
10
+ templatePath?: string;
10
11
  }
11
12
  export interface HMAnimatorResult extends BaseAnalyzeResult {
12
13
  animatorName: string;
@@ -4,6 +4,6 @@ export interface TemplateModel {
4
4
  importPath: string;
5
5
  componentName: string;
6
6
  dialog: boolean;
7
- generatorViewName: string;
7
+ relativeShortPath: string;
8
8
  isDefaultExport?: boolean;
9
9
  }
@@ -8,15 +8,7 @@ export declare class CodeGenerationProcessor {
8
8
  getCompileSdkVersion(): number;
9
9
  getSdkVersion(json5FilePath: string, index: number): number;
10
10
  private generatePageFile;
11
- private matchedPath;
11
+ private deleteOtherFile;
12
12
  private prepareTemplateModel;
13
- private determineTemplatePath;
14
- private determineTemplateType;
15
13
  private generateFile;
16
- private detectLibraryVersion;
17
- private detectLibraryVersion2;
18
- private extractHMRouterVersion;
19
- private getLibraryPossiblePaths;
20
- private parseVersion;
21
- private compareVersions;
22
14
  }
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.CodeGenerationProcessor = void 0;
7
- const micromatch_1 = __importDefault(require("micromatch"));
8
7
  const ejs_1 = __importDefault(require("ejs"));
9
8
  const framework_1 = require("../../framework");
10
9
  const PluginError_1 = require("../error/PluginError");
@@ -17,7 +16,7 @@ class CodeGenerationProcessor {
17
16
  execute() {
18
17
  this.sdkVersion = this.getCompileSdkVersion();
19
18
  framework_1.Logger.debug(this.context.node.getNodeName(), `Start to code generation...`);
20
- this.context.generatedPaths = new Map();
19
+ const generatedFilePaths = [];
21
20
  this.context.getAnalyzeResults().forEach((result) => {
22
21
  if (result.annotation === constants_1.AnnotationConstants.ROUTER_ANNOTATION) {
23
22
  if (!result.sourceFilePath) {
@@ -26,9 +25,11 @@ class CodeGenerationProcessor {
26
25
  let pageSourceFile = this.context.config
27
26
  .getRelativeSourcePath(result.sourceFilePath)
28
27
  .replaceAll(constants_1.FilePathConstants.FILE_SEPARATOR, constants_1.FilePathConstants.DELIMITER);
29
- this.generatePageFile(result, pageSourceFile, this.matchedPath(pageSourceFile, this.context.config.customPageTemplate, this.context.config.getDefaultTplFilePath()));
28
+ const generatePageFilePath = this.generatePageFile(result, pageSourceFile);
29
+ generatedFilePaths.push(generatePageFilePath);
30
30
  }
31
31
  });
32
+ this.deleteOtherFile(generatedFilePaths);
32
33
  }
33
34
  extractVersion(compatibleSdkVersion) {
34
35
  if (typeof compatibleSdkVersion === 'number') {
@@ -87,29 +88,36 @@ class CodeGenerationProcessor {
87
88
  }
88
89
  return constants_1.FilePathConstants.DEFAULT_VALUE;
89
90
  }
90
- generatePageFile(result, pageSourceFile, tempFilePath) {
91
+ generatePageFile(result, pageSourceFile) {
91
92
  const templateModel = this.prepareTemplateModel(result, pageSourceFile);
92
- tempFilePath = this.determineTemplatePath(result, tempFilePath);
93
- const generatedFilePath = this.generateFile(templateModel, tempFilePath);
94
- framework_1.Logger.info(this.context.node.getNodeName(), `Builder ${templateModel.generatorViewName}.ets has been generated in ${generatedFilePath}`);
95
- const uniqueKey = `${result.name}#${result.pageUrl}`;
96
- this.context.generatedPaths.set(uniqueKey, generatedFilePath);
97
- }
98
- matchedPath(filePath, customPageTemplate, defaultTplFilePath) {
99
- for (const template of customPageTemplate) {
100
- if (micromatch_1.default.isMatch(filePath, template.srcPath)) {
101
- framework_1.Logger.debug(this.context.node.getNodeName(), `${filePath} detected matching template: ${template.templatePath}`);
102
- return framework_1.PluginFileUtil.pathResolve(this.context.config.configDir, template.templatePath);
93
+ const generatedFilePath = this.generateFile(templateModel, result.templatePath ?? '');
94
+ framework_1.Logger.info(this.context.node.getNodeName(), `Builder ${result.sourceFilePath}.ets has been generated in ${generatedFilePath}`);
95
+ return generatedFilePath;
96
+ }
97
+ deleteOtherFile(generatedFilePaths) {
98
+ framework_1.Logger.debug(this.context.node.getNodeName(), `Start to delete other file...`);
99
+ const buildDir = this.context.config.getBuilderDir();
100
+ if (!framework_1.PluginFileUtil.exist(buildDir)) {
101
+ framework_1.Logger.debug(this.context.node.getNodeName(), `${buildDir} does not exist`);
102
+ return;
103
+ }
104
+ const files = framework_1.PluginFileUtil.readdirSync(buildDir, { recursive: true, encoding: null });
105
+ framework_1.Logger.debug(this.context.node.getNodeName(), `Files in ${buildDir}: ${files}`);
106
+ for (const file of files) {
107
+ const absoluteFilePath = framework_1.PluginFileUtil.join(buildDir, file);
108
+ framework_1.Logger.debug(this.context.node.getNodeName(), `Delete other file: ${absoluteFilePath}`);
109
+ const isExist = generatedFilePaths.findIndex((path) => path.indexOf(absoluteFilePath) >= 0);
110
+ if (isExist < 0) {
111
+ framework_1.PluginFileUtil.rmSync(absoluteFilePath);
103
112
  }
104
113
  }
105
- return defaultTplFilePath;
106
114
  }
107
115
  prepareTemplateModel(analyzeResult, pageSourceFile) {
116
+ const relativeShortPath = this.context.config.getRelativeShortSourcePath(analyzeResult);
108
117
  let importPath = this.context.config
109
- .getRelativeBuilderPath(pageSourceFile)
118
+ .getRelativeBuilderPath(pageSourceFile, relativeShortPath)
110
119
  .replaceAll(constants_1.FilePathConstants.FILE_SEPARATOR, constants_1.FilePathConstants.DELIMITER)
111
120
  .replaceAll(constants_1.FilePathConstants.ETS_SUFFIX, '');
112
- let generatorViewName = constants_1.PrefixConstants.VIEW_NAME_PREFIX + analyzeResult.name + framework_1.StringUtil.stringToHashCode(analyzeResult.pageUrl);
113
121
  let templateData = this.context.getTemplateData(analyzeResult.name);
114
122
  return {
115
123
  sdkVersion: this.sdkVersion,
@@ -118,147 +126,20 @@ class CodeGenerationProcessor {
118
126
  dialog: !!analyzeResult.dialog,
119
127
  isDefaultExport: !!templateData?.isDefaultExport,
120
128
  importPath,
121
- generatorViewName,
129
+ relativeShortPath,
122
130
  ...templateData,
123
131
  };
124
132
  }
125
- determineTemplatePath(analyzeResult, defaultTemplatePath) {
126
- const libraryVersion = this.detectLibraryVersion();
127
- framework_1.Logger.debug(this.context.node.getNodeName(), `Library version: ${libraryVersion}`);
128
- if (analyzeResult.useNavDst === true) {
129
- return framework_1.PluginFileUtil.pathResolve(__dirname, constants_1.FilePathConstants.PARENT_DELIMITER.repeat(3), constants_1.TemplateConstants.CUSTOM_BUILDER_TEMPLATE);
130
- }
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';
165
- }
166
133
  generateFile(templateModel, templatePath) {
167
134
  if (!framework_1.PluginFileUtil.exist(templatePath)) {
168
135
  throw PluginError_1.PluginError.create(PluginError_1.ErrorCode.TEMPLATE_NOT_FOUND, this.context.config.moduleName, templatePath);
169
136
  }
170
137
  const tpl = framework_1.PluginFileUtil.readFileSync(templatePath).toString();
171
138
  const templateStr = ejs_1.default.render(tpl, templateModel);
172
- const generatorFilePath = this.context.config.getGeneratedFilePath(templateModel.generatorViewName);
139
+ const generatorFilePath = this.context.config.getGeneratedFilePath(templateModel.relativeShortPath);
173
140
  framework_1.PluginFileUtil.ensureFileSync(generatorFilePath);
174
141
  framework_1.PluginFileUtil.writeFileSync(generatorFilePath, templateStr);
175
- return this.context.config
176
- .getBuilderFilePath(templateModel.generatorViewName)
177
- .replaceAll(constants_1.FilePathConstants.FILE_SEPARATOR, constants_1.FilePathConstants.DELIMITER);
178
- }
179
- detectLibraryVersion() {
180
- let libraryVersion = '';
181
- const possiblePaths = this.getLibraryPossiblePaths();
182
- for (const packagePath of possiblePaths) {
183
- libraryVersion = this.detectLibraryVersion2(packagePath);
184
- if (libraryVersion) {
185
- break;
186
- }
187
- }
188
- return libraryVersion;
189
- }
190
- detectLibraryVersion2(lockFilePath) {
191
- try {
192
- if (!framework_1.PluginFileUtil.exist(lockFilePath)) {
193
- return '';
194
- }
195
- const lockFileData = framework_1.PluginFileUtil.readJson5(lockFilePath);
196
- return this.extractHMRouterVersion(lockFileData.packages);
197
- }
198
- catch (error) {
199
- return '';
200
- }
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 '';
217
- }
218
- getLibraryPossiblePaths() {
219
- const paths = [];
220
- paths.push(framework_1.PluginFileUtil.pathResolve(this.context.config.modulePath, constants_1.FilePathConstants.OH_PACKAGE_LOCK_FILE_NAME));
221
- const projectRoot = framework_1.PluginStore.getInstance().get('projectFilePath');
222
- if (projectRoot && projectRoot !== this.context.config.modulePath) {
223
- paths.push(framework_1.PluginFileUtil.pathResolve(projectRoot, constants_1.FilePathConstants.OH_PACKAGE_LOCK_FILE_NAME));
224
- }
225
- return paths;
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;
142
+ return generatorFilePath;
262
143
  }
263
144
  }
264
145
  exports.CodeGenerationProcessor = CodeGenerationProcessor;
@@ -21,21 +21,21 @@ class CompletionProcessor {
21
21
  }
22
22
  }
23
23
  deleteRouterMapFile() {
24
- let routerMapDirPath = this.config.getRouterMapDir();
24
+ let routerMapDirPath = this.config.getRouterMapDir(true);
25
25
  if (framework_1.PluginFileUtil.exist(routerMapDirPath)) {
26
26
  framework_1.PluginFileUtil.unlinkSync(routerMapDirPath);
27
27
  framework_1.Logger.info(this.context.node.getNodeName(), `Delete router map file successfully, filePath: ${routerMapDirPath}`);
28
28
  }
29
29
  }
30
30
  deleteRawFile() {
31
- let rawFilePath = this.config.getRawFilePath();
31
+ let rawFilePath = this.config.getRawFilePath(true);
32
32
  if (framework_1.PluginFileUtil.exist(rawFilePath)) {
33
33
  framework_1.PluginFileUtil.unlinkSync(rawFilePath);
34
34
  framework_1.Logger.info(this.context.node.getNodeName(), `Delete raw file successfully, filePath: ${rawFilePath}`);
35
35
  }
36
36
  }
37
37
  deleteGeneratorFile() {
38
- let builderDirPath = this.config.getBuilderDir();
38
+ let builderDirPath = this.config.getBuilderDir(true);
39
39
  if (framework_1.PluginFileUtil.exist(builderDirPath)) {
40
40
  framework_1.PluginFileUtil.rmSync(builderDirPath, {
41
41
  recursive: true,
@@ -44,12 +44,12 @@ class CompletionProcessor {
44
44
  }
45
45
  }
46
46
  deleteObfuscationFile() {
47
- let obfuscationFilePath = this.config.getObfuscationFilePath();
47
+ let obfuscationFilePath = this.config.getObfuscationFilePath(true);
48
48
  if (framework_1.PluginFileUtil.exist(obfuscationFilePath)) {
49
49
  framework_1.PluginFileUtil.unlinkSync(obfuscationFilePath);
50
50
  framework_1.Logger.info(this.context.node.getNodeName(), `Delete obfuscation file successfully, filePath: ${obfuscationFilePath}`);
51
51
  }
52
- let consumerRulesPath = this.config.getConsumerRulesFilePath();
52
+ let consumerRulesPath = this.config.getConsumerRulesFilePath(true);
53
53
  if (framework_1.PluginFileUtil.exist(consumerRulesPath)) {
54
54
  framework_1.PluginFileUtil.unlinkSync(consumerRulesPath);
55
55
  framework_1.Logger.info(this.context.node.getNodeName(), `Delete consumer rules file successfully, filePath: ${consumerRulesPath}`);
@@ -9,4 +9,5 @@ export declare class ConfigUpdateProcessor {
9
9
  private updateModuleJson;
10
10
  private updateBuildProfile;
11
11
  private pushRouterInfo;
12
+ private updateDirectories;
12
13
  }
@@ -40,11 +40,14 @@ class ConfigUpdateProcessor {
40
40
  buildProfileOpt.buildOption.arkOptions.runtimeOnly.sources = [];
41
41
  }
42
42
  this.pushRouterInfo(buildProfileOpt, this.routerMap);
43
+ if (this.context.config.incremental) {
44
+ this.updateDirectories(buildProfileOpt);
45
+ }
43
46
  this.moduleContext.setBuildProfileOpt(buildProfileOpt);
44
- framework_1.Logger.info(this.nodeName, `Update build profile successfully, current sources: ${this.moduleContext.getBuildProfileOpt()?.buildOption?.arkOptions?.runtimeOnly?.sources}`);
47
+ framework_1.Logger.debug(this.nodeName, `Update build profile successfully, current sources: ${this.moduleContext.getBuildProfileOpt()?.buildOption?.arkOptions?.runtimeOnly?.sources}`);
45
48
  }
46
49
  pushRouterInfo(buildProfileOpt, routerMap) {
47
- let sources = buildProfileOpt.buildOption.arkOptions.runtimeOnly.sources;
50
+ let sources = buildProfileOpt.buildOption.arkOptions.runtimeOnly.sources ?? [];
48
51
  routerMap.forEach((item) => {
49
52
  const name = item.name;
50
53
  if (name.includes(constants_1.PrefixConstants.LIFECYCLE_PREFIX) ||
@@ -57,5 +60,29 @@ class ConfigUpdateProcessor {
57
60
  });
58
61
  sources = [...new Set(sources)];
59
62
  }
63
+ updateDirectories(buildProfileOpt) {
64
+ const targets = buildProfileOpt.targets;
65
+ if (!targets || !Array.isArray(targets)) {
66
+ framework_1.Logger.warn(this.nodeName, `No targets found in build-profile.json5, skip updating directories`);
67
+ return;
68
+ }
69
+ const isolatedResourcesDir = constants_1.FilePathConstants.CURRENT_DELIMITER + constants_1.FilePathConstants.ISOLATED_RESOURCES_DIR;
70
+ if (!framework_1.PluginFileUtil.exist(framework_1.PluginFileUtil.pathResolve(this.context.moduleContext.getModulePath(), isolatedResourcesDir))) {
71
+ framework_1.Logger.warn(this.nodeName, `${isolatedResourcesDir} is not exist, skip updating directories`);
72
+ return;
73
+ }
74
+ targets.forEach((target) => {
75
+ if (!target.resource) {
76
+ target.resource = {};
77
+ }
78
+ if (!target.resource.directories) {
79
+ target.resource.directories = [constants_1.FilePathConstants.DEFAULT_RESOURCES_DIR];
80
+ }
81
+ if (!target.resource.directories.includes(isolatedResourcesDir)) {
82
+ target.resource.directories.unshift(isolatedResourcesDir);
83
+ }
84
+ framework_1.Logger.debug(this.nodeName, `Update target '${target.name}' directories: ${JSON.stringify(target.resource.directories)}`);
85
+ });
86
+ }
60
87
  }
61
88
  exports.ConfigUpdateProcessor = ConfigUpdateProcessor;
@@ -79,17 +79,7 @@ class InitializerProcessor {
79
79
  return configParam;
80
80
  }
81
81
  mergeConfigs(projectConfigParam, moduleConfigParam) {
82
- const defaultConfig = {
83
- scanDir: [constants_1.FilePathConstants.DEFAULT_SCAN_DIR],
84
- routerMapDir: constants_1.FilePathConstants.DEFAULT_ROUTER_MAP_DIR,
85
- builderDir: constants_1.FilePathConstants.DEFAULT_BUILD_DIR,
86
- defaultPageTemplate: constants_1.TemplateConstants.VIEW_BUILDER_TEMPLATE,
87
- customPageTemplate: [],
88
- saveGeneratedFile: false,
89
- autoObfuscation: false,
90
- };
91
82
  return {
92
- ...defaultConfig,
93
83
  ...projectConfigParam,
94
84
  ...moduleConfigParam,
95
85
  };