@hadss/hmrouter-plugin 1.1.0-beta.0 → 1.2.0-beta.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 (120) hide show
  1. package/README.md +308 -67
  2. package/dist/HMRouterPluginManager.d.ts +11 -0
  3. package/dist/HMRouterPluginManager.js +66 -0
  4. package/dist/Index.d.ts +14 -3
  5. package/dist/Index.js +58 -110
  6. package/dist/framework/constants/TaskConstants.d.ts +8 -0
  7. package/dist/framework/constants/TaskConstants.js +12 -0
  8. package/dist/framework/constants/index.d.ts +1 -0
  9. package/dist/framework/constants/index.js +17 -0
  10. package/dist/framework/core/PluginExecutionController.d.ts +15 -0
  11. package/dist/framework/core/PluginExecutionController.js +62 -0
  12. package/dist/framework/core/TaskManager.d.ts +12 -0
  13. package/dist/framework/core/TaskManager.js +68 -0
  14. package/dist/framework/core/TaskStage.d.ts +10 -0
  15. package/dist/framework/core/TaskStage.js +14 -0
  16. package/dist/framework/core/index.d.ts +3 -0
  17. package/dist/framework/core/index.js +19 -0
  18. package/dist/framework/extension/ExtensionManager.d.ts +11 -0
  19. package/dist/framework/extension/ExtensionManager.js +33 -0
  20. package/dist/framework/extension/PluginExtension.d.ts +13 -0
  21. package/dist/framework/extension/PluginExtension.js +6 -0
  22. package/dist/framework/extension/context/ExtensionContextImpl.d.ts +23 -0
  23. package/dist/framework/extension/context/ExtensionContextImpl.js +64 -0
  24. package/dist/framework/extension/context/Interface.d.ts +21 -0
  25. package/dist/framework/extension/context/Interface.js +2 -0
  26. package/dist/framework/extension/context/TemplateMetadataImpl.d.ts +12 -0
  27. package/dist/framework/extension/context/TemplateMetadataImpl.js +22 -0
  28. package/dist/framework/extension/index.d.ts +4 -0
  29. package/dist/framework/extension/index.js +20 -0
  30. package/dist/framework/index.d.ts +4 -0
  31. package/dist/framework/index.js +20 -0
  32. package/dist/framework/utils/FileUtil.d.ts +13 -0
  33. package/dist/framework/utils/FileUtil.js +20 -0
  34. package/dist/framework/utils/Logger.d.ts +12 -0
  35. package/dist/framework/utils/Logger.js +31 -0
  36. package/dist/framework/utils/ModuleTypeUtil.d.ts +4 -0
  37. package/dist/framework/utils/ModuleTypeUtil.js +16 -0
  38. package/dist/framework/utils/ObjectUtils.d.ts +3 -0
  39. package/dist/framework/utils/ObjectUtils.js +14 -0
  40. package/dist/framework/utils/PluginStore.d.ts +10 -0
  41. package/dist/framework/utils/PluginStore.js +29 -0
  42. package/dist/framework/utils/StringUtil.d.ts +3 -0
  43. package/dist/framework/utils/StringUtil.js +18 -0
  44. package/dist/framework/utils/TsAstUtil.d.ts +6 -0
  45. package/dist/framework/utils/TsAstUtil.js +19 -0
  46. package/dist/framework/utils/index.d.ts +7 -0
  47. package/dist/framework/utils/index.js +23 -0
  48. package/dist/hmrouter_extension/HMRouterExtension.d.ts +15 -0
  49. package/dist/hmrouter_extension/HMRouterExtension.js +102 -0
  50. package/dist/hmrouter_extension/HMRouterExtensionContext.d.ts +8 -0
  51. package/dist/hmrouter_extension/HMRouterExtensionContext.js +2 -0
  52. package/dist/hmrouter_extension/analyzer/AnnotationAnalyzerRegistry.d.ts +14 -0
  53. package/dist/hmrouter_extension/analyzer/AnnotationAnalyzerRegistry.js +45 -0
  54. package/dist/hmrouter_extension/analyzer/ComponentAnalyzer.d.ts +12 -0
  55. package/dist/hmrouter_extension/analyzer/ComponentAnalyzer.js +51 -0
  56. package/dist/hmrouter_extension/analyzer/RouterAnalyzer.d.ts +12 -0
  57. package/dist/hmrouter_extension/analyzer/RouterAnalyzer.js +87 -0
  58. package/dist/hmrouter_extension/analyzer/interface/AbstractAnnotationAnalyzer.d.ts +9 -0
  59. package/dist/hmrouter_extension/analyzer/interface/AbstractAnnotationAnalyzer.js +9 -0
  60. package/dist/hmrouter_extension/analyzer/interface/IConstantResolver.d.ts +7 -0
  61. package/dist/hmrouter_extension/analyzer/interface/IConstantResolver.js +2 -0
  62. package/dist/hmrouter_extension/analyzer/utils/ConstantAnalyzer.d.ts +9 -0
  63. package/dist/hmrouter_extension/analyzer/utils/ConstantAnalyzer.js +32 -0
  64. package/dist/hmrouter_extension/analyzer/utils/ConstantResolver.d.ts +15 -0
  65. package/dist/hmrouter_extension/analyzer/utils/ConstantResolver.js +217 -0
  66. package/dist/hmrouter_extension/analyzer/utils/DecoratorParser.d.ts +7 -0
  67. package/dist/hmrouter_extension/analyzer/utils/DecoratorParser.js +41 -0
  68. package/dist/hmrouter_extension/analyzer/utils/ImportAnalyzer.d.ts +4 -0
  69. package/dist/hmrouter_extension/analyzer/utils/ImportAnalyzer.js +35 -0
  70. package/dist/hmrouter_extension/config/HMRouterPluginConfig.d.ts +38 -0
  71. package/dist/hmrouter_extension/config/HMRouterPluginConfig.js +64 -0
  72. package/dist/hmrouter_extension/constants/AnnotationConstants.d.ts +8 -0
  73. package/dist/hmrouter_extension/constants/AnnotationConstants.js +11 -0
  74. package/dist/hmrouter_extension/constants/FilePathConstants.d.ts +19 -0
  75. package/dist/hmrouter_extension/constants/FilePathConstants.js +26 -0
  76. package/dist/hmrouter_extension/constants/ObfuscationConstants.d.ts +5 -0
  77. package/dist/hmrouter_extension/constants/ObfuscationConstants.js +8 -0
  78. package/dist/hmrouter_extension/constants/PluginConstants.d.ts +7 -0
  79. package/dist/hmrouter_extension/constants/PluginConstants.js +10 -0
  80. package/dist/hmrouter_extension/constants/PrefixConstants.d.ts +8 -0
  81. package/dist/hmrouter_extension/constants/PrefixConstants.js +11 -0
  82. package/dist/hmrouter_extension/constants/RouterMapConstants.d.ts +5 -0
  83. package/dist/hmrouter_extension/constants/RouterMapConstants.js +8 -0
  84. package/dist/hmrouter_extension/constants/TemplateConstants.d.ts +6 -0
  85. package/dist/hmrouter_extension/constants/TemplateConstants.js +9 -0
  86. package/dist/hmrouter_extension/constants/VersionConstants.d.ts +6 -0
  87. package/dist/hmrouter_extension/constants/VersionConstants.js +9 -0
  88. package/dist/hmrouter_extension/constants/index.d.ts +8 -0
  89. package/dist/hmrouter_extension/constants/index.js +22 -0
  90. package/dist/hmrouter_extension/error/PluginError.d.ts +29 -0
  91. package/dist/hmrouter_extension/error/PluginError.js +75 -0
  92. package/dist/hmrouter_extension/model/HMAnnotationModel.d.ts +28 -0
  93. package/dist/hmrouter_extension/model/HMAnnotationModel.js +2 -0
  94. package/dist/hmrouter_extension/model/RouterInfo.d.ts +6 -0
  95. package/dist/hmrouter_extension/model/RouterInfo.js +2 -0
  96. package/dist/hmrouter_extension/model/TemplateModel.d.ts +8 -0
  97. package/dist/hmrouter_extension/model/TemplateModel.js +2 -0
  98. package/dist/hmrouter_extension/model/index.d.ts +3 -0
  99. package/dist/hmrouter_extension/model/index.js +19 -0
  100. package/dist/hmrouter_extension/processor/CodeGenerationProcessor.d.ts +13 -0
  101. package/dist/hmrouter_extension/processor/CodeGenerationProcessor.js +117 -0
  102. package/dist/hmrouter_extension/processor/CompletionProcessor.d.ts +11 -0
  103. package/dist/hmrouter_extension/processor/CompletionProcessor.js +59 -0
  104. package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.d.ts +11 -0
  105. package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.js +53 -0
  106. package/dist/hmrouter_extension/processor/InitializerProcessor.d.ts +15 -0
  107. package/dist/hmrouter_extension/processor/InitializerProcessor.js +96 -0
  108. package/dist/hmrouter_extension/processor/ObfuscationProcessor.d.ts +12 -0
  109. package/dist/hmrouter_extension/processor/ObfuscationProcessor.js +118 -0
  110. package/dist/hmrouter_extension/processor/ResourceProcessor.d.ts +9 -0
  111. package/dist/hmrouter_extension/processor/ResourceProcessor.js +53 -0
  112. package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.d.ts +9 -0
  113. package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.js +117 -0
  114. package/dist/hmrouter_extension/processor/index.d.ts +7 -0
  115. package/dist/hmrouter_extension/processor/index.js +23 -0
  116. package/examples/CustomExtension.ts +256 -0
  117. package/package.json +3 -2
  118. package/template/customBuilder.ejs +1 -0
  119. package/template/viewBuilder.ejs +2 -1
  120. package/template/viewBuilder_v1.ejs +104 -0
@@ -0,0 +1,26 @@
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 path_1 = __importDefault(require("path"));
7
+ class FilePathConstants {
8
+ }
9
+ exports.default = FilePathConstants;
10
+ FilePathConstants.OBFUSCATION_FILE_NAME = 'hmrouter-obfuscation-rules.txt';
11
+ FilePathConstants.CONSUMER_FILE_NAME = 'hmrouter-consumer-rules.txt';
12
+ FilePathConstants.FILE_SEPARATOR = path_1.default.sep;
13
+ FilePathConstants.DELIMITER = '/';
14
+ FilePathConstants.TEMP_ROUTER_MAP_PATH = '../../intermediates/router_map';
15
+ FilePathConstants.RAWFILE_DIR = 'src/main/resources/rawfile/hm_router_map.json';
16
+ FilePathConstants.ETS_SUFFIX = '.ets';
17
+ FilePathConstants.JSON_SUFFIX = '.json';
18
+ FilePathConstants.CONFIG_FILE_NAME = 'hmrouter_config.json';
19
+ FilePathConstants.PARENT_DELIMITER = '../';
20
+ FilePathConstants.CURRENT_DELIMITER = './';
21
+ FilePathConstants.OH_MODULE_PATH = 'oh_modules';
22
+ FilePathConstants.OH_PACKAGE_FILE_NAME = 'oh-package.json5';
23
+ FilePathConstants.LINE_BREAK = '\n';
24
+ FilePathConstants.DEFAULT_SCAN_DIR = 'src/main/ets';
25
+ FilePathConstants.DEFAULT_ROUTER_MAP_DIR = 'src/main/resources/base/profile';
26
+ FilePathConstants.DEFAULT_BUILD_DIR = 'src/main/ets/generated';
@@ -0,0 +1,5 @@
1
+ export default class ObfuscationConstants {
2
+ static readonly KEEP_FILE_NAME = "-keep-file-name";
3
+ static readonly KEEP_PROPERTY_NAME = "-keep-property-name";
4
+ static readonly KEEP_GLOBAL_NAME = "-keep-global-name";
5
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class ObfuscationConstants {
4
+ }
5
+ exports.default = ObfuscationConstants;
6
+ ObfuscationConstants.KEEP_FILE_NAME = '-keep-file-name';
7
+ ObfuscationConstants.KEEP_PROPERTY_NAME = '-keep-property-name';
8
+ ObfuscationConstants.KEEP_GLOBAL_NAME = '-keep-global-name';
@@ -0,0 +1,7 @@
1
+ export default class PluginConstants {
2
+ static readonly HAP_PLUGIN_ID = "HAP_HMROUTER_PLUGIN";
3
+ static readonly HSP_PLUGIN_ID = "HSP_HMROUTER_PLUGIN";
4
+ static readonly HAR_PLUGIN_ID = "HAR_HMROUTER_PLUGIN";
5
+ static readonly HAR_MODULE_NAME = "har";
6
+ static readonly STRUCT_KEYWORD = "struct";
7
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class PluginConstants {
4
+ }
5
+ exports.default = PluginConstants;
6
+ PluginConstants.HAP_PLUGIN_ID = 'HAP_HMROUTER_PLUGIN';
7
+ PluginConstants.HSP_PLUGIN_ID = 'HSP_HMROUTER_PLUGIN';
8
+ PluginConstants.HAR_PLUGIN_ID = 'HAR_HMROUTER_PLUGIN';
9
+ PluginConstants.HAR_MODULE_NAME = 'har';
10
+ PluginConstants.STRUCT_KEYWORD = 'struct';
@@ -0,0 +1,8 @@
1
+ export default class PrefixConstants {
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 SERVICE_PROVIDE_PREFIX = "__service_provider__";
7
+ static readonly VIEW_NAME_PREFIX = "HM";
8
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class PrefixConstants {
4
+ }
5
+ exports.default = PrefixConstants;
6
+ PrefixConstants.ANIMATOR_PREFIX = '__animator__';
7
+ PrefixConstants.INTERCEPTOR_PREFIX = '__interceptor__';
8
+ PrefixConstants.LIFECYCLE_PREFIX = '__lifecycle__';
9
+ PrefixConstants.SERVICE_PREFIX = '__service__';
10
+ PrefixConstants.SERVICE_PROVIDE_PREFIX = '__service_provider__';
11
+ PrefixConstants.VIEW_NAME_PREFIX = 'HM';
@@ -0,0 +1,5 @@
1
+ export default class RouterMapConstants {
2
+ static readonly ROUTER_MAP_KEY = "routerMap";
3
+ static readonly MODULE_ROUTER_MAP_NAME = "$profile:hm_router_map";
4
+ static readonly ROUTER_MAP_NAME = "hm_router_map.json";
5
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class RouterMapConstants {
4
+ }
5
+ exports.default = RouterMapConstants;
6
+ RouterMapConstants.ROUTER_MAP_KEY = 'routerMap';
7
+ RouterMapConstants.MODULE_ROUTER_MAP_NAME = '$profile:hm_router_map';
8
+ RouterMapConstants.ROUTER_MAP_NAME = 'hm_router_map.json';
@@ -0,0 +1,6 @@
1
+ export default class TemplateConstants {
2
+ static readonly CUSTOM_BUILDER_TEMPLATE = "template/customBuilder.ejs";
3
+ static readonly VIEW_BUILDER_TEMPLATE = "template/viewBuilder.ejs";
4
+ static readonly V1_TEMPLATE = "template/viewBuilder_v1.ejs";
5
+ static readonly WARP_BUILDER = "WrapBuilder";
6
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class TemplateConstants {
4
+ }
5
+ exports.default = TemplateConstants;
6
+ TemplateConstants.CUSTOM_BUILDER_TEMPLATE = 'template/customBuilder.ejs';
7
+ TemplateConstants.VIEW_BUILDER_TEMPLATE = 'template/viewBuilder.ejs';
8
+ TemplateConstants.V1_TEMPLATE = 'template/viewBuilder_v1.ejs';
9
+ TemplateConstants.WARP_BUILDER = 'WrapBuilder';
@@ -0,0 +1,6 @@
1
+ export default class VersionConstants {
2
+ static readonly HMROUTER_ORGANIZATION = "@hadss";
3
+ static readonly HMROUTER_LIB_NAME = "hmrouter";
4
+ static readonly HMROUTER_VERSION_KEY = "version";
5
+ static readonly HMROUTER_VERSION_V1 = "1.0.0";
6
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class VersionConstants {
4
+ }
5
+ exports.default = VersionConstants;
6
+ VersionConstants.HMROUTER_ORGANIZATION = '@hadss';
7
+ VersionConstants.HMROUTER_LIB_NAME = 'hmrouter';
8
+ VersionConstants.HMROUTER_VERSION_KEY = 'version';
9
+ VersionConstants.HMROUTER_VERSION_V1 = '1.0.0';
@@ -0,0 +1,8 @@
1
+ export { default as AnnotationConstants } from './AnnotationConstants';
2
+ export { default as PrefixConstants } from './PrefixConstants';
3
+ export { default as FilePathConstants } from './FilePathConstants';
4
+ export { default as TemplateConstants } from './TemplateConstants';
5
+ export { default as RouterMapConstants } from './RouterMapConstants';
6
+ export { default as PluginConstants } from './PluginConstants';
7
+ export { default as ObfuscationConstants } from './ObfuscationConstants';
8
+ export { default as VersionConstants } from './VersionConstants';
@@ -0,0 +1,22 @@
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.VersionConstants = exports.ObfuscationConstants = exports.PluginConstants = exports.RouterMapConstants = exports.TemplateConstants = exports.FilePathConstants = exports.PrefixConstants = exports.AnnotationConstants = void 0;
7
+ var AnnotationConstants_1 = require("./AnnotationConstants");
8
+ Object.defineProperty(exports, "AnnotationConstants", { enumerable: true, get: function () { return __importDefault(AnnotationConstants_1).default; } });
9
+ var PrefixConstants_1 = require("./PrefixConstants");
10
+ Object.defineProperty(exports, "PrefixConstants", { enumerable: true, get: function () { return __importDefault(PrefixConstants_1).default; } });
11
+ var FilePathConstants_1 = require("./FilePathConstants");
12
+ Object.defineProperty(exports, "FilePathConstants", { enumerable: true, get: function () { return __importDefault(FilePathConstants_1).default; } });
13
+ var TemplateConstants_1 = require("./TemplateConstants");
14
+ Object.defineProperty(exports, "TemplateConstants", { enumerable: true, get: function () { return __importDefault(TemplateConstants_1).default; } });
15
+ var RouterMapConstants_1 = require("./RouterMapConstants");
16
+ Object.defineProperty(exports, "RouterMapConstants", { enumerable: true, get: function () { return __importDefault(RouterMapConstants_1).default; } });
17
+ var PluginConstants_1 = require("./PluginConstants");
18
+ Object.defineProperty(exports, "PluginConstants", { enumerable: true, get: function () { return __importDefault(PluginConstants_1).default; } });
19
+ var ObfuscationConstants_1 = require("./ObfuscationConstants");
20
+ Object.defineProperty(exports, "ObfuscationConstants", { enumerable: true, get: function () { return __importDefault(ObfuscationConstants_1).default; } });
21
+ var VersionConstants_1 = require("./VersionConstants");
22
+ Object.defineProperty(exports, "VersionConstants", { enumerable: true, get: function () { return __importDefault(VersionConstants_1).default; } });
@@ -0,0 +1,29 @@
1
+ export declare enum ErrorCode {
2
+ UNKNOWN_ERROR = 40000000,
3
+ DUPLICATE_NAME = 40000001,
4
+ WRONG_DECORATION = 40000002,
5
+ REPEAT_ANNOTATION = 40000003,
6
+ ERROR_CONFIG = 40000004,
7
+ NOT_EMPTY_STRING = 40000005,
8
+ INVALID_STRING_VALUE = 40000006,
9
+ ERROR_PAGE_SOURCE_FILE = 40000007,
10
+ FILE_ACCESS_ERROR = 40000101,
11
+ FILE_NOT_FOUND = 40000102,
12
+ PARSE_FILE_ERROR = 40000103,
13
+ TEMPLATE_RENDER_ERROR = 40000201,
14
+ TEMPLATE_NOT_FOUND = 40000202,
15
+ UNKNOWN_CLASS = 40000301,
16
+ UNKNOWN_PROPERTY = 40000302,
17
+ UNKNOWN_CONSTANT = 40000303,
18
+ UNKNOWN_VARIABLE = 40000304,
19
+ EXTENSION_LOAD_ERROR = 40000401,
20
+ EXTENSION_EXECUTE_ERROR = 40000402
21
+ }
22
+ export declare class PluginError extends Error {
23
+ readonly code: ErrorCode;
24
+ readonly module: string;
25
+ readonly data?: any;
26
+ constructor(code: ErrorCode, module: string, params?: string | string[], data?: any);
27
+ private logError;
28
+ static create(code: ErrorCode, module: string, params?: string | string[], data?: any): PluginError;
29
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PluginError = exports.ErrorCode = void 0;
4
+ const framework_1 = require("../../framework");
5
+ var ErrorCode;
6
+ (function (ErrorCode) {
7
+ ErrorCode[ErrorCode["UNKNOWN_ERROR"] = 40000000] = "UNKNOWN_ERROR";
8
+ ErrorCode[ErrorCode["DUPLICATE_NAME"] = 40000001] = "DUPLICATE_NAME";
9
+ ErrorCode[ErrorCode["WRONG_DECORATION"] = 40000002] = "WRONG_DECORATION";
10
+ ErrorCode[ErrorCode["REPEAT_ANNOTATION"] = 40000003] = "REPEAT_ANNOTATION";
11
+ ErrorCode[ErrorCode["ERROR_CONFIG"] = 40000004] = "ERROR_CONFIG";
12
+ ErrorCode[ErrorCode["NOT_EMPTY_STRING"] = 40000005] = "NOT_EMPTY_STRING";
13
+ ErrorCode[ErrorCode["INVALID_STRING_VALUE"] = 40000006] = "INVALID_STRING_VALUE";
14
+ ErrorCode[ErrorCode["ERROR_PAGE_SOURCE_FILE"] = 40000007] = "ERROR_PAGE_SOURCE_FILE";
15
+ ErrorCode[ErrorCode["FILE_ACCESS_ERROR"] = 40000101] = "FILE_ACCESS_ERROR";
16
+ ErrorCode[ErrorCode["FILE_NOT_FOUND"] = 40000102] = "FILE_NOT_FOUND";
17
+ ErrorCode[ErrorCode["PARSE_FILE_ERROR"] = 40000103] = "PARSE_FILE_ERROR";
18
+ ErrorCode[ErrorCode["TEMPLATE_RENDER_ERROR"] = 40000201] = "TEMPLATE_RENDER_ERROR";
19
+ ErrorCode[ErrorCode["TEMPLATE_NOT_FOUND"] = 40000202] = "TEMPLATE_NOT_FOUND";
20
+ ErrorCode[ErrorCode["UNKNOWN_CLASS"] = 40000301] = "UNKNOWN_CLASS";
21
+ ErrorCode[ErrorCode["UNKNOWN_PROPERTY"] = 40000302] = "UNKNOWN_PROPERTY";
22
+ ErrorCode[ErrorCode["UNKNOWN_CONSTANT"] = 40000303] = "UNKNOWN_CONSTANT";
23
+ ErrorCode[ErrorCode["UNKNOWN_VARIABLE"] = 40000304] = "UNKNOWN_VARIABLE";
24
+ ErrorCode[ErrorCode["EXTENSION_LOAD_ERROR"] = 40000401] = "EXTENSION_LOAD_ERROR";
25
+ ErrorCode[ErrorCode["EXTENSION_EXECUTE_ERROR"] = 40000402] = "EXTENSION_EXECUTE_ERROR";
26
+ })(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
27
+ const ERROR_MAP = new Map([
28
+ [ErrorCode.UNKNOWN_ERROR, 'Unknown error'],
29
+ [ErrorCode.DUPLICATE_NAME, 'Duplicate name: %s'],
30
+ [ErrorCode.WRONG_DECORATION, 'Structure with @HMRouter annotation cannot contain NavDestination component, filePath: %s'],
31
+ [ErrorCode.REPEAT_ANNOTATION, 'File contains multiple annotations of the same type: %s'],
32
+ [ErrorCode.ERROR_CONFIG, 'Module context is empty, please check the hvigorfile.ts file in the module directory: %s'],
33
+ [ErrorCode.NOT_EMPTY_STRING, 'Constant value cannot be an empty string: %s'],
34
+ [ErrorCode.INVALID_STRING_VALUE, 'Invalid string value: %s'],
35
+ [ErrorCode.ERROR_PAGE_SOURCE_FILE, 'Page source file is empty, please check the pageSourceFile: %s'],
36
+ [ErrorCode.FILE_ACCESS_ERROR, 'File access error: %s'],
37
+ [ErrorCode.FILE_NOT_FOUND, 'File not found: %s'],
38
+ [ErrorCode.PARSE_FILE_ERROR, 'File parsing error: %s'],
39
+ [ErrorCode.TEMPLATE_RENDER_ERROR, 'Template rendering error: %s'],
40
+ [ErrorCode.TEMPLATE_NOT_FOUND, 'Template not found: %s'],
41
+ [ErrorCode.UNKNOWN_CLASS, 'Unknown class: %s'],
42
+ [ErrorCode.UNKNOWN_PROPERTY, 'Unknown property: %s'],
43
+ [ErrorCode.UNKNOWN_CONSTANT, 'Unknown constant: %s'],
44
+ [ErrorCode.UNKNOWN_VARIABLE, 'Unknown variable: %s'],
45
+ [ErrorCode.EXTENSION_LOAD_ERROR, 'Extension loading error: %s'],
46
+ [ErrorCode.EXTENSION_EXECUTE_ERROR, 'Extension execution error: %s'],
47
+ ]);
48
+ class PluginError extends Error {
49
+ constructor(code, module, params, data) {
50
+ let message = ERROR_MAP.get(code) || 'Unknown error';
51
+ if (params) {
52
+ if (Array.isArray(params)) {
53
+ params.forEach((param) => {
54
+ message = message.replace(`%s`, param);
55
+ });
56
+ }
57
+ else {
58
+ message = message.replace('%s', params);
59
+ }
60
+ }
61
+ super(message);
62
+ this.code = code;
63
+ this.module = module;
64
+ this.data = data;
65
+ Object.setPrototypeOf(this, PluginError.prototype);
66
+ this.logError();
67
+ }
68
+ logError() {
69
+ framework_1.Logger.error(this.module, `error code: ${this.code}, error message: ${this.message}`, this.data);
70
+ }
71
+ static create(code, module, params, data) {
72
+ return new PluginError(code, module, params, data);
73
+ }
74
+ }
75
+ exports.PluginError = PluginError;
@@ -0,0 +1,28 @@
1
+ import { BaseAnalyzeResult } from '../../framework';
2
+ export interface HMRouterResult extends BaseAnalyzeResult {
3
+ pageUrl: any;
4
+ dialog?: boolean;
5
+ singleton?: boolean;
6
+ interceptors?: string[];
7
+ animator?: string;
8
+ lifecycle?: string;
9
+ useNavDst?: boolean;
10
+ }
11
+ export interface HMAnimatorResult extends BaseAnalyzeResult {
12
+ animatorName: string;
13
+ }
14
+ export interface HMInterceptorResult extends BaseAnalyzeResult {
15
+ interceptorName: string;
16
+ priority?: number;
17
+ global?: boolean;
18
+ }
19
+ export interface HMLifecycleResult extends BaseAnalyzeResult {
20
+ lifecycleName: string;
21
+ priority?: number;
22
+ global?: boolean;
23
+ }
24
+ export interface HMServiceResult extends BaseAnalyzeResult {
25
+ serviceName: string;
26
+ functionName: string;
27
+ singleton?: boolean;
28
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export interface RouterInfo {
2
+ name: string;
3
+ pageSourceFile: string;
4
+ buildFunction: string;
5
+ customData: Record<string, any>;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ export interface TemplateModel {
2
+ pageUrl: string;
3
+ importPath: string;
4
+ componentName: string;
5
+ dialog: boolean;
6
+ generatorViewName: string;
7
+ isDefaultExport?: boolean;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export * from './HMAnnotationModel';
2
+ export * from './TemplateModel';
3
+ export * from './RouterInfo';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./HMAnnotationModel"), exports);
18
+ __exportStar(require("./TemplateModel"), exports);
19
+ __exportStar(require("./RouterInfo"), exports);
@@ -0,0 +1,13 @@
1
+ import { HMRouterExtensionContext } from '../HMRouterExtensionContext';
2
+ export declare class CodeGenerationProcessor {
3
+ private context;
4
+ constructor(context: HMRouterExtensionContext);
5
+ execute(): void;
6
+ private generatePageFile;
7
+ private matchedPath;
8
+ private prepareTemplateModel;
9
+ private determineTemplatePath;
10
+ private generateFile;
11
+ private detectLibraryVersion;
12
+ private getLibraryPossiblePaths;
13
+ }
@@ -0,0 +1,117 @@
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.CodeGenerationProcessor = void 0;
7
+ const micromatch_1 = __importDefault(require("micromatch"));
8
+ const ejs_1 = __importDefault(require("ejs"));
9
+ const framework_1 = require("../../framework");
10
+ const PluginError_1 = require("../error/PluginError");
11
+ const constants_1 = require("../constants");
12
+ class CodeGenerationProcessor {
13
+ constructor(context) {
14
+ this.context = context;
15
+ }
16
+ execute() {
17
+ framework_1.Logger.debug(this.context.node.getNodeName(), `Start to code generation...`);
18
+ this.context.generatedPaths = new Map();
19
+ this.context.getAnalyzeResults().forEach((result) => {
20
+ if (result.annotation === constants_1.AnnotationConstants.ROUTER_ANNOTATION) {
21
+ if (!result.sourceFilePath) {
22
+ throw PluginError_1.PluginError.create(PluginError_1.ErrorCode.ERROR_PAGE_SOURCE_FILE, this.context.config.moduleName, result.sourceFilePath);
23
+ }
24
+ let pageSourceFile = this.context.config
25
+ .getRelativeSourcePath(result.sourceFilePath)
26
+ .replaceAll(constants_1.FilePathConstants.FILE_SEPARATOR, constants_1.FilePathConstants.DELIMITER);
27
+ this.generatePageFile(result, pageSourceFile, this.matchedPath(pageSourceFile, this.context.config.customPageTemplate, this.context.config.getDefaultTplFilePath()));
28
+ }
29
+ });
30
+ }
31
+ generatePageFile(result, pageSourceFile, tempFilePath) {
32
+ const templateModel = this.prepareTemplateModel(result, pageSourceFile);
33
+ tempFilePath = this.determineTemplatePath(result, tempFilePath);
34
+ const generatedFilePath = this.generateFile(templateModel, tempFilePath);
35
+ framework_1.Logger.info(this.context.node.getNodeName(), `Builder ${templateModel.generatorViewName}.ets has been generated in ${generatedFilePath}`);
36
+ this.context.generatedPaths.set(result.name, generatedFilePath);
37
+ }
38
+ matchedPath(filePath, customPageTemplate, defaultTplFilePath) {
39
+ for (const template of customPageTemplate) {
40
+ if (micromatch_1.default.isMatch(filePath, template.srcPath)) {
41
+ framework_1.Logger.debug(this.context.node.getNodeName(), `${filePath} detected matching template: ${template.templatePath}`);
42
+ return framework_1.PluginFileUtil.pathResolve(this.context.config.configDir, template.templatePath);
43
+ }
44
+ }
45
+ return defaultTplFilePath;
46
+ }
47
+ prepareTemplateModel(analyzeResult, pageSourceFile) {
48
+ let importPath = this.context.config
49
+ .getRelativeBuilderPath(pageSourceFile)
50
+ .replaceAll(constants_1.FilePathConstants.FILE_SEPARATOR, constants_1.FilePathConstants.DELIMITER)
51
+ .replaceAll(constants_1.FilePathConstants.ETS_SUFFIX, '');
52
+ let generatorViewName = constants_1.PrefixConstants.VIEW_NAME_PREFIX + analyzeResult.name + framework_1.StringUtil.stringToHashCode(analyzeResult.pageUrl);
53
+ let templateData = this.context.getTemplateData(analyzeResult.name);
54
+ return {
55
+ pageUrl: analyzeResult.pageUrl,
56
+ componentName: analyzeResult.name,
57
+ dialog: !!analyzeResult.dialog,
58
+ isDefaultExport: !!templateData?.isDefaultExport,
59
+ importPath,
60
+ generatorViewName,
61
+ ...templateData,
62
+ };
63
+ }
64
+ determineTemplatePath(analyzeResult, defaultTemplatePath) {
65
+ const libraryVersion = this.detectLibraryVersion();
66
+ framework_1.Logger.debug(this.context.node.getNodeName(), `Library version: ${libraryVersion}`);
67
+ const useV1Template = libraryVersion.startsWith(constants_1.VersionConstants.HMROUTER_VERSION_V1);
68
+ if (useV1Template) {
69
+ return framework_1.PluginFileUtil.pathResolve(__dirname, constants_1.FilePathConstants.PARENT_DELIMITER.repeat(3) + constants_1.TemplateConstants.V1_TEMPLATE);
70
+ }
71
+ else if (analyzeResult.useNavDst === true) {
72
+ return framework_1.PluginFileUtil.pathResolve(__dirname, constants_1.FilePathConstants.PARENT_DELIMITER.repeat(3), constants_1.TemplateConstants.CUSTOM_BUILDER_TEMPLATE);
73
+ }
74
+ return defaultTemplatePath;
75
+ }
76
+ generateFile(templateModel, templatePath) {
77
+ if (!framework_1.PluginFileUtil.exist(templatePath)) {
78
+ throw PluginError_1.PluginError.create(PluginError_1.ErrorCode.TEMPLATE_NOT_FOUND, this.context.config.moduleName, templatePath);
79
+ }
80
+ const tpl = framework_1.PluginFileUtil.readFileSync(templatePath).toString();
81
+ const templateStr = ejs_1.default.render(tpl, templateModel);
82
+ const generatorFilePath = this.context.config.getGeneratedFilePath(templateModel.generatorViewName);
83
+ framework_1.PluginFileUtil.ensureFileSync(generatorFilePath);
84
+ framework_1.PluginFileUtil.writeFileSync(generatorFilePath, templateStr);
85
+ return this.context.config
86
+ .getBuilderFilePath(templateModel.generatorViewName)
87
+ .replaceAll(constants_1.FilePathConstants.FILE_SEPARATOR, constants_1.FilePathConstants.DELIMITER);
88
+ }
89
+ detectLibraryVersion() {
90
+ let libraryVersion = '';
91
+ const possiblePaths = this.getLibraryPossiblePaths();
92
+ for (const packagePath of possiblePaths) {
93
+ try {
94
+ if (framework_1.PluginFileUtil.exist(packagePath)) {
95
+ const packageJson = framework_1.PluginFileUtil.readJson5(packagePath);
96
+ libraryVersion = packageJson[constants_1.VersionConstants.HMROUTER_VERSION_KEY] || '';
97
+ if (libraryVersion) {
98
+ break;
99
+ }
100
+ }
101
+ }
102
+ catch (error) {
103
+ }
104
+ }
105
+ return libraryVersion;
106
+ }
107
+ getLibraryPossiblePaths() {
108
+ const paths = [];
109
+ paths.push(framework_1.PluginFileUtil.pathResolve(this.context.config.modulePath, constants_1.FilePathConstants.OH_MODULE_PATH, constants_1.VersionConstants.HMROUTER_ORGANIZATION, constants_1.VersionConstants.HMROUTER_LIB_NAME, constants_1.FilePathConstants.OH_PACKAGE_FILE_NAME));
110
+ const projectRoot = framework_1.PluginStore.getInstance().get('projectFilePath');
111
+ if (projectRoot && projectRoot !== this.context.config.modulePath) {
112
+ paths.push(framework_1.PluginFileUtil.pathResolve(projectRoot, constants_1.FilePathConstants.OH_MODULE_PATH, constants_1.VersionConstants.HMROUTER_ORGANIZATION, constants_1.VersionConstants.HMROUTER_LIB_NAME, constants_1.FilePathConstants.OH_PACKAGE_FILE_NAME));
113
+ }
114
+ return paths;
115
+ }
116
+ }
117
+ exports.CodeGenerationProcessor = CodeGenerationProcessor;
@@ -0,0 +1,11 @@
1
+ import { HMRouterExtensionContext } from '../HMRouterExtensionContext';
2
+ export declare class CompletionProcessor {
3
+ private context;
4
+ private config;
5
+ constructor(context: HMRouterExtensionContext);
6
+ execute(): void;
7
+ private deleteRouterMapFile;
8
+ private deleteRawFile;
9
+ private deleteGeneratorFile;
10
+ private deleteObfuscationFile;
11
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CompletionProcessor = void 0;
4
+ const framework_1 = require("../../framework");
5
+ class CompletionProcessor {
6
+ constructor(context) {
7
+ this.context = context;
8
+ this.config = context.config;
9
+ }
10
+ execute() {
11
+ framework_1.Logger.debug(this.context.node.getNodeName(), `Start to delete temporary files...`);
12
+ if (this.context.config.saveGeneratedFile) {
13
+ framework_1.Logger.info(this.context.node.getNodeName(), `Save generated file is true, skip deleting temporary files`);
14
+ return;
15
+ }
16
+ this.deleteRouterMapFile();
17
+ this.deleteRawFile();
18
+ this.deleteGeneratorFile();
19
+ if (this.config?.autoObfuscation) {
20
+ this.deleteObfuscationFile();
21
+ }
22
+ }
23
+ deleteRouterMapFile() {
24
+ let routerMapDirPath = this.config.getRouterMapDir();
25
+ if (framework_1.PluginFileUtil.exist(routerMapDirPath)) {
26
+ framework_1.PluginFileUtil.unlinkSync(routerMapDirPath);
27
+ framework_1.Logger.info(this.context.node.getNodeName(), `Delete router map file successfully, filePath: ${routerMapDirPath}`);
28
+ }
29
+ }
30
+ deleteRawFile() {
31
+ let rawFilePath = this.config.getRawFilePath();
32
+ if (framework_1.PluginFileUtil.exist(rawFilePath)) {
33
+ framework_1.PluginFileUtil.unlinkSync(rawFilePath);
34
+ framework_1.Logger.info(this.context.node.getNodeName(), `Delete raw file successfully, filePath: ${rawFilePath}`);
35
+ }
36
+ }
37
+ deleteGeneratorFile() {
38
+ let builderDirPath = this.config.getBuilderDir();
39
+ if (framework_1.PluginFileUtil.exist(builderDirPath)) {
40
+ framework_1.PluginFileUtil.rmSync(builderDirPath, {
41
+ recursive: true,
42
+ });
43
+ framework_1.Logger.info(this.context.node.getNodeName(), `Delete generator file successfully, filePath: ${builderDirPath}`);
44
+ }
45
+ }
46
+ deleteObfuscationFile() {
47
+ let obfuscationFilePath = this.config.getObfuscationFilePath();
48
+ if (framework_1.PluginFileUtil.exist(obfuscationFilePath)) {
49
+ framework_1.PluginFileUtil.unlinkSync(obfuscationFilePath);
50
+ framework_1.Logger.info(this.context.node.getNodeName(), `Delete obfuscation file successfully, filePath: ${obfuscationFilePath}`);
51
+ }
52
+ let consumerRulesPath = this.config.getConsumerRulesFilePath();
53
+ if (framework_1.PluginFileUtil.exist(consumerRulesPath)) {
54
+ framework_1.PluginFileUtil.unlinkSync(consumerRulesPath);
55
+ framework_1.Logger.info(this.context.node.getNodeName(), `Delete consumer rules file successfully, filePath: ${consumerRulesPath}`);
56
+ }
57
+ }
58
+ }
59
+ exports.CompletionProcessor = CompletionProcessor;
@@ -0,0 +1,11 @@
1
+ import { HMRouterExtensionContext } from '../HMRouterExtensionContext';
2
+ export declare class ConfigUpdateProcessor {
3
+ private moduleContext;
4
+ private readonly routerMap;
5
+ private readonly nodeName;
6
+ constructor(context: HMRouterExtensionContext);
7
+ execute(): void;
8
+ private updateModuleJson;
9
+ private updateBuildProfile;
10
+ private pushRouterInfo;
11
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigUpdateProcessor = void 0;
4
+ const framework_1 = require("../../framework");
5
+ const constants_1 = require("../constants");
6
+ class ConfigUpdateProcessor {
7
+ constructor(context) {
8
+ this.moduleContext = context.moduleContext;
9
+ this.routerMap = context.routerMap;
10
+ this.nodeName = context.node.getNodeName();
11
+ }
12
+ execute() {
13
+ framework_1.Logger.debug(this.nodeName, `Start to update module.json and build profile...`);
14
+ this.updateModuleJson();
15
+ this.updateBuildProfile();
16
+ }
17
+ updateModuleJson() {
18
+ const moduleJsonOpt = this.moduleContext.getModuleJsonOpt();
19
+ moduleJsonOpt.module.routerMap = constants_1.RouterMapConstants.MODULE_ROUTER_MAP_NAME;
20
+ this.moduleContext.setModuleJsonOpt(moduleJsonOpt);
21
+ framework_1.Logger.info(this.nodeName, `Update module.json5 routerMap successfully, current routerMap: ${this.moduleContext.getModuleJsonOpt().module.routerMap}`);
22
+ }
23
+ updateBuildProfile() {
24
+ const buildProfileOpt = this.moduleContext.getBuildProfileOpt();
25
+ let sources = framework_1.ObjectUtils.ensureNestedObject(buildProfileOpt, [
26
+ 'buildOption',
27
+ 'arkOptions',
28
+ 'runtimeOnly',
29
+ 'sources',
30
+ ]);
31
+ if (!Array.isArray(sources)) {
32
+ buildProfileOpt.buildOption.arkOptions.runtimeOnly.sources = [];
33
+ }
34
+ this.pushRouterInfo(buildProfileOpt, this.routerMap);
35
+ this.moduleContext.setBuildProfileOpt(buildProfileOpt);
36
+ framework_1.Logger.info(this.nodeName, `Update build profile successfully, current sources: ${this.moduleContext.getBuildProfileOpt()?.buildOption?.arkOptions?.runtimeOnly?.sources}`);
37
+ }
38
+ pushRouterInfo(buildProfileOpt, routerMap) {
39
+ let sources = buildProfileOpt.buildOption.arkOptions.runtimeOnly.sources;
40
+ routerMap.forEach((item) => {
41
+ const name = item.name;
42
+ if (name.includes(constants_1.PrefixConstants.LIFECYCLE_PREFIX) ||
43
+ name.includes(constants_1.PrefixConstants.INTERCEPTOR_PREFIX) ||
44
+ name.includes(constants_1.PrefixConstants.ANIMATOR_PREFIX) ||
45
+ name.includes(constants_1.PrefixConstants.SERVICE_PREFIX) ||
46
+ name.includes(constants_1.PrefixConstants.SERVICE_PROVIDE_PREFIX)) {
47
+ sources.push(constants_1.FilePathConstants.CURRENT_DELIMITER + item.pageSourceFile);
48
+ }
49
+ });
50
+ sources = [...new Set(sources)];
51
+ }
52
+ }
53
+ exports.ConfigUpdateProcessor = ConfigUpdateProcessor;