@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,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaskConstants = void 0;
|
|
4
|
+
class TaskConstants {
|
|
5
|
+
}
|
|
6
|
+
exports.TaskConstants = TaskConstants;
|
|
7
|
+
TaskConstants.PRE_BUILD = '@PreBuild';
|
|
8
|
+
TaskConstants.PROCESS_ROUTER_MAP = '@ProcessRouterMap';
|
|
9
|
+
TaskConstants.PROCESS_RESOURCE = '@ProcessResource';
|
|
10
|
+
TaskConstants.PLUGIN_TASK = '@HMRouterPluginTask';
|
|
11
|
+
TaskConstants.COPY_ROUTER_MAP_TASK = '@HMRouterCopyRouterMapToRawFileTask';
|
|
12
|
+
TaskConstants.GENERATE_OBFUSCATION_TASK = '@HMRouterGenerateObfuscationFileTask';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TaskConstants';
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./TaskConstants"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HvigorNode } from '@ohos/hvigor';
|
|
2
|
+
import { OhosModuleContext } from '@ohos/hvigor-ohos-plugin/src/plugin/context/plugin-context';
|
|
3
|
+
import { PluginExtension } from '../extension';
|
|
4
|
+
export declare class PluginExecutionController {
|
|
5
|
+
private readonly node;
|
|
6
|
+
private readonly moduleContext;
|
|
7
|
+
private readonly taskManager;
|
|
8
|
+
private readonly baseContext;
|
|
9
|
+
private extensionContextCache;
|
|
10
|
+
constructor(node: HvigorNode, moduleContext: OhosModuleContext, moduleExtensions?: PluginExtension[]);
|
|
11
|
+
start(): void;
|
|
12
|
+
complete(): void;
|
|
13
|
+
private initializeContext;
|
|
14
|
+
private registerHvigorTasks;
|
|
15
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PluginExecutionController = void 0;
|
|
4
|
+
const TaskManager_1 = require("./TaskManager");
|
|
5
|
+
const TaskStage_1 = require("./TaskStage");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const extension_1 = require("../extension");
|
|
8
|
+
class PluginExecutionController {
|
|
9
|
+
constructor(node, moduleContext, moduleExtensions) {
|
|
10
|
+
this.extensionContextCache = new Map();
|
|
11
|
+
this.node = node;
|
|
12
|
+
this.moduleContext = moduleContext;
|
|
13
|
+
this.baseContext = this.initializeContext();
|
|
14
|
+
this.taskManager = new TaskManager_1.TaskManager(this.baseContext, moduleExtensions);
|
|
15
|
+
}
|
|
16
|
+
start() {
|
|
17
|
+
this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_INITIALIZE);
|
|
18
|
+
this.registerHvigorTasks();
|
|
19
|
+
}
|
|
20
|
+
complete() {
|
|
21
|
+
this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_COMPLETION);
|
|
22
|
+
}
|
|
23
|
+
initializeContext() {
|
|
24
|
+
const context = new extension_1.ExtensionContextImpl(this.node, this.moduleContext);
|
|
25
|
+
context.scanFiles = [];
|
|
26
|
+
return context;
|
|
27
|
+
}
|
|
28
|
+
registerHvigorTasks() {
|
|
29
|
+
this.moduleContext.targets((target) => {
|
|
30
|
+
const targetName = target.getTargetName();
|
|
31
|
+
this.node.registerTask({
|
|
32
|
+
name: targetName + constants_1.TaskConstants.PLUGIN_TASK,
|
|
33
|
+
run: () => {
|
|
34
|
+
this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_ANNOTATION_ANALYSIS);
|
|
35
|
+
this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_CODE_GENERATION);
|
|
36
|
+
this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_ROUTER_MAP_BUILDING);
|
|
37
|
+
this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_CONFIG_UPDATE);
|
|
38
|
+
},
|
|
39
|
+
dependencies: [],
|
|
40
|
+
postDependencies: [targetName + constants_1.TaskConstants.PRE_BUILD],
|
|
41
|
+
});
|
|
42
|
+
this.node.registerTask({
|
|
43
|
+
name: targetName + constants_1.TaskConstants.GENERATE_OBFUSCATION_TASK,
|
|
44
|
+
run: () => {
|
|
45
|
+
this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_OBFUSCATION_PROCESS);
|
|
46
|
+
},
|
|
47
|
+
dependencies: [targetName + constants_1.TaskConstants.PLUGIN_TASK],
|
|
48
|
+
postDependencies: [targetName + constants_1.TaskConstants.PRE_BUILD],
|
|
49
|
+
});
|
|
50
|
+
this.node.registerTask({
|
|
51
|
+
name: targetName + constants_1.TaskConstants.COPY_ROUTER_MAP_TASK,
|
|
52
|
+
run: () => {
|
|
53
|
+
this.taskManager.context.currentTarget = target;
|
|
54
|
+
this.taskManager.executeStage(TaskStage_1.TaskStage.AFTER_RESOURCE_PROCESS);
|
|
55
|
+
},
|
|
56
|
+
dependencies: [targetName + constants_1.TaskConstants.PROCESS_ROUTER_MAP],
|
|
57
|
+
postDependencies: [targetName + constants_1.TaskConstants.PROCESS_RESOURCE],
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.PluginExecutionController = PluginExecutionController;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ExtensionContext, PluginExtension } from '../extension';
|
|
2
|
+
import { TaskStage } from './TaskStage';
|
|
3
|
+
export declare class TaskManager {
|
|
4
|
+
private extensionManager;
|
|
5
|
+
private readonly moduleExtensions;
|
|
6
|
+
context: ExtensionContext;
|
|
7
|
+
constructor(context: ExtensionContext, moduleExtensions?: PluginExtension[]);
|
|
8
|
+
executeStage(stage: TaskStage): void;
|
|
9
|
+
private executeAnnotationAnalysis;
|
|
10
|
+
private getExtensions;
|
|
11
|
+
private validateTemplateData;
|
|
12
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaskManager = void 0;
|
|
4
|
+
const extension_1 = require("../extension");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const TaskStage_1 = require("./TaskStage");
|
|
7
|
+
class TaskManager {
|
|
8
|
+
constructor(context, moduleExtensions) {
|
|
9
|
+
this.extensionManager = extension_1.ExtensionManager.getInstance();
|
|
10
|
+
this.moduleExtensions = moduleExtensions || [];
|
|
11
|
+
this.context = context;
|
|
12
|
+
}
|
|
13
|
+
executeStage(stage) {
|
|
14
|
+
switch (stage) {
|
|
15
|
+
case TaskStage_1.TaskStage.AFTER_ANNOTATION_ANALYSIS:
|
|
16
|
+
this.executeAnnotationAnalysis();
|
|
17
|
+
break;
|
|
18
|
+
default:
|
|
19
|
+
this.getExtensions().forEach((extension) => {
|
|
20
|
+
const methodName = stage.toString();
|
|
21
|
+
extension[methodName]?.(this.context);
|
|
22
|
+
});
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
executeAnnotationAnalysis() {
|
|
27
|
+
const analyzers = this.getExtensions()
|
|
28
|
+
.map((extension) => extension.afterAnnotationAnalysis || null);
|
|
29
|
+
this.context.scanFiles.forEach((file) => {
|
|
30
|
+
this.context.setCurrentFilePath(file);
|
|
31
|
+
const sourceFile = utils_1.TsAstUtil.getSourceFile(file);
|
|
32
|
+
for (const analyzer of analyzers) {
|
|
33
|
+
analyzer?.(sourceFile, file, this.context);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
this.context.setCurrentFilePath('');
|
|
37
|
+
this.validateTemplateData();
|
|
38
|
+
}
|
|
39
|
+
getExtensions() {
|
|
40
|
+
const globalExtensions = this.extensionManager.getExtensions();
|
|
41
|
+
const allExtensions = globalExtensions.concat(this.moduleExtensions);
|
|
42
|
+
return allExtensions.sort((a, b) => {
|
|
43
|
+
const aIsHMRouter = a.name?.includes('HMRouter') || false;
|
|
44
|
+
const bIsHMRouter = b.name?.includes('HMRouter') || false;
|
|
45
|
+
if (aIsHMRouter && !bIsHMRouter)
|
|
46
|
+
return -1;
|
|
47
|
+
if (!aIsHMRouter && bIsHMRouter)
|
|
48
|
+
return 1;
|
|
49
|
+
return 0;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
validateTemplateData() {
|
|
53
|
+
const componentNames = new Set();
|
|
54
|
+
this.context.getAnalyzeResults().forEach((result) => {
|
|
55
|
+
if (result.name) {
|
|
56
|
+
componentNames.add(result.name);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
const templateComponentNames = new Set(this.context.getTemplateDataMap().keys());
|
|
60
|
+
templateComponentNames.forEach((name) => {
|
|
61
|
+
if (!componentNames.has(name)) {
|
|
62
|
+
utils_1.Logger.warn(this.context.node.getNodeName(), `Component ${name} has template data but was not found in analyze results.`);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.TaskManager = TaskManager;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare enum TaskStage {
|
|
2
|
+
AFTER_INITIALIZE = "afterInitialize",
|
|
3
|
+
AFTER_ANNOTATION_ANALYSIS = "afterAnnotationAnalysis",
|
|
4
|
+
AFTER_CODE_GENERATION = "afterCodeGeneration",
|
|
5
|
+
AFTER_ROUTER_MAP_BUILDING = "afterRouterMapBuilding",
|
|
6
|
+
AFTER_CONFIG_UPDATE = "afterConfigUpdate",
|
|
7
|
+
AFTER_OBFUSCATION_PROCESS = "afterObfuscationProcess",
|
|
8
|
+
AFTER_RESOURCE_PROCESS = "afterResourceProcess",
|
|
9
|
+
AFTER_COMPLETION = "afterCompletion"
|
|
10
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaskStage = void 0;
|
|
4
|
+
var TaskStage;
|
|
5
|
+
(function (TaskStage) {
|
|
6
|
+
TaskStage["AFTER_INITIALIZE"] = "afterInitialize";
|
|
7
|
+
TaskStage["AFTER_ANNOTATION_ANALYSIS"] = "afterAnnotationAnalysis";
|
|
8
|
+
TaskStage["AFTER_CODE_GENERATION"] = "afterCodeGeneration";
|
|
9
|
+
TaskStage["AFTER_ROUTER_MAP_BUILDING"] = "afterRouterMapBuilding";
|
|
10
|
+
TaskStage["AFTER_CONFIG_UPDATE"] = "afterConfigUpdate";
|
|
11
|
+
TaskStage["AFTER_OBFUSCATION_PROCESS"] = "afterObfuscationProcess";
|
|
12
|
+
TaskStage["AFTER_RESOURCE_PROCESS"] = "afterResourceProcess";
|
|
13
|
+
TaskStage["AFTER_COMPLETION"] = "afterCompletion";
|
|
14
|
+
})(TaskStage = exports.TaskStage || (exports.TaskStage = {}));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./TaskManager"), exports);
|
|
18
|
+
__exportStar(require("./TaskStage"), exports);
|
|
19
|
+
__exportStar(require("./PluginExecutionController"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PluginExtension } from './PluginExtension';
|
|
2
|
+
export declare class ExtensionManager {
|
|
3
|
+
private static instance;
|
|
4
|
+
private extensions;
|
|
5
|
+
static getInstance(): ExtensionManager;
|
|
6
|
+
static destroy(): void;
|
|
7
|
+
registerExtension(extension: PluginExtension): void;
|
|
8
|
+
getExtensions(): PluginExtension[];
|
|
9
|
+
private clear;
|
|
10
|
+
}
|
|
11
|
+
export declare function registerPluginExtension(extension: PluginExtension): void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerPluginExtension = exports.ExtensionManager = void 0;
|
|
4
|
+
class ExtensionManager {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.extensions = [];
|
|
7
|
+
}
|
|
8
|
+
static getInstance() {
|
|
9
|
+
if (!this.instance) {
|
|
10
|
+
this.instance = new ExtensionManager();
|
|
11
|
+
}
|
|
12
|
+
return this.instance;
|
|
13
|
+
}
|
|
14
|
+
static destroy() {
|
|
15
|
+
this.instance = null;
|
|
16
|
+
this.getInstance().clear();
|
|
17
|
+
}
|
|
18
|
+
registerExtension(extension) {
|
|
19
|
+
this.extensions.push(extension);
|
|
20
|
+
}
|
|
21
|
+
getExtensions() {
|
|
22
|
+
return this.extensions;
|
|
23
|
+
}
|
|
24
|
+
clear() {
|
|
25
|
+
this.extensions = [];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.ExtensionManager = ExtensionManager;
|
|
29
|
+
ExtensionManager.instance = null;
|
|
30
|
+
function registerPluginExtension(extension) {
|
|
31
|
+
ExtensionManager.getInstance().registerExtension(extension);
|
|
32
|
+
}
|
|
33
|
+
exports.registerPluginExtension = registerPluginExtension;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ExtensionContext } from '../extension';
|
|
2
|
+
import { SourceFile } from 'ts-morph';
|
|
3
|
+
export declare abstract class PluginExtension<T extends ExtensionContext = ExtensionContext> {
|
|
4
|
+
abstract get name(): string;
|
|
5
|
+
afterInitialize?(context: T): void;
|
|
6
|
+
afterAnnotationAnalysis?(sourceFile: SourceFile, filePath: string, context: T): void;
|
|
7
|
+
afterCodeGeneration?(context: T): void;
|
|
8
|
+
afterRouterMapBuilding?(context: T): void;
|
|
9
|
+
afterConfigUpdate?(context: T): void;
|
|
10
|
+
afterObfuscationProcess?(context: T): void;
|
|
11
|
+
afterResourceProcess?(context: T): void;
|
|
12
|
+
afterCompletion?(context: T): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { HvigorNode } from '@ohos/hvigor';
|
|
2
|
+
import { OhosModuleContext, Target } from '@ohos/hvigor-ohos-plugin/src/plugin/context/plugin-context';
|
|
3
|
+
import { BaseAnalyzeResult, ExtensionContext } from './Interface';
|
|
4
|
+
export declare class ExtensionContextImpl implements ExtensionContext {
|
|
5
|
+
node: HvigorNode;
|
|
6
|
+
moduleContext: OhosModuleContext;
|
|
7
|
+
currentTarget?: Target;
|
|
8
|
+
scanFiles: string[];
|
|
9
|
+
private templateMetadata;
|
|
10
|
+
private analyzeResults;
|
|
11
|
+
private _currentView;
|
|
12
|
+
private _currentFilePath?;
|
|
13
|
+
constructor(node: HvigorNode, moduleContext: OhosModuleContext);
|
|
14
|
+
get currentView(): ReadonlyArray<BaseAnalyzeResult>;
|
|
15
|
+
addAnalyzeResults(results: BaseAnalyzeResult | BaseAnalyzeResult[]): void;
|
|
16
|
+
getAnalyzeResults<T extends BaseAnalyzeResult = BaseAnalyzeResult>(): Set<T>;
|
|
17
|
+
getTemplateData(componentName: string): Record<string, any> | undefined;
|
|
18
|
+
getTemplateDataMap(): Map<string, Record<string, any>>;
|
|
19
|
+
addTemplateData(componentName: string, data: Record<string, any>): void;
|
|
20
|
+
private validateAnalyzeResult;
|
|
21
|
+
private syncToCurrentView;
|
|
22
|
+
setCurrentFilePath(filePath: string): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExtensionContextImpl = void 0;
|
|
4
|
+
const TemplateMetadataImpl_1 = require("./TemplateMetadataImpl");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
class ExtensionContextImpl {
|
|
7
|
+
constructor(node, moduleContext) {
|
|
8
|
+
this.scanFiles = [];
|
|
9
|
+
this.analyzeResults = new Set();
|
|
10
|
+
this._currentView = [];
|
|
11
|
+
this.node = node;
|
|
12
|
+
this.moduleContext = moduleContext;
|
|
13
|
+
this.templateMetadata = new TemplateMetadataImpl_1.TemplateMetadataImpl();
|
|
14
|
+
}
|
|
15
|
+
get currentView() {
|
|
16
|
+
return this._currentView;
|
|
17
|
+
}
|
|
18
|
+
addAnalyzeResults(results) {
|
|
19
|
+
if (Array.isArray(results)) {
|
|
20
|
+
results.forEach((result) => {
|
|
21
|
+
if (!this.validateAnalyzeResult(result)) {
|
|
22
|
+
utils_1.Logger.warn(this.node.getNodeName(), `Invalid analyze result: ${JSON.stringify(result)}`);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
this.analyzeResults.add(result);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
if (!this.validateAnalyzeResult(results)) {
|
|
30
|
+
utils_1.Logger.warn(this.node.getNodeName(), `Invalid analyze result: ${JSON.stringify(results)}`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
this.analyzeResults.add(results);
|
|
34
|
+
}
|
|
35
|
+
this.syncToCurrentView(results);
|
|
36
|
+
}
|
|
37
|
+
getAnalyzeResults() {
|
|
38
|
+
return this.analyzeResults;
|
|
39
|
+
}
|
|
40
|
+
getTemplateData(componentName) {
|
|
41
|
+
return this.templateMetadata.getTemplateData(componentName);
|
|
42
|
+
}
|
|
43
|
+
getTemplateDataMap() {
|
|
44
|
+
return this.templateMetadata.templateDataMap;
|
|
45
|
+
}
|
|
46
|
+
addTemplateData(componentName, data) {
|
|
47
|
+
this.templateMetadata.addTemplateData(componentName, data);
|
|
48
|
+
}
|
|
49
|
+
validateAnalyzeResult(result) {
|
|
50
|
+
return result.name !== undefined && result.sourceFilePath !== undefined && result.annotation !== undefined;
|
|
51
|
+
}
|
|
52
|
+
syncToCurrentView(results) {
|
|
53
|
+
if (!this._currentFilePath)
|
|
54
|
+
return;
|
|
55
|
+
const resultsArray = Array.isArray(results) ? results : [results];
|
|
56
|
+
const currentFileResults = resultsArray.filter(result => result.sourceFilePath === this._currentFilePath);
|
|
57
|
+
this._currentView.push(...currentFileResults);
|
|
58
|
+
}
|
|
59
|
+
setCurrentFilePath(filePath) {
|
|
60
|
+
this._currentFilePath = filePath;
|
|
61
|
+
this._currentView = [];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.ExtensionContextImpl = ExtensionContextImpl;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HvigorNode } from '@ohos/hvigor';
|
|
2
|
+
import { OhosModuleContext, Target } from '@ohos/hvigor-ohos-plugin/src/plugin/context/plugin-context';
|
|
3
|
+
export interface BaseAnalyzeResult {
|
|
4
|
+
name: string;
|
|
5
|
+
annotation: string;
|
|
6
|
+
sourceFilePath: string;
|
|
7
|
+
}
|
|
8
|
+
export interface BaseExtensionContext {
|
|
9
|
+
readonly node: HvigorNode;
|
|
10
|
+
readonly moduleContext: OhosModuleContext;
|
|
11
|
+
readonly currentView: ReadonlyArray<BaseAnalyzeResult>;
|
|
12
|
+
currentTarget?: Target;
|
|
13
|
+
scanFiles: string[];
|
|
14
|
+
}
|
|
15
|
+
export interface ExtensionContext extends BaseExtensionContext {
|
|
16
|
+
getAnalyzeResults<T extends BaseAnalyzeResult = BaseAnalyzeResult>(): Set<T>;
|
|
17
|
+
addAnalyzeResults(results: BaseAnalyzeResult | BaseAnalyzeResult[]): void;
|
|
18
|
+
getTemplateData(componentName: string): Record<string, any> | undefined;
|
|
19
|
+
getTemplateDataMap(): Map<string, Record<string, any>>;
|
|
20
|
+
addTemplateData(componentName: string, data: Record<string, any>): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface TemplateMetadata {
|
|
2
|
+
currentFilePath: string;
|
|
3
|
+
templateDataMap: Map<string, Record<string, any>>;
|
|
4
|
+
addTemplateData(componentName: string, data: Record<string, any>): void;
|
|
5
|
+
getTemplateData(componentName: string): Record<string, any> | undefined;
|
|
6
|
+
}
|
|
7
|
+
export declare class TemplateMetadataImpl implements TemplateMetadata {
|
|
8
|
+
currentFilePath: string;
|
|
9
|
+
templateDataMap: Map<string, Record<string, any>>;
|
|
10
|
+
addTemplateData(componentName: string, data: Record<string, any>): void;
|
|
11
|
+
getTemplateData(componentName: string): Record<string, any> | undefined;
|
|
12
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TemplateMetadataImpl = void 0;
|
|
4
|
+
class TemplateMetadataImpl {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.currentFilePath = '';
|
|
7
|
+
this.templateDataMap = new Map();
|
|
8
|
+
}
|
|
9
|
+
addTemplateData(componentName, data) {
|
|
10
|
+
if (this.templateDataMap.has(componentName)) {
|
|
11
|
+
const existing = this.templateDataMap.get(componentName) || {};
|
|
12
|
+
this.templateDataMap.set(componentName, { ...existing, ...data });
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
this.templateDataMap.set(componentName, data);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
getTemplateData(componentName) {
|
|
19
|
+
return this.templateDataMap.get(componentName);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.TemplateMetadataImpl = TemplateMetadataImpl;
|
|
@@ -0,0 +1,20 @@
|
|
|
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("./ExtensionManager"), exports);
|
|
18
|
+
__exportStar(require("./PluginExtension"), exports);
|
|
19
|
+
__exportStar(require("./context/Interface"), exports);
|
|
20
|
+
__exportStar(require("./context/ExtensionContextImpl"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
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("./core"), exports);
|
|
18
|
+
__exportStar(require("./extension"), exports);
|
|
19
|
+
__exportStar(require("./utils"), exports);
|
|
20
|
+
__exportStar(require("./constants"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { FileUtil } from '@ohos/hvigor';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
export declare class PluginFileUtil extends FileUtil {
|
|
6
|
+
static rmSync(path: fs.PathLike, options?: fs.RmOptions): void;
|
|
7
|
+
static unlinkSync(path: fs.PathLike): void;
|
|
8
|
+
static readdirSync(path: fs.PathLike, options?: {
|
|
9
|
+
encoding: BufferEncoding | null;
|
|
10
|
+
withFileTypes?: false | undefined;
|
|
11
|
+
recursive?: boolean | undefined;
|
|
12
|
+
}): string[];
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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.PluginFileUtil = void 0;
|
|
7
|
+
const hvigor_1 = require("@ohos/hvigor");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
class PluginFileUtil extends hvigor_1.FileUtil {
|
|
10
|
+
static rmSync(path, options) {
|
|
11
|
+
return fs_1.default.rmSync(path, options);
|
|
12
|
+
}
|
|
13
|
+
static unlinkSync(path) {
|
|
14
|
+
return fs_1.default.unlinkSync(path);
|
|
15
|
+
}
|
|
16
|
+
static readdirSync(path, options) {
|
|
17
|
+
return fs_1.default.readdirSync(path, options);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.PluginFileUtil = PluginFileUtil;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class Logger {
|
|
2
|
+
static error(module: string, msg: string, ...args: unknown[]): void;
|
|
3
|
+
static info(module: string, msg: string, ...args: unknown[]): void;
|
|
4
|
+
static warn(module: string, msg: string, ...args: unknown[]): void;
|
|
5
|
+
static debug(module: string, msg: string, ...args: unknown[]): void;
|
|
6
|
+
static withContext(module: string, operation: string): {
|
|
7
|
+
error: (msg: string, ...args: unknown[]) => void;
|
|
8
|
+
info: (msg: string, ...args: unknown[]) => void;
|
|
9
|
+
warn: (msg: string, ...args: unknown[]) => void;
|
|
10
|
+
debug: (msg: string, ...args: unknown[]) => void;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
const hvigor_1 = require("@ohos/hvigor");
|
|
5
|
+
class Logger {
|
|
6
|
+
static error(module, msg, ...args) {
|
|
7
|
+
const prefix = `[HMRouterPlugin][${module}]:`;
|
|
8
|
+
hvigor_1.HvigorLogger.getLogger().error(`${prefix} ${msg}`, ...args);
|
|
9
|
+
}
|
|
10
|
+
static info(module, msg, ...args) {
|
|
11
|
+
const prefix = `[HMRouterPlugin][${module}]:`;
|
|
12
|
+
hvigor_1.HvigorLogger.getLogger().info(`${prefix} ${msg}`, ...args);
|
|
13
|
+
}
|
|
14
|
+
static warn(module, msg, ...args) {
|
|
15
|
+
const prefix = `[HMRouterPlugin][${module}]:`;
|
|
16
|
+
hvigor_1.HvigorLogger.getLogger().warn(`${prefix} ${msg}`, ...args);
|
|
17
|
+
}
|
|
18
|
+
static debug(module, msg, ...args) {
|
|
19
|
+
const prefix = `[HMRouterPlugin][${module}]:`;
|
|
20
|
+
hvigor_1.HvigorLogger.getLogger().debug(`${prefix} ${msg}`, ...args);
|
|
21
|
+
}
|
|
22
|
+
static withContext(module, operation) {
|
|
23
|
+
return {
|
|
24
|
+
error: (msg, ...args) => Logger.error(module, `${operation} - ${msg}`, ...args),
|
|
25
|
+
info: (msg, ...args) => Logger.info(module, `${operation} - ${msg}`, ...args),
|
|
26
|
+
warn: (msg, ...args) => Logger.warn(module, `${operation} - ${msg}`, ...args),
|
|
27
|
+
debug: (msg, ...args) => Logger.debug(module, `${operation} - ${msg}`, ...args),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.Logger = Logger;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isHspModule = exports.isHarModule = exports.isHapModule = void 0;
|
|
4
|
+
const hvigor_ohos_plugin_1 = require("@ohos/hvigor-ohos-plugin");
|
|
5
|
+
function isHapModule(node) {
|
|
6
|
+
return node.getAllPluginIds().includes(hvigor_ohos_plugin_1.OhosPluginId.OHOS_HAP_PLUGIN);
|
|
7
|
+
}
|
|
8
|
+
exports.isHapModule = isHapModule;
|
|
9
|
+
function isHarModule(node) {
|
|
10
|
+
return node.getAllPluginIds().includes(hvigor_ohos_plugin_1.OhosPluginId.OHOS_HAR_PLUGIN);
|
|
11
|
+
}
|
|
12
|
+
exports.isHarModule = isHarModule;
|
|
13
|
+
function isHspModule(node) {
|
|
14
|
+
return node.getAllPluginIds().includes(hvigor_ohos_plugin_1.OhosPluginId.OHOS_HSP_PLUGIN);
|
|
15
|
+
}
|
|
16
|
+
exports.isHspModule = isHspModule;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObjectUtils = void 0;
|
|
4
|
+
class ObjectUtils {
|
|
5
|
+
static ensureNestedObject(obj, path) {
|
|
6
|
+
return path.reduce((acc, key) => {
|
|
7
|
+
if (!acc[key]) {
|
|
8
|
+
acc[key] = {};
|
|
9
|
+
}
|
|
10
|
+
return acc[key];
|
|
11
|
+
}, obj);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ObjectUtils = ObjectUtils;
|