@hadss/hmrouter-plugin 1.0.0-rc.0 → 1.0.0-rc.10

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 (50) hide show
  1. package/LICENSE +77 -77
  2. package/README.md +260 -37
  3. package/dist/HMRouterAnalyzer.d.ts +31 -0
  4. package/dist/HMRouterAnalyzer.js +293 -0
  5. package/dist/HMRouterHvigorPlugin.d.ts +15 -0
  6. package/dist/HMRouterHvigorPlugin.js +139 -0
  7. package/dist/HMRouterPluginConfig.d.ts +39 -0
  8. package/dist/HMRouterPluginConfig.js +73 -0
  9. package/dist/HMRouterPluginHandle.d.ts +23 -0
  10. package/dist/HMRouterPluginHandle.js +231 -0
  11. package/dist/Index.d.ts +4 -0
  12. package/dist/Index.js +124 -0
  13. package/dist/common/Constant.d.ts +27 -0
  14. package/dist/common/Constant.js +35 -0
  15. package/dist/common/Logger.d.ts +13 -0
  16. package/dist/common/Logger.js +55 -0
  17. package/dist/common/PluginModel.d.ts +50 -0
  18. package/dist/common/PluginModel.js +23 -0
  19. package/dist/constants/CommonConstants.d.ts +39 -0
  20. package/dist/constants/CommonConstants.js +46 -0
  21. package/dist/constants/ConfigConstants.d.ts +11 -0
  22. package/dist/constants/ConfigConstants.js +15 -0
  23. package/dist/constants/TaskConstants.d.ts +9 -0
  24. package/dist/constants/TaskConstants.js +13 -0
  25. package/dist/store/PluginStore.d.ts +12 -0
  26. package/dist/store/PluginStore.js +19 -0
  27. package/dist/utils/ConfusionUtil.d.ts +4 -0
  28. package/dist/utils/ConfusionUtil.js +27 -0
  29. package/dist/utils/FileUtil.d.ts +11 -0
  30. package/dist/utils/FileUtil.js +20 -0
  31. package/dist/utils/ObfuscationUtil.d.ts +4 -0
  32. package/dist/utils/ObfuscationUtil.js +34 -0
  33. package/dist/utils/StringUtil.d.ts +3 -0
  34. package/dist/utils/StringUtil.js +18 -0
  35. package/dist/utils/TsAstUtil.d.ts +9 -0
  36. package/dist/utils/TsAstUtil.js +89 -0
  37. package/package.json +46 -27
  38. package/viewBuilder.ejs +103 -0
  39. package/lib/HMRouterAnalyzer.js +0 -223
  40. package/lib/HMRouterHvigorPlugin.js +0 -175
  41. package/lib/HMRouterPluginConfig.js +0 -31
  42. package/lib/Index.js +0 -201
  43. package/lib/PluginModel.js +0 -33
  44. package/src/HMRouterAnalyzer.ts +0 -253
  45. package/src/HMRouterHvigorPlugin.ts +0 -246
  46. package/src/HMRouterPluginConfig.ts +0 -44
  47. package/src/Index.ts +0 -218
  48. package/src/PluginModel.ts +0 -50
  49. package/tsconfig.json +0 -14
  50. package/viewBuilder.tpl +0 -97
@@ -0,0 +1,231 @@
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.HMRouterPluginHandle = void 0;
7
+ const hvigor_1 = require("@ohos/hvigor");
8
+ const hvigor_ohos_plugin_1 = require("@ohos/hvigor-ohos-plugin");
9
+ const HMRouterPluginConfig_1 = require("./HMRouterPluginConfig");
10
+ const HMRouterHvigorPlugin_1 = require("./HMRouterHvigorPlugin");
11
+ const Logger_1 = require("./common/Logger");
12
+ const CommonConstants_1 = __importDefault(require("./constants/CommonConstants"));
13
+ const TaskConstants_1 = __importDefault(require("./constants/TaskConstants"));
14
+ const FileUtil_1 = __importDefault(require("./utils/FileUtil"));
15
+ const ObfuscationUtil_1 = __importDefault(require("./utils/ObfuscationUtil"));
16
+ const PluginStore_1 = __importDefault(require("./store/PluginStore"));
17
+ class HMRouterPluginHandle {
18
+ constructor(node, moduleContext) {
19
+ this.node = node;
20
+ this.moduleContext = moduleContext;
21
+ this.config = this.readConfig();
22
+ this.appContext = this.node.getParentNode()?.getContext(hvigor_ohos_plugin_1.OhosPluginId.OHOS_APP_PLUGIN);
23
+ PluginStore_1.default.getInstance().projectFilePath = this.appContext.getProjectPath();
24
+ this.plugin = new HMRouterHvigorPlugin_1.HMRouterHvigorPlugin(this.config);
25
+ }
26
+ start() {
27
+ Logger_1.Logger.info(`Exec ${this.moduleContext.getModuleType()}Plugin..., node:${this.node.getNodeName()}, nodePath:${this.node.getNodePath()}`);
28
+ this.moduleContext.targets((target) => {
29
+ const targetName = target.getTargetName();
30
+ this.node.registerTask({
31
+ name: targetName + TaskConstants_1.default.PLUGIN_TASK,
32
+ run: () => {
33
+ this.taskExec();
34
+ this.plugin.scanFiles = [];
35
+ this.plugin.routerMap = [];
36
+ },
37
+ dependencies: [targetName + TaskConstants_1.default.PRE_BUILD],
38
+ postDependencies: [targetName + TaskConstants_1.default.MERGE_PROFILE]
39
+ });
40
+ this.node.registerTask({
41
+ name: targetName + TaskConstants_1.default.COPY_ROUTER_MAP_TASK,
42
+ run: () => {
43
+ this.copyRouterMapToRawFileTask(target.getBuildTargetOutputPath(), targetName);
44
+ this.writeHspModuleName();
45
+ },
46
+ dependencies: [targetName + TaskConstants_1.default.PROCESS_ROUTER_MAP],
47
+ postDependencies: [targetName + TaskConstants_1.default.PROCESS_RESOURCE]
48
+ });
49
+ this.node.registerTask({
50
+ name: targetName + TaskConstants_1.default.GENERATE_OBFUSCATION_TASK,
51
+ run: () => {
52
+ this.generateObfuscationFileTask(this.moduleContext.getBuildProfileOpt());
53
+ },
54
+ dependencies: [targetName + TaskConstants_1.default.PLUGIN_TASK],
55
+ postDependencies: [targetName + TaskConstants_1.default.MERGE_PROFILE]
56
+ });
57
+ });
58
+ }
59
+ generateObfuscationFileTask(buildProfileOpt) {
60
+ if (!this.isEnableObfuscation(buildProfileOpt)) {
61
+ Logger_1.Logger.info('This compilation does not turn on code obfuscation, skip hmrouter_obfuscation_rules.txt file generation');
62
+ return;
63
+ }
64
+ let obfuscationFilePath = FileUtil_1.default.pathResolve(this.config.modulePath, CommonConstants_1.default.OBFUSCATION_FILE_NAME);
65
+ let routerMap = JSON.parse(FileUtil_1.default.readFileSync(this.config.getRouterMapDir()).toString()).routerMap;
66
+ let obfuscationString = ObfuscationUtil_1.default.buildObfuscatedStrings(routerMap);
67
+ FileUtil_1.default.ensureFileSync(obfuscationFilePath);
68
+ FileUtil_1.default.writeFileSync(obfuscationFilePath, obfuscationString);
69
+ if (this.moduleContext.getModuleType() === CommonConstants_1.default.HAR_MODULE_NAME) {
70
+ let consumerRulesPath = FileUtil_1.default.pathResolve(this.config.modulePath, CommonConstants_1.default.CONSUMER_FILE_NAME);
71
+ FileUtil_1.default.ensureFileSync(consumerRulesPath);
72
+ FileUtil_1.default.writeFileSync(consumerRulesPath, obfuscationString);
73
+ }
74
+ Logger_1.Logger.info('Generate obfuscation rule file successfully, filePath:', obfuscationFilePath);
75
+ }
76
+ isEnableObfuscation(buildProfileOpt) {
77
+ let currentBuildMode = this.appContext.getBuildMode();
78
+ let buildOption = buildProfileOpt.buildOptionSet?.find((item) => {
79
+ return item.name == currentBuildMode;
80
+ });
81
+ if (!buildOption)
82
+ return false;
83
+ let ruleOptions = this.ensureNestedObject(buildOption, ['arkOptions', 'obfuscation', 'ruleOptions']);
84
+ if (this.config.autoObfuscation && ruleOptions.enable) {
85
+ let files = this.ensureNestedObject(buildOption, ['arkOptions', 'obfuscation', 'ruleOptions', 'files']);
86
+ let obfuscationFilePath = CommonConstants_1.default.CURRENT_DELIMITER +
87
+ CommonConstants_1.default.OBFUSCATION_FILE_NAME;
88
+ if (typeof files === 'string') {
89
+ ruleOptions.files = [files, obfuscationFilePath];
90
+ }
91
+ else if (Array.isArray(files)) {
92
+ files.push(obfuscationFilePath);
93
+ }
94
+ else {
95
+ ruleOptions.files = obfuscationFilePath;
96
+ }
97
+ if (this.moduleContext.getModuleType() === CommonConstants_1.default.HAR_MODULE_NAME) {
98
+ let consumerFiles = this.ensureNestedObject(buildOption, ['arkOptions', 'obfuscation', 'consumerFiles']);
99
+ let consumerRulesPath = CommonConstants_1.default.CURRENT_DELIMITER +
100
+ CommonConstants_1.default.CONSUMER_FILE_NAME;
101
+ if (typeof consumerFiles === 'string') {
102
+ this.ensureNestedObject(buildOption, ['arkOptions', 'obfuscation']).consumerFiles =
103
+ [consumerFiles, consumerRulesPath];
104
+ }
105
+ else if (Array.isArray(consumerFiles)) {
106
+ consumerFiles.push(consumerRulesPath);
107
+ }
108
+ else {
109
+ this.ensureNestedObject(buildOption, ['arkOptions', 'obfuscation']).consumerFiles = consumerRulesPath;
110
+ }
111
+ }
112
+ this.moduleContext.setBuildProfileOpt(buildProfileOpt);
113
+ }
114
+ return ruleOptions.enable;
115
+ }
116
+ copyRouterMapToRawFileTask(buildOutputPath, targetName) {
117
+ let routerMapFilePath = FileUtil_1.default.pathResolve(buildOutputPath, CommonConstants_1.default.TEMP_ROUTER_MAP_PATH, targetName, CommonConstants_1.default.ROUTER_MAP_NAME);
118
+ let rawFilePath = this.config.getRawFilePath();
119
+ FileUtil_1.default.ensureFileSync(rawFilePath);
120
+ FileUtil_1.default.copyFileSync(routerMapFilePath, rawFilePath);
121
+ }
122
+ writeHspModuleName() {
123
+ if (!this.node.getAllPluginIds().includes(hvigor_ohos_plugin_1.OhosPluginId.OHOS_HAP_PLUGIN))
124
+ return;
125
+ let rawFilePath = this.config.getRawFilePath();
126
+ let rawFileRouterMap = JSON.parse(FileUtil_1.default.readFileSync(rawFilePath).toString());
127
+ rawFileRouterMap.hspModuleNames = [];
128
+ hvigor_1.hvigor.getAllNodes().forEach((node) => {
129
+ let pluginIds = node.getAllPluginIds();
130
+ if (pluginIds.includes(hvigor_ohos_plugin_1.OhosPluginId.OHOS_HSP_PLUGIN)) {
131
+ let packageJson = FileUtil_1.default.readJson5(FileUtil_1.default.pathResolve(node.getNodePath(), 'oh-package.json5'));
132
+ rawFileRouterMap.hspModuleNames.push(packageJson.name);
133
+ }
134
+ rawFileRouterMap.hspModuleNames.push(...this.getRemoteHspModuleNames(node, pluginIds));
135
+ });
136
+ rawFileRouterMap.hspModuleNames = [...new Set(rawFileRouterMap.hspModuleNames)];
137
+ FileUtil_1.default.writeFileSync(rawFilePath, JSON.stringify(rawFileRouterMap));
138
+ }
139
+ getRemoteHspModuleNames(node, pluginIds) {
140
+ let remoteHspModuleNames = [];
141
+ try {
142
+ pluginIds.forEach((id) => {
143
+ let context = node.getContext(id);
144
+ let signedHspObj = context.getOhpmRemoteHspDependencyInfo(true);
145
+ let remoteHspObj = context.getOhpmRemoteHspDependencyInfo(false);
146
+ for (const key in signedHspObj) {
147
+ remoteHspModuleNames.push(signedHspObj[key].name);
148
+ }
149
+ for (const key in remoteHspObj) {
150
+ remoteHspModuleNames.push(remoteHspObj[key].name);
151
+ }
152
+ });
153
+ }
154
+ catch (error) {
155
+ Logger_1.Logger.warn('Your DevEco Studio version less than 5.0.3.800, may cause remote hsp dependencies get failed');
156
+ }
157
+ return remoteHspModuleNames;
158
+ }
159
+ taskExec() {
160
+ let startTime = Date.now();
161
+ Logger_1.Logger.info(this.node.getNodeName() + ': HMRouterPluginTask start');
162
+ this.plugin.analyzeAnnotation();
163
+ this.updateModuleJsonOpt();
164
+ this.updateBuildProfileOpt();
165
+ let endTime = Date.now();
166
+ Logger_1.Logger.info(this.config.moduleName + ': HMRouterPluginTask end');
167
+ Logger_1.Logger.info(this.config.moduleName + ': HMRouterPluginTask cost: ' + (endTime - startTime) + ' ms');
168
+ }
169
+ updateModuleJsonOpt() {
170
+ const moduleJsonOpt = this.moduleContext.getModuleJsonOpt();
171
+ if (moduleJsonOpt.module.routerMap) {
172
+ let routerMapFileName = moduleJsonOpt.module.routerMap.split(':')[1];
173
+ let routerMapFilePath = this.config.getModuleRouterMapFilePath(routerMapFileName);
174
+ let routerMapObj = FileUtil_1.default.readJson5(routerMapFilePath);
175
+ if (routerMapFileName !== 'hm_router_map') {
176
+ this.plugin.routerMap.unshift(...routerMapObj[CommonConstants_1.default.ROUTER_MAP_KEY]);
177
+ }
178
+ }
179
+ this.plugin.generateRouterMap();
180
+ moduleJsonOpt.module.routerMap = CommonConstants_1.default.MODULE_ROUTER_MAP_NAME;
181
+ this.moduleContext.setModuleJsonOpt(moduleJsonOpt);
182
+ }
183
+ updateBuildProfileOpt() {
184
+ const buildProfileOpt = this.moduleContext.getBuildProfileOpt();
185
+ let sources = this.ensureNestedObject(buildProfileOpt, ['buildOption', 'arkOptions', 'runtimeOnly', 'sources']);
186
+ if (!Array.isArray(sources)) {
187
+ buildProfileOpt.buildOption.arkOptions.runtimeOnly.sources = [];
188
+ }
189
+ this.pushRouterInfo(buildProfileOpt, this.plugin.routerMap);
190
+ this.moduleContext.setBuildProfileOpt(buildProfileOpt);
191
+ }
192
+ pushRouterInfo(buildProfileOpt, routerMap) {
193
+ const sources = buildProfileOpt.buildOption.arkOptions.runtimeOnly.sources;
194
+ routerMap.forEach((item) => {
195
+ const name = item.name;
196
+ if (name.includes(CommonConstants_1.default.LIFECYCLE_PREFIX) ||
197
+ name.includes(CommonConstants_1.default.INTERCEPTOR_PREFIX) ||
198
+ name.includes(CommonConstants_1.default.ANIMATOR_PREFIX) ||
199
+ name.includes(CommonConstants_1.default.SERVICE_PREFIX)) {
200
+ sources.push(CommonConstants_1.default.CURRENT_DELIMITER + item.pageSourceFile);
201
+ }
202
+ });
203
+ }
204
+ readConfig() {
205
+ let configParam;
206
+ let configFilePath;
207
+ let configDir;
208
+ configFilePath = FileUtil_1.default.pathResolve(this.node.getNodePath(), CommonConstants_1.default.CONFIG_FILE_NAME);
209
+ if (!FileUtil_1.default.exist(configFilePath)) {
210
+ configFilePath =
211
+ FileUtil_1.default.pathResolve(PluginStore_1.default.getInstance().projectFilePath, CommonConstants_1.default.CONFIG_FILE_NAME);
212
+ }
213
+ if (FileUtil_1.default.exist(configFilePath)) {
214
+ configParam = FileUtil_1.default.readJson5(configFilePath);
215
+ }
216
+ else {
217
+ configParam = {};
218
+ }
219
+ configDir = FileUtil_1.default.pathResolve(configFilePath, CommonConstants_1.default.PARENT_DELIMITER);
220
+ return new HMRouterPluginConfig_1.HMRouterPluginConfig(this.node.getNodeName(), this.node.getNodePath(), configDir, configParam);
221
+ }
222
+ ensureNestedObject(obj, path) {
223
+ return path.reduce((acc, key) => {
224
+ if (!acc[key]) {
225
+ acc[key] = {};
226
+ }
227
+ return acc[key];
228
+ }, obj);
229
+ }
230
+ }
231
+ exports.HMRouterPluginHandle = HMRouterPluginHandle;
@@ -0,0 +1,4 @@
1
+ import { HvigorPlugin } from '@ohos/hvigor';
2
+ export declare function hapPlugin(): HvigorPlugin;
3
+ export declare function hspPlugin(): HvigorPlugin;
4
+ export declare function harPlugin(): HvigorPlugin;
package/dist/Index.js ADDED
@@ -0,0 +1,124 @@
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.hapPlugin = hapPlugin;
7
+ exports.hspPlugin = hspPlugin;
8
+ exports.harPlugin = harPlugin;
9
+ const hvigor_1 = require("@ohos/hvigor");
10
+ const hvigor_ohos_plugin_1 = require("@ohos/hvigor-ohos-plugin");
11
+ const Logger_1 = require("./common/Logger");
12
+ const CommonConstants_1 = __importDefault(require("./constants/CommonConstants"));
13
+ const TsAstUtil_1 = require("./utils/TsAstUtil");
14
+ const FileUtil_1 = __importDefault(require("./utils/FileUtil"));
15
+ const HMRouterPluginHandle_1 = require("./HMRouterPluginHandle");
16
+ class HMRouterPluginMgr {
17
+ constructor() {
18
+ this.hmRouterPluginSet = new Set();
19
+ hvigor_1.hvigor.nodesEvaluated(() => {
20
+ this.hmRouterPluginSet.forEach((pluginHandle) => {
21
+ pluginHandle.start();
22
+ });
23
+ });
24
+ hvigor_1.hvigor.buildFinished(() => {
25
+ Logger_1.Logger.info('buildFinished deleteFile exec...');
26
+ this.hmRouterPluginSet.forEach((pluginHandle) => {
27
+ if (pluginHandle.config.saveGeneratedFile) {
28
+ Logger_1.Logger.info(pluginHandle.config.moduleName + ' saveGeneratedFile is true, skip deleting');
29
+ return;
30
+ }
31
+ this.deleteRouterMapFile(pluginHandle);
32
+ this.deleteRawFile(pluginHandle);
33
+ this.deleteGeneratorFile(pluginHandle);
34
+ if (pluginHandle.config.autoObfuscation) {
35
+ this.deleteObfuscationFile(pluginHandle);
36
+ }
37
+ });
38
+ HMRouterPluginMgrInstance = null;
39
+ TsAstUtil_1.TsAstUtil.clearProject();
40
+ });
41
+ }
42
+ registerHMRouterPlugin(node, pluginId) {
43
+ const moduleContext = node.getContext(pluginId);
44
+ if (!moduleContext) {
45
+ Logger_1.Logger.error(Logger_1.PluginError.ERR_ERROR_CONFIG, node.getNodePath());
46
+ throw new Error('moduleContext is null');
47
+ }
48
+ let pluginHandle = new HMRouterPluginHandle_1.HMRouterPluginHandle(node, moduleContext);
49
+ if (pluginId === hvigor_ohos_plugin_1.OhosPluginId.OHOS_HAP_PLUGIN) {
50
+ let packageJson = FileUtil_1.default.readJson5(FileUtil_1.default.pathResolve(node.getNodePath(), 'oh-package.json5'));
51
+ pluginHandle.config.moduleName = packageJson.name;
52
+ }
53
+ this.hmRouterPluginSet.add(pluginHandle);
54
+ }
55
+ deleteGeneratorFile(pluginHandle) {
56
+ let builderDirPath = pluginHandle.config.getBuilderDir();
57
+ if (FileUtil_1.default.exist(builderDirPath)) {
58
+ FileUtil_1.default.rmSync(builderDirPath, {
59
+ recursive: true
60
+ });
61
+ Logger_1.Logger.info(pluginHandle.config.modulePath + ' delete builder dir');
62
+ }
63
+ }
64
+ deleteRouterMapFile(pluginHandle) {
65
+ let routerMapDirPath = pluginHandle.config.getRouterMapDir();
66
+ if (FileUtil_1.default.exist(routerMapDirPath)) {
67
+ FileUtil_1.default.unlinkSync(routerMapDirPath);
68
+ Logger_1.Logger.info(routerMapDirPath + ' delete hm_router_map.json');
69
+ }
70
+ }
71
+ deleteRawFile(pluginHandle) {
72
+ let rawFilePath = pluginHandle.config.getRawFilePath();
73
+ if (FileUtil_1.default.exist(rawFilePath)) {
74
+ FileUtil_1.default.unlinkSync(rawFilePath);
75
+ Logger_1.Logger.info(pluginHandle.config.modulePath + ' delete rawfile hm_router_map.json');
76
+ }
77
+ }
78
+ deleteObfuscationFile(pluginHandle) {
79
+ let obfuscationFilePath = pluginHandle.config.getObfuscationFilePath();
80
+ if (FileUtil_1.default.exist(obfuscationFilePath)) {
81
+ FileUtil_1.default.unlinkSync(obfuscationFilePath);
82
+ Logger_1.Logger.info(pluginHandle.config.modulePath + ' delete obfuscation hmrouter-obfuscation-rules.txt');
83
+ }
84
+ let consumerRulesPath = pluginHandle.config.getConsumerRulesFilePath();
85
+ if (FileUtil_1.default.exist(consumerRulesPath)) {
86
+ FileUtil_1.default.unlinkSync(consumerRulesPath);
87
+ Logger_1.Logger.info(pluginHandle.config.modulePath + ' delete hmrouter-consumer-rules.txt');
88
+ }
89
+ }
90
+ }
91
+ let HMRouterPluginMgrInstance = null;
92
+ function hapPlugin() {
93
+ return {
94
+ pluginId: CommonConstants_1.default.HAP_PLUGIN_ID,
95
+ apply(node) {
96
+ if (!HMRouterPluginMgrInstance) {
97
+ HMRouterPluginMgrInstance = new HMRouterPluginMgr();
98
+ }
99
+ HMRouterPluginMgrInstance.registerHMRouterPlugin(node, hvigor_ohos_plugin_1.OhosPluginId.OHOS_HAP_PLUGIN);
100
+ }
101
+ };
102
+ }
103
+ function hspPlugin() {
104
+ return {
105
+ pluginId: CommonConstants_1.default.HSP_PLUGIN_ID,
106
+ apply(node) {
107
+ if (!HMRouterPluginMgrInstance) {
108
+ HMRouterPluginMgrInstance = new HMRouterPluginMgr();
109
+ }
110
+ HMRouterPluginMgrInstance.registerHMRouterPlugin(node, hvigor_ohos_plugin_1.OhosPluginId.OHOS_HSP_PLUGIN);
111
+ }
112
+ };
113
+ }
114
+ function harPlugin() {
115
+ return {
116
+ pluginId: CommonConstants_1.default.HAR_PLUGIN_ID,
117
+ apply(node) {
118
+ if (!HMRouterPluginMgrInstance) {
119
+ HMRouterPluginMgrInstance = new HMRouterPluginMgr();
120
+ }
121
+ HMRouterPluginMgrInstance.registerHMRouterPlugin(node, hvigor_ohos_plugin_1.OhosPluginId.OHOS_HAR_PLUGIN);
122
+ }
123
+ };
124
+ }
@@ -0,0 +1,27 @@
1
+ export declare class HMRouterPluginConstant {
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 PAGE_URL_PREFIX = "";
7
+ static readonly FILE_SEPARATOR: "\\" | "/";
8
+ static readonly DELIMITER = "/";
9
+ static readonly MODULE_ROUTER_MAP_NAME = "$profile:hm_router_map";
10
+ static readonly ROUTER_MAP_NAME = "hm_router_map.json";
11
+ static readonly TEMP_ROUTER_MAP_PATH = "../../intermediates/router_map";
12
+ static readonly RAWFILE_DIR = "src/main/resources/rawfile/hm_router_map.json";
13
+ static readonly VIEW_NAME_PREFIX = "HM";
14
+ static readonly VIEW_NAME_SUFFIX = ".ets";
15
+ static readonly JSON_SUFFIX = ".json";
16
+ static readonly HAP_PLUGIN_ID = "HAP_HMROUTER_PLUGIN";
17
+ static readonly HSP_PLUGIN_ID = "HSP_HMROUTER_PLUGIN";
18
+ static readonly HAR_PLUGIN_ID = "HAR_HMROUTER_PLUGIN";
19
+ static readonly ROUTER_ANNOTATION = "HMRouter";
20
+ static readonly ANIMATOR_ANNOTATION = "HMAnimator";
21
+ static readonly INTERCEPTOR_ANNOTATION = "HMInterceptor";
22
+ static readonly LIFECYCLE_ANNOTATION = "HMLifecycle";
23
+ static readonly SERVICE_ANNOTATION = "HMService";
24
+ static readonly CLASS_ANNOTATION_ARR: string[];
25
+ static readonly CONFIG_FILE_NAME = "hmrouter_config.json";
26
+ static readonly PARENT_DELIMITER = "../";
27
+ }
@@ -0,0 +1,35 @@
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.HMRouterPluginConstant = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ class HMRouterPluginConstant {
9
+ }
10
+ exports.HMRouterPluginConstant = HMRouterPluginConstant;
11
+ HMRouterPluginConstant.ANIMATOR_PREFIX = '__animator__';
12
+ HMRouterPluginConstant.INTERCEPTOR_PREFIX = '__interceptor__';
13
+ HMRouterPluginConstant.LIFECYCLE_PREFIX = '__lifecycle__';
14
+ HMRouterPluginConstant.SERVICE_PREFIX = '__service__';
15
+ HMRouterPluginConstant.PAGE_URL_PREFIX = '';
16
+ HMRouterPluginConstant.FILE_SEPARATOR = path_1.default.sep;
17
+ HMRouterPluginConstant.DELIMITER = '/';
18
+ HMRouterPluginConstant.MODULE_ROUTER_MAP_NAME = '$profile:hm_router_map';
19
+ HMRouterPluginConstant.ROUTER_MAP_NAME = 'hm_router_map.json';
20
+ HMRouterPluginConstant.TEMP_ROUTER_MAP_PATH = '../../intermediates/router_map';
21
+ HMRouterPluginConstant.RAWFILE_DIR = 'src/main/resources/rawfile/hm_router_map.json';
22
+ HMRouterPluginConstant.VIEW_NAME_PREFIX = 'HM';
23
+ HMRouterPluginConstant.VIEW_NAME_SUFFIX = '.ets';
24
+ HMRouterPluginConstant.JSON_SUFFIX = '.json';
25
+ HMRouterPluginConstant.HAP_PLUGIN_ID = 'HAP_HMROUTER_PLUGIN';
26
+ HMRouterPluginConstant.HSP_PLUGIN_ID = 'HSP_HMROUTER_PLUGIN';
27
+ HMRouterPluginConstant.HAR_PLUGIN_ID = 'HAR_HMROUTER_PLUGIN';
28
+ HMRouterPluginConstant.ROUTER_ANNOTATION = 'HMRouter';
29
+ HMRouterPluginConstant.ANIMATOR_ANNOTATION = 'HMAnimator';
30
+ HMRouterPluginConstant.INTERCEPTOR_ANNOTATION = 'HMInterceptor';
31
+ HMRouterPluginConstant.LIFECYCLE_ANNOTATION = 'HMLifecycle';
32
+ HMRouterPluginConstant.SERVICE_ANNOTATION = 'HMService';
33
+ HMRouterPluginConstant.CLASS_ANNOTATION_ARR = ['HMAnimator', 'HMInterceptor', 'HMLifecycle'];
34
+ HMRouterPluginConstant.CONFIG_FILE_NAME = 'hmrouter_config.json';
35
+ HMRouterPluginConstant.PARENT_DELIMITER = '../';
@@ -0,0 +1,13 @@
1
+ export declare class Logger {
2
+ static error(format: string, ...args: string[]): void;
3
+ static info(msg: string, ...args: unknown[]): void;
4
+ static warn(msg: string, ...args: unknown[]): void;
5
+ }
6
+ export declare enum PluginError {
7
+ ERR_DUPLICATE_NAME = "ERR_DUPLICATE_NAME",
8
+ ERR_WRONG_DECORATION = "ERR_DUPLICATE_",
9
+ ERR_REPEAT_ANNOTATION = "ERR_INIT_FRAMEWORK",
10
+ ERR_ERROR_CONFIG = "ERR_INIT_COMPONENT",
11
+ ERR_NOT_EMPTY_STRING = "ERR_INIT_NOT_READY",
12
+ ERR_INVALID_STRING_VALUE = "ERR_INVALID_STRING_VALUE"
13
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PluginError = exports.Logger = void 0;
4
+ const hvigor_1 = require("@ohos/hvigor");
5
+ class Logger {
6
+ static error(format, ...args) {
7
+ let formatStr = format;
8
+ if (DEFINED_ERROR.has(format)) {
9
+ formatStr = `errorCode ${DEFINED_ERROR.get(format)?.errorCode}, errorMsg: ${DEFINED_ERROR.get(format)?.errorMsg}`;
10
+ }
11
+ const publicFormat = `[HMRouterPlugin] ERROR: ${formatStr.replace('%s', args[0])}`;
12
+ hvigor_1.HvigorLogger.getLogger().error(publicFormat);
13
+ }
14
+ static info(msg, ...args) {
15
+ hvigor_1.HvigorLogger.getLogger().info('[HMRouterPlugin] ' + msg, ...args);
16
+ }
17
+ static warn(msg, ...args) {
18
+ hvigor_1.HvigorLogger.getLogger().warn('[HMRouterPlugin] ' + msg, ...args);
19
+ }
20
+ }
21
+ exports.Logger = Logger;
22
+ var PluginError;
23
+ (function (PluginError) {
24
+ PluginError["ERR_DUPLICATE_NAME"] = "ERR_DUPLICATE_NAME";
25
+ PluginError["ERR_WRONG_DECORATION"] = "ERR_DUPLICATE_";
26
+ PluginError["ERR_REPEAT_ANNOTATION"] = "ERR_INIT_FRAMEWORK";
27
+ PluginError["ERR_ERROR_CONFIG"] = "ERR_INIT_COMPONENT";
28
+ PluginError["ERR_NOT_EMPTY_STRING"] = "ERR_INIT_NOT_READY";
29
+ PluginError["ERR_INVALID_STRING_VALUE"] = "ERR_INVALID_STRING_VALUE";
30
+ })(PluginError || (exports.PluginError = PluginError = {}));
31
+ const DEFINED_ERROR = new Map();
32
+ DEFINED_ERROR.set(PluginError.ERR_DUPLICATE_NAME, {
33
+ errorCode: 40000001,
34
+ errorMsg: 'Duplicate pageUrl/interceptor/service/animator/lifecycle - %s'
35
+ });
36
+ DEFINED_ERROR.set(PluginError.ERR_WRONG_DECORATION, {
37
+ errorCode: 40000002,
38
+ errorMsg: 'Struct with @HMRouter annotation could not contain NavDestination component - %s'
39
+ });
40
+ DEFINED_ERROR.set(PluginError.ERR_REPEAT_ANNOTATION, {
41
+ errorCode: 40000003,
42
+ errorMsg: 'File: %s contains multiple annotations'
43
+ });
44
+ DEFINED_ERROR.set(PluginError.ERR_ERROR_CONFIG, {
45
+ errorCode: 40000004,
46
+ errorMsg: 'moduleContext is null, Please check hvigorfile.ts file in module directory - %s'
47
+ });
48
+ DEFINED_ERROR.set(PluginError.ERR_NOT_EMPTY_STRING, {
49
+ errorCode: 40000005,
50
+ errorMsg: '%s constant value cannot be empty string - %s'
51
+ });
52
+ DEFINED_ERROR.set(PluginError.ERR_INVALID_STRING_VALUE, {
53
+ errorCode: 40000006,
54
+ errorMsg: 'invalid string value: %s'
55
+ });
@@ -0,0 +1,50 @@
1
+ export type AnalyzerResultLike = HMRouterResult | HMAnimatorResult | HMInterceptorResult | HMLifecycleResult | HMServiceResult;
2
+ export interface BaseAnalyzeResult {
3
+ name?: string;
4
+ module?: string;
5
+ annotation?: string;
6
+ pageSourceFile?: string;
7
+ isDefaultExport?: boolean;
8
+ }
9
+ export interface HMRouterResult extends BaseAnalyzeResult {
10
+ pageUrl?: any;
11
+ dialog?: boolean;
12
+ singleton?: boolean;
13
+ interceptors?: string[];
14
+ animator?: string;
15
+ lifecycle?: string;
16
+ }
17
+ export interface HMAnimatorResult extends BaseAnalyzeResult {
18
+ animatorName?: string;
19
+ }
20
+ export interface HMInterceptorResult extends BaseAnalyzeResult {
21
+ interceptorName?: string;
22
+ priority?: number;
23
+ global?: boolean;
24
+ }
25
+ export interface HMLifecycleResult extends BaseAnalyzeResult {
26
+ lifecycleName?: string;
27
+ priority?: number;
28
+ global?: boolean;
29
+ }
30
+ export interface HMServiceResult extends BaseAnalyzeResult {
31
+ serviceName?: string;
32
+ functionName?: string;
33
+ singleton?: boolean;
34
+ }
35
+ export declare class TemplateModel {
36
+ pageUrl: string;
37
+ importPath: string;
38
+ componentName: string;
39
+ dialog: boolean;
40
+ generatorViewName: string;
41
+ isDefaultExport?: boolean;
42
+ constructor(pageUrl: string, importPath: string, componentName: string, dialog: boolean, generatorViewName: string, isDefaultExport?: boolean);
43
+ }
44
+ export declare class RouterInfo {
45
+ name: string;
46
+ pageSourceFile: string;
47
+ buildFunction: string;
48
+ customData: AnalyzerResultLike;
49
+ constructor(name: string, pageSourceFile: string, buildFunction: string, data?: AnalyzerResultLike);
50
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RouterInfo = exports.TemplateModel = void 0;
4
+ class TemplateModel {
5
+ constructor(pageUrl, importPath, componentName, dialog, generatorViewName, isDefaultExport) {
6
+ this.isDefaultExport = isDefaultExport;
7
+ this.pageUrl = pageUrl;
8
+ this.importPath = importPath;
9
+ this.componentName = componentName;
10
+ this.dialog = dialog;
11
+ this.generatorViewName = generatorViewName;
12
+ }
13
+ }
14
+ exports.TemplateModel = TemplateModel;
15
+ class RouterInfo {
16
+ constructor(name, pageSourceFile, buildFunction, data = {}) {
17
+ this.name = name;
18
+ this.pageSourceFile = pageSourceFile;
19
+ this.buildFunction = buildFunction;
20
+ this.customData = data;
21
+ }
22
+ }
23
+ exports.RouterInfo = RouterInfo;
@@ -0,0 +1,39 @@
1
+ export default class HMRouterPluginConstant {
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 PAGE_URL_PREFIX = "";
7
+ static readonly OBFUSCATION_FILE_NAME = "hmrouter-obfuscation-rules.txt";
8
+ static readonly CONSUMER_FILE_NAME = "hmrouter-consumer-rules.txt";
9
+ static readonly VARIABLE_SEPARATOR = "__";
10
+ static readonly PAGE_URL = "pageUrl";
11
+ static readonly ROUTER_MAP_KEY = "routerMap";
12
+ static readonly FILE_SEPARATOR: "\\" | "/";
13
+ static readonly DELIMITER = "/";
14
+ static readonly MODULE_ROUTER_MAP_NAME = "$profile:hm_router_map";
15
+ static readonly ROUTER_MAP_NAME = "hm_router_map.json";
16
+ static readonly TEMP_ROUTER_MAP_PATH = "../../intermediates/router_map";
17
+ static readonly RAWFILE_DIR = "src/main/resources/rawfile/hm_router_map.json";
18
+ static readonly VIEW_NAME_PREFIX = "HM";
19
+ static readonly ETS_SUFFIX = ".ets";
20
+ static readonly JSON_SUFFIX = ".json";
21
+ static readonly HAP_PLUGIN_ID = "HAP_HMROUTER_PLUGIN";
22
+ static readonly HSP_PLUGIN_ID = "HSP_HMROUTER_PLUGIN";
23
+ static readonly HAR_PLUGIN_ID = "HAR_HMROUTER_PLUGIN";
24
+ static readonly HAR_MODULE_NAME = "har";
25
+ static readonly ROUTER_ANNOTATION = "HMRouter";
26
+ static readonly ANIMATOR_ANNOTATION = "HMAnimator";
27
+ static readonly INTERCEPTOR_ANNOTATION = "HMInterceptor";
28
+ static readonly LIFECYCLE_ANNOTATION = "HMLifecycle";
29
+ static readonly SERVICE_ANNOTATION = "HMService";
30
+ static readonly CONFIG_FILE_NAME = "hmrouter_config.json";
31
+ static readonly PARENT_DELIMITER = "../";
32
+ static readonly CURRENT_DELIMITER = "./";
33
+ static readonly LINE_BREAK = "\n";
34
+ static readonly KEEP_FILE_NAME = "-keep-file-name";
35
+ static readonly KEEP_PROPERTY_NAME = "-keep-property-name";
36
+ static readonly KEEP_GLOBAL_NAME = "-keep-global-name";
37
+ static readonly OH_MODULE_PATH = "oh_modules";
38
+ static readonly WARP_BUILDER = "WrapBuilder";
39
+ }
@@ -0,0 +1,46 @@
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 HMRouterPluginConstant {
8
+ }
9
+ HMRouterPluginConstant.ANIMATOR_PREFIX = '__animator__';
10
+ HMRouterPluginConstant.INTERCEPTOR_PREFIX = '__interceptor__';
11
+ HMRouterPluginConstant.LIFECYCLE_PREFIX = '__lifecycle__';
12
+ HMRouterPluginConstant.SERVICE_PREFIX = '__service__';
13
+ HMRouterPluginConstant.PAGE_URL_PREFIX = '';
14
+ HMRouterPluginConstant.OBFUSCATION_FILE_NAME = 'hmrouter-obfuscation-rules.txt';
15
+ HMRouterPluginConstant.CONSUMER_FILE_NAME = 'hmrouter-consumer-rules.txt';
16
+ HMRouterPluginConstant.VARIABLE_SEPARATOR = '__';
17
+ HMRouterPluginConstant.PAGE_URL = 'pageUrl';
18
+ HMRouterPluginConstant.ROUTER_MAP_KEY = 'routerMap';
19
+ HMRouterPluginConstant.FILE_SEPARATOR = path_1.default.sep;
20
+ HMRouterPluginConstant.DELIMITER = '/';
21
+ HMRouterPluginConstant.MODULE_ROUTER_MAP_NAME = '$profile:hm_router_map';
22
+ HMRouterPluginConstant.ROUTER_MAP_NAME = 'hm_router_map.json';
23
+ HMRouterPluginConstant.TEMP_ROUTER_MAP_PATH = '../../intermediates/router_map';
24
+ HMRouterPluginConstant.RAWFILE_DIR = 'src/main/resources/rawfile/hm_router_map.json';
25
+ HMRouterPluginConstant.VIEW_NAME_PREFIX = 'HM';
26
+ HMRouterPluginConstant.ETS_SUFFIX = '.ets';
27
+ HMRouterPluginConstant.JSON_SUFFIX = '.json';
28
+ HMRouterPluginConstant.HAP_PLUGIN_ID = 'HAP_HMROUTER_PLUGIN';
29
+ HMRouterPluginConstant.HSP_PLUGIN_ID = 'HSP_HMROUTER_PLUGIN';
30
+ HMRouterPluginConstant.HAR_PLUGIN_ID = 'HAR_HMROUTER_PLUGIN';
31
+ HMRouterPluginConstant.HAR_MODULE_NAME = 'har';
32
+ HMRouterPluginConstant.ROUTER_ANNOTATION = 'HMRouter';
33
+ HMRouterPluginConstant.ANIMATOR_ANNOTATION = 'HMAnimator';
34
+ HMRouterPluginConstant.INTERCEPTOR_ANNOTATION = 'HMInterceptor';
35
+ HMRouterPluginConstant.LIFECYCLE_ANNOTATION = 'HMLifecycle';
36
+ HMRouterPluginConstant.SERVICE_ANNOTATION = 'HMService';
37
+ HMRouterPluginConstant.CONFIG_FILE_NAME = 'hmrouter_config.json';
38
+ HMRouterPluginConstant.PARENT_DELIMITER = '../';
39
+ HMRouterPluginConstant.CURRENT_DELIMITER = './';
40
+ HMRouterPluginConstant.LINE_BREAK = '\n';
41
+ HMRouterPluginConstant.KEEP_FILE_NAME = '-keep-file-name';
42
+ HMRouterPluginConstant.KEEP_PROPERTY_NAME = '-keep-property-name';
43
+ HMRouterPluginConstant.KEEP_GLOBAL_NAME = '-keep-global-name';
44
+ HMRouterPluginConstant.OH_MODULE_PATH = 'oh_modules';
45
+ HMRouterPluginConstant.WARP_BUILDER = 'WrapBuilder';
46
+ exports.default = HMRouterPluginConstant;