@hadss/hmrouter-plugin 1.0.0-rc.1 → 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.
- package/README.md +240 -17
- package/dist/HMRouterAnalyzer.d.ts +31 -0
- package/dist/HMRouterAnalyzer.js +293 -0
- package/dist/HMRouterHvigorPlugin.d.ts +15 -0
- package/dist/HMRouterHvigorPlugin.js +139 -0
- package/dist/HMRouterPluginConfig.d.ts +39 -0
- package/dist/HMRouterPluginConfig.js +73 -0
- package/dist/HMRouterPluginHandle.d.ts +23 -0
- package/dist/HMRouterPluginHandle.js +231 -0
- package/dist/Index.d.ts +4 -0
- package/dist/Index.js +124 -0
- package/dist/common/Constant.d.ts +27 -0
- package/{lib → dist}/common/Constant.js +0 -15
- package/dist/common/Logger.d.ts +13 -0
- package/{lib → dist}/common/Logger.js +17 -24
- package/dist/common/PluginModel.d.ts +50 -0
- package/{lib → dist}/common/PluginModel.js +2 -16
- package/dist/constants/CommonConstants.d.ts +39 -0
- package/dist/constants/CommonConstants.js +46 -0
- package/dist/constants/ConfigConstants.d.ts +11 -0
- package/dist/constants/ConfigConstants.js +15 -0
- package/dist/constants/TaskConstants.d.ts +9 -0
- package/dist/constants/TaskConstants.js +13 -0
- package/dist/store/PluginStore.d.ts +12 -0
- package/dist/store/PluginStore.js +19 -0
- package/dist/utils/ConfusionUtil.d.ts +4 -0
- package/dist/utils/ConfusionUtil.js +27 -0
- package/dist/utils/FileUtil.d.ts +11 -0
- package/dist/utils/FileUtil.js +20 -0
- package/dist/utils/ObfuscationUtil.d.ts +4 -0
- package/dist/utils/ObfuscationUtil.js +34 -0
- package/dist/utils/StringUtil.d.ts +3 -0
- package/dist/utils/StringUtil.js +18 -0
- package/dist/utils/TsAstUtil.d.ts +9 -0
- package/dist/utils/TsAstUtil.js +89 -0
- package/package.json +27 -13
- package/{viewBuilder.tpl → viewBuilder.ejs} +18 -11
- package/lib/HMRouterAnalyzer.js +0 -351
- package/lib/HMRouterAnalyzer.js.map +0 -1
- package/lib/HMRouterHvigorPlugin.js +0 -177
- package/lib/HMRouterHvigorPlugin.js.map +0 -1
- package/lib/HMRouterPluginConfig.js +0 -31
- package/lib/HMRouterPluginConfig.js.map +0 -1
- package/lib/HMRouterPluginHandle.js +0 -148
- package/lib/HMRouterPluginHandle.js.map +0 -1
- package/lib/Index.js +0 -143
- package/lib/Index.js.map +0 -1
- package/lib/common/Constant.js.map +0 -1
- package/lib/common/Logger.js.map +0 -1
- package/lib/common/PluginModel.js.map +0 -1
- package/src/HMRouterAnalyzer.ts +0 -375
- package/src/HMRouterHvigorPlugin.ts +0 -199
- package/src/HMRouterPluginConfig.ts +0 -44
- package/src/HMRouterPluginHandle.ts +0 -188
- package/src/Index.ts +0 -151
- package/src/common/Constant.ts +0 -49
- package/src/common/Logger.ts +0 -73
- package/src/common/PluginModel.ts +0 -83
- package/tsconfig.json +0 -14
|
@@ -0,0 +1,139 @@
|
|
|
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.HMRouterHvigorPlugin = void 0;
|
|
7
|
+
const micromatch_1 = __importDefault(require("micromatch"));
|
|
8
|
+
const ejs_1 = __importDefault(require("ejs"));
|
|
9
|
+
const PluginModel_1 = require("./common/PluginModel");
|
|
10
|
+
const Logger_1 = require("./common/Logger");
|
|
11
|
+
const CommonConstants_1 = __importDefault(require("./constants/CommonConstants"));
|
|
12
|
+
const FileUtil_1 = __importDefault(require("./utils/FileUtil"));
|
|
13
|
+
const StringUtil_1 = require("./utils/StringUtil");
|
|
14
|
+
const HMRouterAnalyzer_1 = require("./HMRouterAnalyzer");
|
|
15
|
+
class HMRouterHvigorPlugin {
|
|
16
|
+
constructor(config) {
|
|
17
|
+
this.routerMap = [];
|
|
18
|
+
this.scanFiles = [];
|
|
19
|
+
this.analyzerController = new HMRouterAnalyzer_1.AnalyzerController();
|
|
20
|
+
this.config = config;
|
|
21
|
+
}
|
|
22
|
+
analyzeAnnotation() {
|
|
23
|
+
this.config.scanDir.forEach((dir) => {
|
|
24
|
+
const scanPath = this.config.getScanPath(dir);
|
|
25
|
+
this.deepScan(scanPath, '');
|
|
26
|
+
});
|
|
27
|
+
Logger_1.Logger.info(`Scanned ${this.scanFiles.length} files`, this.scanFiles);
|
|
28
|
+
this.scanFiles.forEach((filePath) => {
|
|
29
|
+
if (filePath.endsWith(CommonConstants_1.default.ETS_SUFFIX)) {
|
|
30
|
+
this.analyzerController.analyzeFile(filePath, this.config);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
this.analyzerController.getAnalyzeResultSet().forEach((analyzerResult) => {
|
|
34
|
+
this.pushRouterInfo(analyzerResult);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
generateRouterMap() {
|
|
38
|
+
let set = new Set();
|
|
39
|
+
this.routerMap.forEach((item) => {
|
|
40
|
+
if (set.has(item.name)) {
|
|
41
|
+
Logger_1.Logger.error(Logger_1.PluginError.ERR_DUPLICATE_NAME, item.name);
|
|
42
|
+
throw new Error(`Route page name: ${item.name} is duplicated`);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
set.add(item.name);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
let routerMap = {
|
|
49
|
+
routerMap: this.routerMap.map((item) => {
|
|
50
|
+
if (item.customData && item.customData.annotation) {
|
|
51
|
+
delete item.customData.annotation;
|
|
52
|
+
delete item.customData.pageSourceFile;
|
|
53
|
+
delete item.customData.isDefaultExport;
|
|
54
|
+
}
|
|
55
|
+
return item;
|
|
56
|
+
})
|
|
57
|
+
};
|
|
58
|
+
const routerMapJsonStr = JSON.stringify(routerMap, null, 2);
|
|
59
|
+
const routerMapFilePath = this.config.getRouterMapDir();
|
|
60
|
+
FileUtil_1.default.ensureFileSync(routerMapFilePath);
|
|
61
|
+
FileUtil_1.default.writeFileSync(routerMapFilePath, routerMapJsonStr);
|
|
62
|
+
Logger_1.Logger.info(`hm_router_map.json has been generated in ${routerMapFilePath}`);
|
|
63
|
+
this.analyzerController.clearAnalyzeResultSet();
|
|
64
|
+
}
|
|
65
|
+
matchedPath(filePath, customPageTemplate, defaultTplFilePath) {
|
|
66
|
+
for (const template of customPageTemplate) {
|
|
67
|
+
if (micromatch_1.default.isMatch(filePath, template.srcPath)) {
|
|
68
|
+
return FileUtil_1.default.pathResolve(this.config.configDir, template.templatePath);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return defaultTplFilePath;
|
|
72
|
+
}
|
|
73
|
+
pushRouterInfo(analyzeResult) {
|
|
74
|
+
let pageSourceFile = this.config
|
|
75
|
+
.getRelativeSourcePath(analyzeResult.pageSourceFile)
|
|
76
|
+
.replaceAll(CommonConstants_1.default.FILE_SEPARATOR, CommonConstants_1.default.DELIMITER);
|
|
77
|
+
switch (analyzeResult.annotation) {
|
|
78
|
+
case CommonConstants_1.default.ROUTER_ANNOTATION:
|
|
79
|
+
let generatorFilePath = this.generateBuilder(analyzeResult, pageSourceFile, this.matchedPath(pageSourceFile, this.config.customPageTemplate, this.config.getDefaultTplFilePath()));
|
|
80
|
+
let pageUrl = analyzeResult.pageUrl;
|
|
81
|
+
this.routerMap.push(new PluginModel_1.RouterInfo(pageUrl, generatorFilePath, analyzeResult.name + 'Builder', analyzeResult));
|
|
82
|
+
break;
|
|
83
|
+
case CommonConstants_1.default.ANIMATOR_ANNOTATION:
|
|
84
|
+
let animatorName = CommonConstants_1.default.ANIMATOR_PREFIX + analyzeResult.animatorName;
|
|
85
|
+
this.routerMap.push(new PluginModel_1.RouterInfo(animatorName, pageSourceFile, '', analyzeResult));
|
|
86
|
+
break;
|
|
87
|
+
case CommonConstants_1.default.INTERCEPTOR_ANNOTATION:
|
|
88
|
+
let interceptorName = CommonConstants_1.default.INTERCEPTOR_PREFIX + analyzeResult.interceptorName;
|
|
89
|
+
this.routerMap.push(new PluginModel_1.RouterInfo(interceptorName, pageSourceFile, '', analyzeResult));
|
|
90
|
+
break;
|
|
91
|
+
case CommonConstants_1.default.LIFECYCLE_ANNOTATION:
|
|
92
|
+
let lifecycleName = CommonConstants_1.default.LIFECYCLE_PREFIX + analyzeResult.lifecycleName;
|
|
93
|
+
this.routerMap.push(new PluginModel_1.RouterInfo(lifecycleName, pageSourceFile, '', analyzeResult));
|
|
94
|
+
break;
|
|
95
|
+
case CommonConstants_1.default.SERVICE_ANNOTATION:
|
|
96
|
+
let serviceName = CommonConstants_1.default.SERVICE_PREFIX + analyzeResult.serviceName;
|
|
97
|
+
this.routerMap.push(new PluginModel_1.RouterInfo(serviceName, pageSourceFile, '', analyzeResult));
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
generateBuilder(analyzeResult, pageSourceFile, tempFilePath) {
|
|
102
|
+
let importPath = this.config
|
|
103
|
+
.getRelativeBuilderPath(pageSourceFile)
|
|
104
|
+
.replaceAll(CommonConstants_1.default.FILE_SEPARATOR, CommonConstants_1.default.DELIMITER)
|
|
105
|
+
.replaceAll(CommonConstants_1.default.ETS_SUFFIX, '');
|
|
106
|
+
let generatorViewName = CommonConstants_1.default.VIEW_NAME_PREFIX +
|
|
107
|
+
analyzeResult.name +
|
|
108
|
+
StringUtil_1.StringUtil.stringToHashCode(analyzeResult.pageUrl);
|
|
109
|
+
const templateModel = new PluginModel_1.TemplateModel(analyzeResult.pageUrl, importPath, analyzeResult.name, !!analyzeResult.dialog, generatorViewName, analyzeResult.isDefaultExport);
|
|
110
|
+
if (!FileUtil_1.default.exist(tempFilePath)) {
|
|
111
|
+
throw new Error('Invalid template path: ' + tempFilePath);
|
|
112
|
+
}
|
|
113
|
+
const tpl = FileUtil_1.default.readFileSync(tempFilePath).toString();
|
|
114
|
+
const templateStr = ejs_1.default.render(tpl, templateModel);
|
|
115
|
+
const generatorFilePath = this.config.getGeneratedFilePath(templateModel.generatorViewName);
|
|
116
|
+
FileUtil_1.default.ensureFileSync(generatorFilePath);
|
|
117
|
+
FileUtil_1.default.writeFileSync(generatorFilePath, templateStr);
|
|
118
|
+
Logger_1.Logger.info(`Builder ${templateModel.generatorViewName}.ets has been generated in ${generatorFilePath}`);
|
|
119
|
+
return this.config
|
|
120
|
+
.getBuilderFilePath(templateModel.generatorViewName)
|
|
121
|
+
.replaceAll(CommonConstants_1.default.FILE_SEPARATOR, CommonConstants_1.default.DELIMITER);
|
|
122
|
+
}
|
|
123
|
+
deepScan(scanPath, filePath) {
|
|
124
|
+
let resolvePath = FileUtil_1.default.pathResolve(scanPath, filePath);
|
|
125
|
+
if (!FileUtil_1.default.exist(resolvePath)) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (FileUtil_1.default.isDictionary(resolvePath)) {
|
|
129
|
+
const files = FileUtil_1.default.readdirSync(resolvePath);
|
|
130
|
+
files.forEach((file) => {
|
|
131
|
+
this.deepScan(resolvePath, file);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
this.scanFiles.push(resolvePath);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.HMRouterHvigorPlugin = HMRouterHvigorPlugin;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare class HMRouterPluginConfig {
|
|
2
|
+
moduleName: string;
|
|
3
|
+
modulePath: string;
|
|
4
|
+
configDir: string;
|
|
5
|
+
scanDir: string[];
|
|
6
|
+
routerMapDir: string;
|
|
7
|
+
builderDir: string;
|
|
8
|
+
annotation: string[];
|
|
9
|
+
defaultPageTemplate: string;
|
|
10
|
+
customPageTemplate: CustomPageTemplateImpl[];
|
|
11
|
+
saveGeneratedFile: boolean;
|
|
12
|
+
autoObfuscation: boolean;
|
|
13
|
+
constructor(moduleName: string, modulePath: string, configDir: string, param: HMRouterPluginConfigParam);
|
|
14
|
+
getScanPath(dir: string): string;
|
|
15
|
+
getRelativeSourcePath(filePath: string): string;
|
|
16
|
+
getRelativeBuilderPath(filePath: string): string;
|
|
17
|
+
getGeneratedFilePath(generatorViewName: string): string;
|
|
18
|
+
getBuilderDir(): string;
|
|
19
|
+
getBuilderFilePath(generatorViewName: string): string;
|
|
20
|
+
getRouterMapDir(): string;
|
|
21
|
+
getModuleRouterMapFilePath(routerMapFileName: string): string;
|
|
22
|
+
getRawFilePath(): string;
|
|
23
|
+
getDefaultTplFilePath(): string;
|
|
24
|
+
getObfuscationFilePath(): string;
|
|
25
|
+
getConsumerRulesFilePath(): string;
|
|
26
|
+
}
|
|
27
|
+
export interface HMRouterPluginConfigParam {
|
|
28
|
+
scanDir?: string[];
|
|
29
|
+
routerMapDir?: string;
|
|
30
|
+
builderDir?: string;
|
|
31
|
+
autoObfuscation?: boolean;
|
|
32
|
+
saveGeneratedFile?: boolean;
|
|
33
|
+
defaultPageTemplate?: string;
|
|
34
|
+
customPageTemplate?: CustomPageTemplateImpl[];
|
|
35
|
+
}
|
|
36
|
+
export interface CustomPageTemplateImpl {
|
|
37
|
+
srcPath: string[];
|
|
38
|
+
templatePath: string;
|
|
39
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
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.HMRouterPluginConfig = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const FileUtil_1 = __importDefault(require("./utils/FileUtil"));
|
|
9
|
+
const ConfigConstants_1 = __importDefault(require("./constants/ConfigConstants"));
|
|
10
|
+
const CommonConstants_1 = __importDefault(require("./constants/CommonConstants"));
|
|
11
|
+
class HMRouterPluginConfig {
|
|
12
|
+
constructor(moduleName, modulePath, configDir, param) {
|
|
13
|
+
this.moduleName = moduleName;
|
|
14
|
+
this.modulePath = modulePath;
|
|
15
|
+
this.configDir = configDir;
|
|
16
|
+
this.scanDir = param.scanDir ? [...new Set(param.scanDir)] : [ConfigConstants_1.default.DEFAULT_SCAN_DIR];
|
|
17
|
+
this.routerMapDir = param.routerMapDir ? param.routerMapDir : ConfigConstants_1.default.DEFAULT_ROUTER_MAP_DIR;
|
|
18
|
+
this.builderDir = param.builderDir ? param.builderDir : ConfigConstants_1.default.DEFAULT_BUILD_DIR;
|
|
19
|
+
this.annotation = [
|
|
20
|
+
ConfigConstants_1.default.ROUTER_ANNOTATION,
|
|
21
|
+
ConfigConstants_1.default.ANIMATOR_ANNOTATION,
|
|
22
|
+
ConfigConstants_1.default.INTERCEPTOR_ANNOTATION,
|
|
23
|
+
ConfigConstants_1.default.LIFECYCLE_ANNOTATION,
|
|
24
|
+
ConfigConstants_1.default.SERVICE_ANNOTATION
|
|
25
|
+
];
|
|
26
|
+
this.defaultPageTemplate =
|
|
27
|
+
param.defaultPageTemplate ? param.defaultPageTemplate : ConfigConstants_1.default.DEFAULT_BUILD_TPL;
|
|
28
|
+
this.customPageTemplate = param.customPageTemplate ? param.customPageTemplate : [];
|
|
29
|
+
this.saveGeneratedFile = !!param.saveGeneratedFile;
|
|
30
|
+
this.autoObfuscation = !!param.autoObfuscation;
|
|
31
|
+
}
|
|
32
|
+
getScanPath(dir) {
|
|
33
|
+
return FileUtil_1.default.pathResolve(this.modulePath, dir);
|
|
34
|
+
}
|
|
35
|
+
getRelativeSourcePath(filePath) {
|
|
36
|
+
return path_1.default.relative(this.modulePath, filePath);
|
|
37
|
+
}
|
|
38
|
+
getRelativeBuilderPath(filePath) {
|
|
39
|
+
return path_1.default.relative(this.builderDir, filePath);
|
|
40
|
+
}
|
|
41
|
+
getGeneratedFilePath(generatorViewName) {
|
|
42
|
+
return FileUtil_1.default.pathResolve(this.modulePath, this.builderDir, generatorViewName + CommonConstants_1.default.ETS_SUFFIX);
|
|
43
|
+
}
|
|
44
|
+
getBuilderDir() {
|
|
45
|
+
return FileUtil_1.default.pathResolve(this.modulePath, this.builderDir);
|
|
46
|
+
}
|
|
47
|
+
getBuilderFilePath(generatorViewName) {
|
|
48
|
+
return path_1.default.join(this.builderDir, generatorViewName + CommonConstants_1.default.ETS_SUFFIX);
|
|
49
|
+
}
|
|
50
|
+
getRouterMapDir() {
|
|
51
|
+
return FileUtil_1.default.pathResolve(this.modulePath, this.routerMapDir, CommonConstants_1.default.ROUTER_MAP_NAME);
|
|
52
|
+
}
|
|
53
|
+
getModuleRouterMapFilePath(routerMapFileName) {
|
|
54
|
+
return FileUtil_1.default.pathResolve(this.modulePath, this.routerMapDir, routerMapFileName + CommonConstants_1.default.JSON_SUFFIX);
|
|
55
|
+
}
|
|
56
|
+
getRawFilePath() {
|
|
57
|
+
return FileUtil_1.default.pathResolve(this.modulePath, CommonConstants_1.default.RAWFILE_DIR);
|
|
58
|
+
}
|
|
59
|
+
getDefaultTplFilePath() {
|
|
60
|
+
let templateFilePath = FileUtil_1.default.pathResolve(this.configDir, this.defaultPageTemplate);
|
|
61
|
+
if (FileUtil_1.default.exist(templateFilePath)) {
|
|
62
|
+
return templateFilePath;
|
|
63
|
+
}
|
|
64
|
+
return FileUtil_1.default.pathResolve(__dirname, CommonConstants_1.default.PARENT_DELIMITER + this.defaultPageTemplate);
|
|
65
|
+
}
|
|
66
|
+
getObfuscationFilePath() {
|
|
67
|
+
return FileUtil_1.default.pathResolve(this.modulePath, CommonConstants_1.default.OBFUSCATION_FILE_NAME);
|
|
68
|
+
}
|
|
69
|
+
getConsumerRulesFilePath() {
|
|
70
|
+
return FileUtil_1.default.pathResolve(this.modulePath, CommonConstants_1.default.CONSUMER_FILE_NAME);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.HMRouterPluginConfig = HMRouterPluginConfig;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { HvigorNode } from '@ohos/hvigor';
|
|
2
|
+
import { OhosHapContext, OhosHarContext, OhosHspContext } from '@ohos/hvigor-ohos-plugin';
|
|
3
|
+
import { HMRouterPluginConfig } from './HMRouterPluginConfig';
|
|
4
|
+
export declare class HMRouterPluginHandle {
|
|
5
|
+
readonly config: HMRouterPluginConfig;
|
|
6
|
+
private readonly node;
|
|
7
|
+
private readonly moduleContext;
|
|
8
|
+
private readonly appContext;
|
|
9
|
+
private readonly plugin;
|
|
10
|
+
constructor(node: HvigorNode, moduleContext: OhosHapContext | OhosHarContext | OhosHspContext);
|
|
11
|
+
start(): void;
|
|
12
|
+
private generateObfuscationFileTask;
|
|
13
|
+
private isEnableObfuscation;
|
|
14
|
+
private copyRouterMapToRawFileTask;
|
|
15
|
+
private writeHspModuleName;
|
|
16
|
+
private getRemoteHspModuleNames;
|
|
17
|
+
private taskExec;
|
|
18
|
+
private updateModuleJsonOpt;
|
|
19
|
+
private updateBuildProfileOpt;
|
|
20
|
+
private pushRouterInfo;
|
|
21
|
+
private readConfig;
|
|
22
|
+
private ensureNestedObject;
|
|
23
|
+
}
|
|
@@ -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;
|
package/dist/Index.d.ts
ADDED
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
|
+
}
|