@hadss/hmrouter-plugin 1.0.0-rc.9 → 1.1.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -77
- package/NOTICE +1365 -0
- package/README.md +254 -71
- package/dist/HMRouterAnalyzer.d.ts +24 -1
- package/dist/HMRouterAnalyzer.js +154 -55
- package/dist/HMRouterHvigorPlugin.js +23 -4
- package/dist/HMRouterPluginConfig.d.ts +1 -0
- package/dist/HMRouterPluginConfig.js +7 -3
- package/dist/HMRouterPluginHandle.d.ts +1 -0
- package/dist/HMRouterPluginHandle.js +81 -55
- package/dist/HMRouterPluginManager.d.ts +9 -0
- package/dist/HMRouterPluginManager.js +55 -0
- package/dist/Index.d.ts +9 -3
- package/dist/Index.js +33 -103
- package/dist/common/Logger.js +1 -1
- package/dist/common/PluginModel.d.ts +4 -1
- package/dist/common/PluginModel.js +2 -1
- package/dist/constants/CommonConstants.d.ts +10 -5
- package/dist/constants/CommonConstants.js +11 -6
- package/dist/constants/ConfigConstants.d.ts +2 -1
- package/dist/constants/ConfigConstants.js +3 -2
- package/dist/constants/TaskConstants.js +1 -1
- package/dist/framework/constants/TaskConstants.d.ts +8 -0
- package/dist/framework/constants/TaskConstants.js +12 -0
- package/dist/framework/constants/index.d.ts +1 -0
- package/dist/framework/constants/index.js +17 -0
- package/dist/framework/core/PluginExecutionController.d.ts +15 -0
- package/dist/framework/core/PluginExecutionController.js +62 -0
- package/dist/framework/core/TaskManager.d.ts +12 -0
- package/dist/framework/core/TaskManager.js +67 -0
- package/dist/framework/core/TaskStage.d.ts +10 -0
- package/dist/framework/core/TaskStage.js +14 -0
- package/dist/framework/core/index.d.ts +3 -0
- package/dist/framework/core/index.js +19 -0
- package/dist/framework/extension/ExtensionManager.d.ts +11 -0
- package/dist/framework/extension/ExtensionManager.js +33 -0
- package/dist/framework/extension/PluginExtension.d.ts +13 -0
- package/dist/framework/extension/PluginExtension.js +6 -0
- package/dist/framework/extension/context/ExtensionContextImpl.d.ts +23 -0
- package/dist/framework/extension/context/ExtensionContextImpl.js +64 -0
- package/dist/framework/extension/context/Interface.d.ts +21 -0
- package/dist/framework/extension/context/Interface.js +2 -0
- package/dist/framework/extension/context/TemplateMetadataImpl.d.ts +12 -0
- package/dist/framework/extension/context/TemplateMetadataImpl.js +22 -0
- package/dist/framework/extension/index.d.ts +4 -0
- package/dist/framework/extension/index.js +20 -0
- package/dist/framework/index.d.ts +4 -0
- package/dist/framework/index.js +20 -0
- package/dist/framework/utils/FileUtil.d.ts +13 -0
- package/dist/framework/utils/FileUtil.js +20 -0
- package/dist/framework/utils/Logger.d.ts +12 -0
- package/dist/framework/utils/Logger.js +31 -0
- package/dist/framework/utils/ModuleTypeUtil.d.ts +4 -0
- package/dist/framework/utils/ModuleTypeUtil.js +16 -0
- package/dist/framework/utils/ObjectUtils.d.ts +3 -0
- package/dist/framework/utils/ObjectUtils.js +14 -0
- package/dist/framework/utils/PluginStore.d.ts +10 -0
- package/dist/framework/utils/PluginStore.js +29 -0
- package/dist/framework/utils/StringUtil.d.ts +3 -0
- package/dist/framework/utils/StringUtil.js +18 -0
- package/dist/framework/utils/TsAstUtil.d.ts +6 -0
- package/dist/framework/utils/TsAstUtil.js +19 -0
- package/dist/framework/utils/index.d.ts +7 -0
- package/dist/framework/utils/index.js +23 -0
- package/dist/hmrouter_extension/HMRouterExtension.d.ts +14 -0
- package/dist/hmrouter_extension/HMRouterExtension.js +47 -0
- package/dist/hmrouter_extension/HMRouterExtensionContext.d.ts +8 -0
- package/dist/hmrouter_extension/HMRouterExtensionContext.js +2 -0
- package/dist/hmrouter_extension/analyzer/AnnotationAnalyzerRegistry.d.ts +14 -0
- package/dist/hmrouter_extension/analyzer/AnnotationAnalyzerRegistry.js +45 -0
- package/dist/hmrouter_extension/analyzer/ComponentAnalyzer.d.ts +12 -0
- package/dist/hmrouter_extension/analyzer/ComponentAnalyzer.js +52 -0
- package/dist/hmrouter_extension/analyzer/RouterAnalyzer.d.ts +11 -0
- package/dist/hmrouter_extension/analyzer/RouterAnalyzer.js +79 -0
- package/dist/hmrouter_extension/analyzer/interface/AbstractAnnotationAnalyzer.d.ts +9 -0
- package/dist/hmrouter_extension/analyzer/interface/AbstractAnnotationAnalyzer.js +9 -0
- package/dist/hmrouter_extension/analyzer/interface/IConstantResolver.d.ts +7 -0
- package/dist/hmrouter_extension/analyzer/interface/IConstantResolver.js +2 -0
- package/dist/hmrouter_extension/analyzer/utils/ConstantAnalyzer.d.ts +9 -0
- package/dist/hmrouter_extension/analyzer/utils/ConstantAnalyzer.js +32 -0
- package/dist/hmrouter_extension/analyzer/utils/ConstantResolver.d.ts +15 -0
- package/dist/hmrouter_extension/analyzer/utils/ConstantResolver.js +217 -0
- package/dist/hmrouter_extension/analyzer/utils/DecoratorParser.d.ts +7 -0
- package/dist/hmrouter_extension/analyzer/utils/DecoratorParser.js +41 -0
- package/dist/hmrouter_extension/analyzer/utils/ImportAnalyzer.d.ts +4 -0
- package/dist/hmrouter_extension/analyzer/utils/ImportAnalyzer.js +35 -0
- package/dist/hmrouter_extension/config/HMRouterPluginConfig.d.ts +38 -0
- package/dist/hmrouter_extension/config/HMRouterPluginConfig.js +64 -0
- package/dist/hmrouter_extension/constants/AnnotationConstants.d.ts +8 -0
- package/dist/hmrouter_extension/constants/AnnotationConstants.js +11 -0
- package/dist/hmrouter_extension/constants/FilePathConstants.d.ts +19 -0
- package/dist/hmrouter_extension/constants/FilePathConstants.js +26 -0
- package/dist/hmrouter_extension/constants/ObfuscationConstants.d.ts +5 -0
- package/dist/hmrouter_extension/constants/ObfuscationConstants.js +8 -0
- package/dist/hmrouter_extension/constants/PluginConstants.d.ts +6 -0
- package/dist/hmrouter_extension/constants/PluginConstants.js +9 -0
- package/dist/hmrouter_extension/constants/PrefixConstants.d.ts +8 -0
- package/dist/hmrouter_extension/constants/PrefixConstants.js +11 -0
- package/dist/hmrouter_extension/constants/RouterMapConstants.d.ts +5 -0
- package/dist/hmrouter_extension/constants/RouterMapConstants.js +8 -0
- package/dist/hmrouter_extension/constants/TemplateConstants.d.ts +6 -0
- package/dist/hmrouter_extension/constants/TemplateConstants.js +9 -0
- package/dist/hmrouter_extension/constants/VersionConstants.d.ts +6 -0
- package/dist/hmrouter_extension/constants/VersionConstants.js +9 -0
- package/dist/hmrouter_extension/constants/index.d.ts +8 -0
- package/dist/hmrouter_extension/constants/index.js +22 -0
- package/dist/hmrouter_extension/error/PluginError.d.ts +29 -0
- package/dist/hmrouter_extension/error/PluginError.js +75 -0
- package/dist/hmrouter_extension/model/HMAnnotationModel.d.ts +28 -0
- package/dist/hmrouter_extension/model/HMAnnotationModel.js +2 -0
- package/dist/hmrouter_extension/model/RouterInfo.d.ts +6 -0
- package/dist/hmrouter_extension/model/RouterInfo.js +2 -0
- package/dist/hmrouter_extension/model/TemplateModel.d.ts +8 -0
- package/dist/hmrouter_extension/model/TemplateModel.js +2 -0
- package/dist/hmrouter_extension/model/index.d.ts +3 -0
- package/dist/hmrouter_extension/model/index.js +19 -0
- package/dist/hmrouter_extension/processor/CodeGenerationProcessor.d.ts +13 -0
- package/dist/hmrouter_extension/processor/CodeGenerationProcessor.js +117 -0
- package/dist/hmrouter_extension/processor/CompletionProcessor.d.ts +11 -0
- package/dist/hmrouter_extension/processor/CompletionProcessor.js +59 -0
- package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.d.ts +11 -0
- package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.js +53 -0
- package/dist/hmrouter_extension/processor/InitializerProcessor.d.ts +15 -0
- package/dist/hmrouter_extension/processor/InitializerProcessor.js +95 -0
- package/dist/hmrouter_extension/processor/ObfuscationProcessor.d.ts +13 -0
- package/dist/hmrouter_extension/processor/ObfuscationProcessor.js +121 -0
- package/dist/hmrouter_extension/processor/ResourceProcessor.d.ts +9 -0
- package/dist/hmrouter_extension/processor/ResourceProcessor.js +53 -0
- package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.d.ts +9 -0
- package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.js +122 -0
- package/dist/hmrouter_extension/processor/index.d.ts +7 -0
- package/dist/hmrouter_extension/processor/index.js +23 -0
- package/dist/store/PluginStore.d.ts +14 -0
- package/dist/store/PluginStore.js +20 -0
- package/dist/utils/FileUtil.d.ts +2 -0
- package/dist/utils/ObfuscationUtil.js +7 -1
- package/dist/utils/TsAstUtil.d.ts +3 -2
- package/dist/utils/TsAstUtil.js +51 -11
- package/examples/CustomExtension.ts +256 -0
- package/package.json +8 -7
- package/template/customBuilder.ejs +25 -0
- package/template/viewBuilder.ejs +51 -0
- package/{viewBuilder.ejs → template/viewBuilder_v1.ejs} +11 -4
- package/dist/common/Constant.d.ts +0 -27
- package/dist/common/Constant.js +0 -35
- package/dist/utils/ConfusionUtil.d.ts +0 -4
- package/dist/utils/ConfusionUtil.js +0 -27
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObfuscationProcessor = void 0;
|
|
4
|
+
const framework_1 = require("../../framework");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
class ObfuscationProcessor {
|
|
7
|
+
constructor(context) {
|
|
8
|
+
this.context = context;
|
|
9
|
+
}
|
|
10
|
+
execute() {
|
|
11
|
+
framework_1.Logger.debug(this.context.node.getNodeName(), `Start to obfuscation...`);
|
|
12
|
+
if (!this.checkObfuscationEnabled()) {
|
|
13
|
+
framework_1.Logger.info(this.context.node.getNodeName(), 'This compilation does not turn on code obfuscation, skip hmrouter_obfuscation_rules.txt file generation');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const obfuscationString = this.generateObfuscationRuleFile();
|
|
17
|
+
this.handleHarPackageLogic(obfuscationString);
|
|
18
|
+
}
|
|
19
|
+
checkObfuscationEnabled() {
|
|
20
|
+
return this.isEnableObfuscation();
|
|
21
|
+
}
|
|
22
|
+
generateObfuscationRuleFile() {
|
|
23
|
+
const obfuscationFilePath = framework_1.PluginFileUtil.pathResolve(this.context.config.modulePath, constants_1.FilePathConstants.OBFUSCATION_FILE_NAME);
|
|
24
|
+
const routerMap = JSON.parse(framework_1.PluginFileUtil.readFileSync(this.context.config.getRouterMapDir()).toString()).routerMap;
|
|
25
|
+
const obfuscationString = this.buildObfuscatedStrings(routerMap);
|
|
26
|
+
framework_1.PluginFileUtil.ensureFileSync(obfuscationFilePath);
|
|
27
|
+
framework_1.PluginFileUtil.writeFileSync(obfuscationFilePath, obfuscationString);
|
|
28
|
+
framework_1.Logger.info(this.context.node.getNodeName(), `Generate obfuscation rule file successfully, filePath: ${obfuscationFilePath}`);
|
|
29
|
+
return obfuscationString;
|
|
30
|
+
}
|
|
31
|
+
handleHarPackageLogic(obfuscationString) {
|
|
32
|
+
if (this.context.moduleContext.getModuleType() === constants_1.PluginConstants.HAR_MODULE_NAME) {
|
|
33
|
+
const consumerRulesPath = framework_1.PluginFileUtil.pathResolve(this.context.config.modulePath, constants_1.FilePathConstants.CONSUMER_FILE_NAME);
|
|
34
|
+
framework_1.PluginFileUtil.ensureFileSync(consumerRulesPath);
|
|
35
|
+
framework_1.PluginFileUtil.writeFileSync(consumerRulesPath, obfuscationString);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
isEnableObfuscation() {
|
|
39
|
+
const currentBuildMode = framework_1.PluginStore.getInstance().get('buildMode');
|
|
40
|
+
const buildOption = this.context.moduleContext
|
|
41
|
+
?.getBuildProfileOpt()
|
|
42
|
+
.buildOptionSet?.find((item) => item.name === currentBuildMode);
|
|
43
|
+
if (!buildOption) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const arkOptions = framework_1.ObjectUtils.ensureNestedObject(buildOption, ['arkOptions']);
|
|
47
|
+
const obfuscationOptions = framework_1.ObjectUtils.ensureNestedObject(arkOptions, ['obfuscation']);
|
|
48
|
+
const ruleOptions = framework_1.ObjectUtils.ensureNestedObject(obfuscationOptions, ['ruleOptions']);
|
|
49
|
+
const isObfuscationEnabled = !!ruleOptions.enable;
|
|
50
|
+
if (!isObfuscationEnabled) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
if (this.context.config?.autoObfuscation) {
|
|
54
|
+
this.addHMRouterObfuscationRules(ruleOptions, obfuscationOptions);
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
addHMRouterObfuscationRules(ruleOptions, obfuscationOptions) {
|
|
59
|
+
const obfuscationFilePath = constants_1.FilePathConstants.CURRENT_DELIMITER + constants_1.FilePathConstants.OBFUSCATION_FILE_NAME;
|
|
60
|
+
ruleOptions.files = this.appendFilePathSafely(ruleOptions.files, obfuscationFilePath);
|
|
61
|
+
if (this.context.moduleContext.getModuleType() === constants_1.PluginConstants.HAR_MODULE_NAME) {
|
|
62
|
+
const consumerRulesPath = constants_1.FilePathConstants.CURRENT_DELIMITER + constants_1.FilePathConstants.CONSUMER_FILE_NAME;
|
|
63
|
+
obfuscationOptions.consumerFiles = this.appendFilePathSafely(obfuscationOptions.consumerFiles, consumerRulesPath);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
appendFilePathSafely(target, filePath) {
|
|
67
|
+
if (typeof target === 'string') {
|
|
68
|
+
return target === filePath ? [target] : [target, filePath];
|
|
69
|
+
}
|
|
70
|
+
else if (Array.isArray(target)) {
|
|
71
|
+
if (!target.includes(filePath)) {
|
|
72
|
+
target.push(filePath);
|
|
73
|
+
}
|
|
74
|
+
return target;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
return [filePath];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
buildObfuscatedStrings(routerMap) {
|
|
81
|
+
let srcPathArr = [
|
|
82
|
+
...new Set(routerMap.map((routerInfo) => {
|
|
83
|
+
return constants_1.FilePathConstants.CURRENT_DELIMITER + routerInfo.pageSourceFile;
|
|
84
|
+
})),
|
|
85
|
+
];
|
|
86
|
+
let classNameArr = [
|
|
87
|
+
...new Set(routerMap
|
|
88
|
+
.filter((routerInfo) => {
|
|
89
|
+
return routerInfo.name.includes('__');
|
|
90
|
+
})
|
|
91
|
+
.map((routerInfo) => {
|
|
92
|
+
return routerInfo.customData.className;
|
|
93
|
+
})),
|
|
94
|
+
];
|
|
95
|
+
let functionName = [
|
|
96
|
+
...new Set(routerMap
|
|
97
|
+
.filter((routerInfo) => {
|
|
98
|
+
return routerInfo.name.includes(constants_1.PrefixConstants.SERVICE_PREFIX);
|
|
99
|
+
})
|
|
100
|
+
.map((routerInfo) => {
|
|
101
|
+
return routerInfo.customData.functionName;
|
|
102
|
+
})),
|
|
103
|
+
];
|
|
104
|
+
let watchFunctionName = [
|
|
105
|
+
...new Set(routerMap
|
|
106
|
+
.filter((routerInfo) => {
|
|
107
|
+
return routerInfo.buildFunction;
|
|
108
|
+
})
|
|
109
|
+
.map((routerInfo) => {
|
|
110
|
+
return routerInfo.buildFunction + constants_1.TemplateConstants.WARP_BUILDER;
|
|
111
|
+
})),
|
|
112
|
+
];
|
|
113
|
+
return (constants_1.ObfuscationConstants.KEEP_FILE_NAME +
|
|
114
|
+
constants_1.FilePathConstants.LINE_BREAK +
|
|
115
|
+
srcPathArr
|
|
116
|
+
.concat(constants_1.ObfuscationConstants.KEEP_PROPERTY_NAME, functionName)
|
|
117
|
+
.concat(constants_1.ObfuscationConstants.KEEP_GLOBAL_NAME, classNameArr, watchFunctionName)
|
|
118
|
+
.join(constants_1.FilePathConstants.LINE_BREAK));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.ObfuscationProcessor = ObfuscationProcessor;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { HMRouterExtensionContext } from '../HMRouterExtensionContext';
|
|
2
|
+
export declare class ResourceProcessProcessor {
|
|
3
|
+
private context;
|
|
4
|
+
constructor(context: HMRouterExtensionContext);
|
|
5
|
+
execute(): void;
|
|
6
|
+
private copyRouterMapToRawFile;
|
|
7
|
+
private processHspModuleName;
|
|
8
|
+
private getRemoteHspModuleNames;
|
|
9
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResourceProcessProcessor = void 0;
|
|
4
|
+
const framework_1 = require("../../framework");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
class ResourceProcessProcessor {
|
|
7
|
+
constructor(context) {
|
|
8
|
+
this.context = context;
|
|
9
|
+
}
|
|
10
|
+
execute() {
|
|
11
|
+
framework_1.Logger.debug(this.context.node.getNodeName(), `Start to copy router map to raw file...`);
|
|
12
|
+
this.copyRouterMapToRawFile();
|
|
13
|
+
this.processHspModuleName();
|
|
14
|
+
}
|
|
15
|
+
copyRouterMapToRawFile() {
|
|
16
|
+
let routerMapFilePath = framework_1.PluginFileUtil.pathResolve(this.context.currentTarget?.getBuildTargetOutputPath(), constants_1.FilePathConstants.TEMP_ROUTER_MAP_PATH, this.context.currentTarget?.getTargetName(), constants_1.RouterMapConstants.ROUTER_MAP_NAME);
|
|
17
|
+
let rawFilePath = this.context.config.getRawFilePath();
|
|
18
|
+
framework_1.PluginFileUtil.ensureFileSync(rawFilePath);
|
|
19
|
+
framework_1.PluginFileUtil.copyFileSync(routerMapFilePath, rawFilePath);
|
|
20
|
+
framework_1.Logger.info(this.context.node.getNodeName(), `Copy router map to raw file successfully, filePath: ${rawFilePath}`);
|
|
21
|
+
}
|
|
22
|
+
processHspModuleName() {
|
|
23
|
+
if (!(0, framework_1.isHapModule)(this.context.node)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
let rawFilePath = this.context.config.getRawFilePath();
|
|
27
|
+
let rawFileRouterMap = JSON.parse(framework_1.PluginFileUtil.readFileSync(rawFilePath).toString());
|
|
28
|
+
rawFileRouterMap.hspModuleNames = [...new Set(framework_1.PluginStore.getInstance().get('hspModuleNames'))];
|
|
29
|
+
rawFileRouterMap.hspModuleNames.push(...this.getRemoteHspModuleNames(this.context.node.getAllPluginIds()));
|
|
30
|
+
framework_1.PluginFileUtil.writeFileSync(rawFilePath, JSON.stringify(rawFileRouterMap));
|
|
31
|
+
}
|
|
32
|
+
getRemoteHspModuleNames(pluginIds) {
|
|
33
|
+
let remoteHspModuleNames = [];
|
|
34
|
+
try {
|
|
35
|
+
pluginIds.forEach((id) => {
|
|
36
|
+
let context = this.context.node.getContext(id);
|
|
37
|
+
let signedHspObj = context.getOhpmRemoteHspDependencyInfo(true);
|
|
38
|
+
let remoteHspObj = context.getOhpmRemoteHspDependencyInfo(false);
|
|
39
|
+
for (const key in signedHspObj) {
|
|
40
|
+
remoteHspModuleNames.push(signedHspObj[key].name);
|
|
41
|
+
}
|
|
42
|
+
for (const key in remoteHspObj) {
|
|
43
|
+
remoteHspModuleNames.push(remoteHspObj[key].name);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
framework_1.Logger.warn(this.context.node.getNodeName(), 'Your DevEco Studio version less than 5.0.3.800, may cause remote hsp dependencies get failed');
|
|
49
|
+
}
|
|
50
|
+
return remoteHspModuleNames;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.ResourceProcessProcessor = ResourceProcessProcessor;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { HMRouterExtensionContext } from '../HMRouterExtensionContext';
|
|
2
|
+
export declare class RouterMapBuildingProcessor {
|
|
3
|
+
private context;
|
|
4
|
+
constructor(context: HMRouterExtensionContext);
|
|
5
|
+
execute(): void;
|
|
6
|
+
private buildRouterMap;
|
|
7
|
+
private generateRouterMapFile;
|
|
8
|
+
private readExistingRouterMap;
|
|
9
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RouterMapBuildingProcessor = void 0;
|
|
4
|
+
const framework_1 = require("../../framework");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const AnnotationAnalyzerRegistry_1 = require("../analyzer/AnnotationAnalyzerRegistry");
|
|
7
|
+
const ConstantAnalyzer_1 = require("../analyzer/utils/ConstantAnalyzer");
|
|
8
|
+
const PluginError_1 = require("../error/PluginError");
|
|
9
|
+
class RouterMapBuildingProcessor {
|
|
10
|
+
constructor(context) {
|
|
11
|
+
this.context = context;
|
|
12
|
+
}
|
|
13
|
+
execute() {
|
|
14
|
+
framework_1.Logger.debug(this.context.node.getNodeName(), `Start to build router map...`);
|
|
15
|
+
this.readExistingRouterMap();
|
|
16
|
+
const constantResolver = AnnotationAnalyzerRegistry_1.AnnotationAnalyzerRegistry.getInstance().getConstantResolver();
|
|
17
|
+
const constantAnalyzer = new ConstantAnalyzer_1.ConstantAnalyzer(constantResolver);
|
|
18
|
+
constantAnalyzer.parseConstants(this.context.getAnalyzeResults());
|
|
19
|
+
for (const result of this.context.getAnalyzeResults()) {
|
|
20
|
+
this.buildRouterMap(result);
|
|
21
|
+
}
|
|
22
|
+
this.generateRouterMapFile();
|
|
23
|
+
}
|
|
24
|
+
buildRouterMap(result) {
|
|
25
|
+
if (!result.sourceFilePath) {
|
|
26
|
+
throw PluginError_1.PluginError.create(PluginError_1.ErrorCode.ERROR_PAGE_SOURCE_FILE, this.context.config.moduleName, result.sourceFilePath);
|
|
27
|
+
}
|
|
28
|
+
let pageSourceFile = this.context.config
|
|
29
|
+
.getRelativeSourcePath(result.sourceFilePath)
|
|
30
|
+
.replaceAll(constants_1.FilePathConstants.FILE_SEPARATOR, constants_1.FilePathConstants.DELIMITER);
|
|
31
|
+
if (result.annotation === constants_1.AnnotationConstants.ROUTER_ANNOTATION) {
|
|
32
|
+
let pageUrl = result.pageUrl;
|
|
33
|
+
let builderPath = this.context.generatedPaths.get(result.name) || '';
|
|
34
|
+
this.context.routerMap.push({
|
|
35
|
+
name: pageUrl,
|
|
36
|
+
pageSourceFile: builderPath,
|
|
37
|
+
buildFunction: result.name + 'Builder',
|
|
38
|
+
customData: result,
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const annotationConfig = {
|
|
43
|
+
[constants_1.AnnotationConstants.ANIMATOR_ANNOTATION]: {
|
|
44
|
+
prefix: constants_1.PrefixConstants.ANIMATOR_PREFIX,
|
|
45
|
+
propertyName: 'animatorName',
|
|
46
|
+
resultType: 'HMAnimatorResult',
|
|
47
|
+
},
|
|
48
|
+
[constants_1.AnnotationConstants.INTERCEPTOR_ANNOTATION]: {
|
|
49
|
+
prefix: constants_1.PrefixConstants.INTERCEPTOR_PREFIX,
|
|
50
|
+
propertyName: 'interceptorName',
|
|
51
|
+
resultType: 'HMInterceptorResult',
|
|
52
|
+
},
|
|
53
|
+
[constants_1.AnnotationConstants.LIFECYCLE_ANNOTATION]: {
|
|
54
|
+
prefix: constants_1.PrefixConstants.LIFECYCLE_PREFIX,
|
|
55
|
+
propertyName: 'lifecycleName',
|
|
56
|
+
resultType: 'HMLifecycleResult',
|
|
57
|
+
},
|
|
58
|
+
[constants_1.AnnotationConstants.SERVICE_ANNOTATION]: {
|
|
59
|
+
prefix: constants_1.PrefixConstants.SERVICE_PREFIX,
|
|
60
|
+
propertyName: 'serviceName',
|
|
61
|
+
resultType: 'HMServiceResult',
|
|
62
|
+
},
|
|
63
|
+
[constants_1.AnnotationConstants.SERVICE_PROVIDE_ANNOTATION]: {
|
|
64
|
+
prefix: constants_1.PrefixConstants.SERVICE_PROVIDE_PREFIX,
|
|
65
|
+
propertyName: 'serviceName',
|
|
66
|
+
resultType: 'HMServiceResult',
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
const config = annotationConfig[result.annotation];
|
|
70
|
+
const nameValue = result[config.propertyName];
|
|
71
|
+
const fullName = config.prefix + nameValue;
|
|
72
|
+
this.context.routerMap.push({
|
|
73
|
+
name: fullName,
|
|
74
|
+
pageSourceFile: pageSourceFile,
|
|
75
|
+
buildFunction: '',
|
|
76
|
+
customData: result,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
generateRouterMapFile() {
|
|
80
|
+
let set = new Set();
|
|
81
|
+
this.context.routerMap.forEach((item) => {
|
|
82
|
+
if (set.has(item.name)) {
|
|
83
|
+
throw PluginError_1.PluginError.create(PluginError_1.ErrorCode.DUPLICATE_NAME, this.context.config.moduleName, item.name);
|
|
84
|
+
}
|
|
85
|
+
set.add(item.name);
|
|
86
|
+
});
|
|
87
|
+
let routerMap = {
|
|
88
|
+
routerMap: this.context.routerMap.map((item) => {
|
|
89
|
+
if (item.customData && item.customData.annotation) {
|
|
90
|
+
delete item.customData.annotation;
|
|
91
|
+
delete item.customData.sourceFilePath;
|
|
92
|
+
delete item.customData.isDefaultExport;
|
|
93
|
+
delete item.customData.templateData;
|
|
94
|
+
}
|
|
95
|
+
return item;
|
|
96
|
+
}),
|
|
97
|
+
};
|
|
98
|
+
const routerMapJsonStr = JSON.stringify(routerMap, null, 2);
|
|
99
|
+
const routerMapFilePath = this.context.config.getRouterMapDir();
|
|
100
|
+
framework_1.PluginFileUtil.ensureFileSync(routerMapFilePath);
|
|
101
|
+
framework_1.PluginFileUtil.writeFileSync(routerMapFilePath, routerMapJsonStr);
|
|
102
|
+
framework_1.Logger.info(this.context.node.getNodeName(), `hm_router_map.json has been generated in ${routerMapFilePath}`);
|
|
103
|
+
}
|
|
104
|
+
readExistingRouterMap() {
|
|
105
|
+
const moduleJsonOpt = this.context.moduleContext.getModuleJsonOpt();
|
|
106
|
+
if (!moduleJsonOpt?.module.routerMap) {
|
|
107
|
+
framework_1.Logger.debug(this.context.node.getNodeName(), `No routerMap found in the module configuration`);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const routerMapFileName = moduleJsonOpt.module.routerMap.split(':')[1];
|
|
111
|
+
if (routerMapFileName !== 'hm_router_map') {
|
|
112
|
+
const routerMapFilePath = this.context.config.getModuleRouterMapFilePath(routerMapFileName);
|
|
113
|
+
const routerMapObj = framework_1.PluginFileUtil.readJson5(routerMapFilePath);
|
|
114
|
+
const systemRouterMap = routerMapObj[constants_1.RouterMapConstants.ROUTER_MAP_KEY];
|
|
115
|
+
if (systemRouterMap && systemRouterMap.length > 0) {
|
|
116
|
+
this.context.routerMap.unshift(...systemRouterMap);
|
|
117
|
+
framework_1.Logger.debug(this.context.node.getNodeName(), `System routerMap added to the current routerMap`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.RouterMapBuildingProcessor = RouterMapBuildingProcessor;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './CodeGenerationProcessor';
|
|
2
|
+
export * from './CompletionProcessor';
|
|
3
|
+
export * from './ConfigUpdateProcessor';
|
|
4
|
+
export * from './ObfuscationProcessor';
|
|
5
|
+
export * from './InitializerProcessor';
|
|
6
|
+
export * from './RouterMapBuildingProcessor';
|
|
7
|
+
export * from './ResourceProcessor';
|
|
@@ -0,0 +1,23 @@
|
|
|
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("./CodeGenerationProcessor"), exports);
|
|
18
|
+
__exportStar(require("./CompletionProcessor"), exports);
|
|
19
|
+
__exportStar(require("./ConfigUpdateProcessor"), exports);
|
|
20
|
+
__exportStar(require("./ObfuscationProcessor"), exports);
|
|
21
|
+
__exportStar(require("./InitializerProcessor"), exports);
|
|
22
|
+
__exportStar(require("./RouterMapBuildingProcessor"), exports);
|
|
23
|
+
__exportStar(require("./ResourceProcessor"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default class PluginStore implements IPluginStore {
|
|
2
|
+
private static instance;
|
|
3
|
+
variableCache: Map<string, Map<string, string[]>>;
|
|
4
|
+
projectFilePath: string;
|
|
5
|
+
hspModuleNames: string[];
|
|
6
|
+
static clear(): void;
|
|
7
|
+
static getInstance(): IPluginStore;
|
|
8
|
+
}
|
|
9
|
+
interface IPluginStore {
|
|
10
|
+
variableCache: Map<string, Map<string, string[]>>;
|
|
11
|
+
projectFilePath: string;
|
|
12
|
+
hspModuleNames: string[];
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class PluginStore {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.variableCache = new Map();
|
|
6
|
+
this.projectFilePath = '';
|
|
7
|
+
this.hspModuleNames = [];
|
|
8
|
+
}
|
|
9
|
+
static clear() {
|
|
10
|
+
this.instance = null;
|
|
11
|
+
}
|
|
12
|
+
static getInstance() {
|
|
13
|
+
if (!this.instance) {
|
|
14
|
+
this.instance = new PluginStore();
|
|
15
|
+
}
|
|
16
|
+
return this.instance;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.default = PluginStore;
|
|
20
|
+
PluginStore.instance = null;
|
package/dist/utils/FileUtil.d.ts
CHANGED
|
@@ -19,8 +19,14 @@ class ObfuscationUtil {
|
|
|
19
19
|
}).map((routerInfo) => {
|
|
20
20
|
return routerInfo.customData.functionName;
|
|
21
21
|
}))];
|
|
22
|
+
let watchFunctionName = [...new Set(routerMap.filter((routerInfo) => {
|
|
23
|
+
return routerInfo.buildFunction;
|
|
24
|
+
}).map((routerInfo) => {
|
|
25
|
+
return routerInfo.buildFunction + CommonConstants_1.default.WARP_BUILDER;
|
|
26
|
+
}))];
|
|
22
27
|
return CommonConstants_1.default.KEEP_FILE_NAME + CommonConstants_1.default.LINE_BREAK +
|
|
23
|
-
srcPathArr.concat(CommonConstants_1.default.KEEP_PROPERTY_NAME,
|
|
28
|
+
srcPathArr.concat(CommonConstants_1.default.KEEP_PROPERTY_NAME, functionName)
|
|
29
|
+
.concat(CommonConstants_1.default.KEEP_GLOBAL_NAME, classNameArr, watchFunctionName)
|
|
24
30
|
.join(CommonConstants_1.default.LINE_BREAK);
|
|
25
31
|
}
|
|
26
32
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Project, SourceFile } from 'ts-morph';
|
|
2
2
|
export declare let project: Project | null;
|
|
3
|
-
export declare const importVariableCache: Map<string, string>;
|
|
4
3
|
export declare class TsAstUtil {
|
|
5
|
-
static getSourceFile(filePath: string): SourceFile
|
|
4
|
+
static getSourceFile(filePath: string): SourceFile;
|
|
6
5
|
static clearProject(): void;
|
|
7
6
|
static parseConstantValue(sourceFile: SourceFile, variableName: string, propertyName?: string): string;
|
|
7
|
+
static parseCrossModuleVariable(scanDir: string): Map<string, string[]>;
|
|
8
|
+
private static getExportedVariables;
|
|
8
9
|
}
|
package/dist/utils/TsAstUtil.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TsAstUtil = exports.
|
|
3
|
+
exports.TsAstUtil = exports.project = void 0;
|
|
4
4
|
const ts_morph_1 = require("ts-morph");
|
|
5
5
|
const hvigor_1 = require("@ohos/hvigor");
|
|
6
6
|
const Logger_1 = require("../common/Logger");
|
|
7
7
|
exports.project = null;
|
|
8
|
-
exports.importVariableCache = new Map();
|
|
9
8
|
class TsAstUtil {
|
|
10
9
|
static getSourceFile(filePath) {
|
|
11
10
|
if (!hvigor_1.FileUtil.exist(filePath)) {
|
|
12
|
-
|
|
11
|
+
Logger_1.Logger.warn(`File not found: ${filePath}`);
|
|
12
|
+
const normalizedPath = filePath.replace(/\.+\/+/g, './');
|
|
13
|
+
if (normalizedPath !== filePath && hvigor_1.FileUtil.exist(normalizedPath)) {
|
|
14
|
+
Logger_1.Logger.info(`Using normalized path instead: ${normalizedPath}`);
|
|
15
|
+
filePath = normalizedPath;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
throw new Error(`File not found: ${filePath}`);
|
|
19
|
+
}
|
|
13
20
|
}
|
|
14
21
|
if (!exports.project) {
|
|
15
22
|
exports.project = new ts_morph_1.Project({
|
|
@@ -24,24 +31,24 @@ class TsAstUtil {
|
|
|
24
31
|
static parseConstantValue(sourceFile, variableName, propertyName) {
|
|
25
32
|
let result;
|
|
26
33
|
if (propertyName) {
|
|
27
|
-
let classInstance = sourceFile.getClasses().
|
|
34
|
+
let classInstance = sourceFile.getClasses().find((classes) => {
|
|
28
35
|
return classes.getName() === variableName;
|
|
29
36
|
});
|
|
30
|
-
if (classInstance
|
|
37
|
+
if (!classInstance) {
|
|
31
38
|
throw new Error(`Unknown class '${variableName}'`);
|
|
32
39
|
}
|
|
33
|
-
let property = classInstance
|
|
40
|
+
let property = classInstance.getProperties().find((properties) => {
|
|
34
41
|
return properties.getName() === propertyName;
|
|
35
42
|
});
|
|
36
|
-
if (property
|
|
43
|
+
if (!property) {
|
|
37
44
|
throw new Error(`Unknown property '${propertyName}'`);
|
|
38
45
|
}
|
|
39
|
-
result = property
|
|
46
|
+
result = property.getInitializer();
|
|
40
47
|
}
|
|
41
48
|
else {
|
|
42
|
-
let constant = sourceFile.getVariableDeclarations().
|
|
49
|
+
let constant = sourceFile.getVariableDeclarations().find(declaration => {
|
|
43
50
|
return declaration.getName() === variableName;
|
|
44
|
-
})
|
|
51
|
+
});
|
|
45
52
|
if (!constant) {
|
|
46
53
|
throw new Error(`Unknown constant '${variableName}'`);
|
|
47
54
|
}
|
|
@@ -49,9 +56,42 @@ class TsAstUtil {
|
|
|
49
56
|
}
|
|
50
57
|
if (result.getKind() !== ts_morph_1.SyntaxKind.StringLiteral) {
|
|
51
58
|
Logger_1.Logger.error(Logger_1.PluginError.ERR_INVALID_STRING_VALUE, variableName);
|
|
52
|
-
throw new Error('Invalid
|
|
59
|
+
throw new Error('Invalid constants value, only string literal is supported, variableName:' + variableName);
|
|
53
60
|
}
|
|
54
61
|
return result.asKind(ts_morph_1.SyntaxKind.StringLiteral)?.getLiteralValue();
|
|
55
62
|
}
|
|
63
|
+
static parseCrossModuleVariable(scanDir) {
|
|
64
|
+
let sourceFiles = exports.project.addSourceFilesAtPaths(`${scanDir}/**/*.ets`);
|
|
65
|
+
const exportMap = new Map();
|
|
66
|
+
for (let sourceFile of sourceFiles) {
|
|
67
|
+
const exportedNames = this.getExportedVariables(sourceFile);
|
|
68
|
+
if (exportedNames.length > 0) {
|
|
69
|
+
exportMap.set(sourceFile.getFilePath(), exportedNames);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return exportMap;
|
|
73
|
+
}
|
|
74
|
+
static getExportedVariables(sourceFile) {
|
|
75
|
+
const exportSymbols = [];
|
|
76
|
+
let exportKeywordNodes = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ExportKeyword);
|
|
77
|
+
exportKeywordNodes.forEach((node) => {
|
|
78
|
+
let parentNodeKind = node.getParent()?.getKind();
|
|
79
|
+
switch (parentNodeKind) {
|
|
80
|
+
case ts_morph_1.SyntaxKind.VariableStatement:
|
|
81
|
+
let variableStatement = node.getParent()?.asKind(ts_morph_1.SyntaxKind.VariableStatement);
|
|
82
|
+
let variableNames = variableStatement.getDeclarationList().getDeclarations().map((declaration) => {
|
|
83
|
+
return declaration.getName();
|
|
84
|
+
});
|
|
85
|
+
exportSymbols.push(...variableNames);
|
|
86
|
+
break;
|
|
87
|
+
case ts_morph_1.SyntaxKind.ClassDeclaration:
|
|
88
|
+
let classDeclaration = node.getParent();
|
|
89
|
+
let className = classDeclaration?.asKind(ts_morph_1.SyntaxKind.ClassDeclaration)?.getName();
|
|
90
|
+
exportSymbols.push(className);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
return exportSymbols;
|
|
95
|
+
}
|
|
56
96
|
}
|
|
57
97
|
exports.TsAstUtil = TsAstUtil;
|