@hadss/hmrouter-plugin 1.2.0-beta.0 → 1.2.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/HMRouterPluginManager.js +9 -2
- package/dist/framework/constants/TaskConstants.d.ts +1 -0
- package/dist/framework/constants/TaskConstants.js +1 -0
- package/dist/framework/core/PluginExecutionController.d.ts +7 -1
- package/dist/framework/core/PluginExecutionController.js +72 -28
- package/dist/framework/utils/FileUtil.d.ts +4 -0
- package/dist/framework/utils/FileUtil.js +11 -0
- package/dist/hmrouter_extension/config/HMRouterPluginConfig.js +3 -4
- package/dist/hmrouter_extension/processor/CodeGenerationProcessor.js +2 -1
- package/dist/hmrouter_extension/processor/InitializerProcessor.d.ts +1 -0
- package/dist/hmrouter_extension/processor/InitializerProcessor.js +29 -5
- package/dist/hmrouter_extension/processor/ObfuscationProcessor.js +1 -1
- package/dist/hmrouter_extension/processor/ResourceProcessor.js +14 -0
- package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.js +2 -1
- package/package.json +1 -1
- package/dist/HMRouterAnalyzer.d.ts +0 -31
- package/dist/HMRouterAnalyzer.js +0 -343
- package/dist/HMRouterHvigorPlugin.d.ts +0 -15
- package/dist/HMRouterHvigorPlugin.js +0 -153
- package/dist/HMRouterPluginConfig.d.ts +0 -39
- package/dist/HMRouterPluginConfig.js +0 -74
- package/dist/HMRouterPluginHandle.d.ts +0 -23
- package/dist/HMRouterPluginHandle.js +0 -222
- package/dist/common/Logger.d.ts +0 -13
- package/dist/common/Logger.js +0 -55
- package/dist/common/PluginModel.d.ts +0 -51
- package/dist/common/PluginModel.js +0 -23
- package/dist/constants/CommonConstants.d.ts +0 -39
- package/dist/constants/CommonConstants.js +0 -46
- package/dist/constants/ConfigConstants.d.ts +0 -12
- package/dist/constants/ConfigConstants.js +0 -16
- package/dist/constants/TaskConstants.d.ts +0 -9
- package/dist/constants/TaskConstants.js +0 -13
- package/dist/store/PluginStore.d.ts +0 -14
- package/dist/store/PluginStore.js +0 -20
- package/dist/utils/FileUtil.d.ts +0 -13
- package/dist/utils/FileUtil.js +0 -20
- package/dist/utils/ObfuscationUtil.d.ts +0 -4
- package/dist/utils/ObfuscationUtil.js +0 -34
- package/dist/utils/StringUtil.d.ts +0 -3
- package/dist/utils/StringUtil.js +0 -18
- package/dist/utils/TsAstUtil.d.ts +0 -9
- package/dist/utils/TsAstUtil.js +0 -97
package/dist/utils/TsAstUtil.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TsAstUtil = exports.project = void 0;
|
|
4
|
-
const ts_morph_1 = require("ts-morph");
|
|
5
|
-
const hvigor_1 = require("@ohos/hvigor");
|
|
6
|
-
const Logger_1 = require("../common/Logger");
|
|
7
|
-
exports.project = null;
|
|
8
|
-
class TsAstUtil {
|
|
9
|
-
static getSourceFile(filePath) {
|
|
10
|
-
if (!hvigor_1.FileUtil.exist(filePath)) {
|
|
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
|
-
}
|
|
20
|
-
}
|
|
21
|
-
if (!exports.project) {
|
|
22
|
-
exports.project = new ts_morph_1.Project({
|
|
23
|
-
compilerOptions: { target: ts_morph_1.ScriptTarget.ES2021 }
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
return exports.project.addSourceFileAtPath(filePath);
|
|
27
|
-
}
|
|
28
|
-
static clearProject() {
|
|
29
|
-
exports.project = null;
|
|
30
|
-
}
|
|
31
|
-
static parseConstantValue(sourceFile, variableName, propertyName) {
|
|
32
|
-
let result;
|
|
33
|
-
if (propertyName) {
|
|
34
|
-
let classInstance = sourceFile.getClasses().find((classes) => {
|
|
35
|
-
return classes.getName() === variableName;
|
|
36
|
-
});
|
|
37
|
-
if (!classInstance) {
|
|
38
|
-
throw new Error(`Unknown class '${variableName}'`);
|
|
39
|
-
}
|
|
40
|
-
let property = classInstance.getProperties().find((properties) => {
|
|
41
|
-
return properties.getName() === propertyName;
|
|
42
|
-
});
|
|
43
|
-
if (!property) {
|
|
44
|
-
throw new Error(`Unknown property '${propertyName}'`);
|
|
45
|
-
}
|
|
46
|
-
result = property.getInitializer();
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
let constant = sourceFile.getVariableDeclarations().find(declaration => {
|
|
50
|
-
return declaration.getName() === variableName;
|
|
51
|
-
});
|
|
52
|
-
if (!constant) {
|
|
53
|
-
throw new Error(`Unknown constant '${variableName}'`);
|
|
54
|
-
}
|
|
55
|
-
result = constant.getInitializer();
|
|
56
|
-
}
|
|
57
|
-
if (result.getKind() !== ts_morph_1.SyntaxKind.StringLiteral) {
|
|
58
|
-
Logger_1.Logger.error(Logger_1.PluginError.ERR_INVALID_STRING_VALUE, variableName);
|
|
59
|
-
throw new Error('Invalid constants value, only string literal is supported, variableName:' + variableName);
|
|
60
|
-
}
|
|
61
|
-
return result.asKind(ts_morph_1.SyntaxKind.StringLiteral)?.getLiteralValue();
|
|
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
|
-
}
|
|
96
|
-
}
|
|
97
|
-
exports.TsAstUtil = TsAstUtil;
|