@hadss/hmrouter-plugin 1.1.0-beta.0 → 1.2.0-beta.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.
Files changed (120) hide show
  1. package/README.md +308 -67
  2. package/dist/HMRouterPluginManager.d.ts +11 -0
  3. package/dist/HMRouterPluginManager.js +66 -0
  4. package/dist/Index.d.ts +14 -3
  5. package/dist/Index.js +58 -110
  6. package/dist/framework/constants/TaskConstants.d.ts +8 -0
  7. package/dist/framework/constants/TaskConstants.js +12 -0
  8. package/dist/framework/constants/index.d.ts +1 -0
  9. package/dist/framework/constants/index.js +17 -0
  10. package/dist/framework/core/PluginExecutionController.d.ts +15 -0
  11. package/dist/framework/core/PluginExecutionController.js +62 -0
  12. package/dist/framework/core/TaskManager.d.ts +12 -0
  13. package/dist/framework/core/TaskManager.js +68 -0
  14. package/dist/framework/core/TaskStage.d.ts +10 -0
  15. package/dist/framework/core/TaskStage.js +14 -0
  16. package/dist/framework/core/index.d.ts +3 -0
  17. package/dist/framework/core/index.js +19 -0
  18. package/dist/framework/extension/ExtensionManager.d.ts +11 -0
  19. package/dist/framework/extension/ExtensionManager.js +33 -0
  20. package/dist/framework/extension/PluginExtension.d.ts +13 -0
  21. package/dist/framework/extension/PluginExtension.js +6 -0
  22. package/dist/framework/extension/context/ExtensionContextImpl.d.ts +23 -0
  23. package/dist/framework/extension/context/ExtensionContextImpl.js +64 -0
  24. package/dist/framework/extension/context/Interface.d.ts +21 -0
  25. package/dist/framework/extension/context/Interface.js +2 -0
  26. package/dist/framework/extension/context/TemplateMetadataImpl.d.ts +12 -0
  27. package/dist/framework/extension/context/TemplateMetadataImpl.js +22 -0
  28. package/dist/framework/extension/index.d.ts +4 -0
  29. package/dist/framework/extension/index.js +20 -0
  30. package/dist/framework/index.d.ts +4 -0
  31. package/dist/framework/index.js +20 -0
  32. package/dist/framework/utils/FileUtil.d.ts +13 -0
  33. package/dist/framework/utils/FileUtil.js +20 -0
  34. package/dist/framework/utils/Logger.d.ts +12 -0
  35. package/dist/framework/utils/Logger.js +31 -0
  36. package/dist/framework/utils/ModuleTypeUtil.d.ts +4 -0
  37. package/dist/framework/utils/ModuleTypeUtil.js +16 -0
  38. package/dist/framework/utils/ObjectUtils.d.ts +3 -0
  39. package/dist/framework/utils/ObjectUtils.js +14 -0
  40. package/dist/framework/utils/PluginStore.d.ts +10 -0
  41. package/dist/framework/utils/PluginStore.js +29 -0
  42. package/dist/framework/utils/StringUtil.d.ts +3 -0
  43. package/dist/framework/utils/StringUtil.js +18 -0
  44. package/dist/framework/utils/TsAstUtil.d.ts +6 -0
  45. package/dist/framework/utils/TsAstUtil.js +19 -0
  46. package/dist/framework/utils/index.d.ts +7 -0
  47. package/dist/framework/utils/index.js +23 -0
  48. package/dist/hmrouter_extension/HMRouterExtension.d.ts +15 -0
  49. package/dist/hmrouter_extension/HMRouterExtension.js +102 -0
  50. package/dist/hmrouter_extension/HMRouterExtensionContext.d.ts +8 -0
  51. package/dist/hmrouter_extension/HMRouterExtensionContext.js +2 -0
  52. package/dist/hmrouter_extension/analyzer/AnnotationAnalyzerRegistry.d.ts +14 -0
  53. package/dist/hmrouter_extension/analyzer/AnnotationAnalyzerRegistry.js +45 -0
  54. package/dist/hmrouter_extension/analyzer/ComponentAnalyzer.d.ts +12 -0
  55. package/dist/hmrouter_extension/analyzer/ComponentAnalyzer.js +51 -0
  56. package/dist/hmrouter_extension/analyzer/RouterAnalyzer.d.ts +12 -0
  57. package/dist/hmrouter_extension/analyzer/RouterAnalyzer.js +87 -0
  58. package/dist/hmrouter_extension/analyzer/interface/AbstractAnnotationAnalyzer.d.ts +9 -0
  59. package/dist/hmrouter_extension/analyzer/interface/AbstractAnnotationAnalyzer.js +9 -0
  60. package/dist/hmrouter_extension/analyzer/interface/IConstantResolver.d.ts +7 -0
  61. package/dist/hmrouter_extension/analyzer/interface/IConstantResolver.js +2 -0
  62. package/dist/hmrouter_extension/analyzer/utils/ConstantAnalyzer.d.ts +9 -0
  63. package/dist/hmrouter_extension/analyzer/utils/ConstantAnalyzer.js +32 -0
  64. package/dist/hmrouter_extension/analyzer/utils/ConstantResolver.d.ts +15 -0
  65. package/dist/hmrouter_extension/analyzer/utils/ConstantResolver.js +217 -0
  66. package/dist/hmrouter_extension/analyzer/utils/DecoratorParser.d.ts +7 -0
  67. package/dist/hmrouter_extension/analyzer/utils/DecoratorParser.js +41 -0
  68. package/dist/hmrouter_extension/analyzer/utils/ImportAnalyzer.d.ts +4 -0
  69. package/dist/hmrouter_extension/analyzer/utils/ImportAnalyzer.js +35 -0
  70. package/dist/hmrouter_extension/config/HMRouterPluginConfig.d.ts +38 -0
  71. package/dist/hmrouter_extension/config/HMRouterPluginConfig.js +64 -0
  72. package/dist/hmrouter_extension/constants/AnnotationConstants.d.ts +8 -0
  73. package/dist/hmrouter_extension/constants/AnnotationConstants.js +11 -0
  74. package/dist/hmrouter_extension/constants/FilePathConstants.d.ts +19 -0
  75. package/dist/hmrouter_extension/constants/FilePathConstants.js +26 -0
  76. package/dist/hmrouter_extension/constants/ObfuscationConstants.d.ts +5 -0
  77. package/dist/hmrouter_extension/constants/ObfuscationConstants.js +8 -0
  78. package/dist/hmrouter_extension/constants/PluginConstants.d.ts +7 -0
  79. package/dist/hmrouter_extension/constants/PluginConstants.js +10 -0
  80. package/dist/hmrouter_extension/constants/PrefixConstants.d.ts +8 -0
  81. package/dist/hmrouter_extension/constants/PrefixConstants.js +11 -0
  82. package/dist/hmrouter_extension/constants/RouterMapConstants.d.ts +5 -0
  83. package/dist/hmrouter_extension/constants/RouterMapConstants.js +8 -0
  84. package/dist/hmrouter_extension/constants/TemplateConstants.d.ts +6 -0
  85. package/dist/hmrouter_extension/constants/TemplateConstants.js +9 -0
  86. package/dist/hmrouter_extension/constants/VersionConstants.d.ts +6 -0
  87. package/dist/hmrouter_extension/constants/VersionConstants.js +9 -0
  88. package/dist/hmrouter_extension/constants/index.d.ts +8 -0
  89. package/dist/hmrouter_extension/constants/index.js +22 -0
  90. package/dist/hmrouter_extension/error/PluginError.d.ts +29 -0
  91. package/dist/hmrouter_extension/error/PluginError.js +75 -0
  92. package/dist/hmrouter_extension/model/HMAnnotationModel.d.ts +28 -0
  93. package/dist/hmrouter_extension/model/HMAnnotationModel.js +2 -0
  94. package/dist/hmrouter_extension/model/RouterInfo.d.ts +6 -0
  95. package/dist/hmrouter_extension/model/RouterInfo.js +2 -0
  96. package/dist/hmrouter_extension/model/TemplateModel.d.ts +8 -0
  97. package/dist/hmrouter_extension/model/TemplateModel.js +2 -0
  98. package/dist/hmrouter_extension/model/index.d.ts +3 -0
  99. package/dist/hmrouter_extension/model/index.js +19 -0
  100. package/dist/hmrouter_extension/processor/CodeGenerationProcessor.d.ts +13 -0
  101. package/dist/hmrouter_extension/processor/CodeGenerationProcessor.js +117 -0
  102. package/dist/hmrouter_extension/processor/CompletionProcessor.d.ts +11 -0
  103. package/dist/hmrouter_extension/processor/CompletionProcessor.js +59 -0
  104. package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.d.ts +11 -0
  105. package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.js +53 -0
  106. package/dist/hmrouter_extension/processor/InitializerProcessor.d.ts +15 -0
  107. package/dist/hmrouter_extension/processor/InitializerProcessor.js +96 -0
  108. package/dist/hmrouter_extension/processor/ObfuscationProcessor.d.ts +12 -0
  109. package/dist/hmrouter_extension/processor/ObfuscationProcessor.js +118 -0
  110. package/dist/hmrouter_extension/processor/ResourceProcessor.d.ts +9 -0
  111. package/dist/hmrouter_extension/processor/ResourceProcessor.js +53 -0
  112. package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.d.ts +9 -0
  113. package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.js +117 -0
  114. package/dist/hmrouter_extension/processor/index.d.ts +7 -0
  115. package/dist/hmrouter_extension/processor/index.js +23 -0
  116. package/examples/CustomExtension.ts +256 -0
  117. package/package.json +3 -2
  118. package/template/customBuilder.ejs +1 -0
  119. package/template/viewBuilder.ejs +2 -1
  120. package/template/viewBuilder_v1.ejs +104 -0
@@ -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,4 @@
1
+ export * from './ExtensionManager';
2
+ export * from './PluginExtension';
3
+ export * from './context/Interface';
4
+ export * from './context/ExtensionContextImpl';
@@ -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,4 @@
1
+ export * from './core';
2
+ export * from './extension';
3
+ export * from './utils';
4
+ export * from './constants';
@@ -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,4 @@
1
+ import { HvigorNode } from '@ohos/hvigor';
2
+ export declare function isHapModule(node: HvigorNode): boolean;
3
+ export declare function isHarModule(node: HvigorNode): boolean;
4
+ export declare function isHspModule(node: HvigorNode): boolean;
@@ -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,3 @@
1
+ export declare class ObjectUtils {
2
+ static ensureNestedObject(obj: any, path: string[]): any;
3
+ }
@@ -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;
@@ -0,0 +1,10 @@
1
+ export declare class PluginStore {
2
+ private static instance;
3
+ private dataMap;
4
+ private constructor();
5
+ set(key: string, value: any): void;
6
+ get<T>(key: string): T | undefined;
7
+ private clear;
8
+ static destroy(): void;
9
+ static getInstance(): PluginStore;
10
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PluginStore = void 0;
4
+ class PluginStore {
5
+ constructor() {
6
+ this.dataMap = new Map();
7
+ }
8
+ set(key, value) {
9
+ this.dataMap.set(key, value);
10
+ }
11
+ get(key) {
12
+ return this.dataMap.get(key);
13
+ }
14
+ clear() {
15
+ this.dataMap.clear();
16
+ }
17
+ static destroy() {
18
+ this.getInstance().clear();
19
+ this.instance = null;
20
+ }
21
+ static getInstance() {
22
+ if (!this.instance) {
23
+ this.instance = new PluginStore();
24
+ }
25
+ return this.instance;
26
+ }
27
+ }
28
+ exports.PluginStore = PluginStore;
29
+ PluginStore.instance = null;
@@ -0,0 +1,3 @@
1
+ export declare class StringUtil {
2
+ static stringToHashCode(str: string): number;
3
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringUtil = void 0;
4
+ class StringUtil {
5
+ static stringToHashCode(str) {
6
+ let hash = 0;
7
+ if (str.length === 0) {
8
+ return hash;
9
+ }
10
+ for (let i = 0; i < str.length; i++) {
11
+ const char = str.charCodeAt(i);
12
+ hash = (hash << 5) - hash + char;
13
+ hash |= 0;
14
+ }
15
+ return hash;
16
+ }
17
+ }
18
+ exports.StringUtil = StringUtil;
@@ -0,0 +1,6 @@
1
+ import { Project, SourceFile } from 'ts-morph';
2
+ export declare class TsAstUtil {
3
+ static project: Project | null;
4
+ static getSourceFile(filePath: string): SourceFile;
5
+ static clearProject(): void;
6
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TsAstUtil = void 0;
4
+ const ts_morph_1 = require("ts-morph");
5
+ class TsAstUtil {
6
+ static getSourceFile(filePath) {
7
+ if (!this.project) {
8
+ this.project = new ts_morph_1.Project({
9
+ compilerOptions: { target: ts_morph_1.ScriptTarget.ES2021 },
10
+ });
11
+ }
12
+ return this.project.addSourceFileAtPath(filePath);
13
+ }
14
+ static clearProject() {
15
+ this.project = null;
16
+ }
17
+ }
18
+ exports.TsAstUtil = TsAstUtil;
19
+ TsAstUtil.project = null;
@@ -0,0 +1,7 @@
1
+ export * from './PluginStore';
2
+ export * from './TsAstUtil';
3
+ export * from './FileUtil';
4
+ export * from './ModuleTypeUtil';
5
+ export * from './StringUtil';
6
+ export * from './ObjectUtils';
7
+ export * from './Logger';
@@ -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("./PluginStore"), exports);
18
+ __exportStar(require("./TsAstUtil"), exports);
19
+ __exportStar(require("./FileUtil"), exports);
20
+ __exportStar(require("./ModuleTypeUtil"), exports);
21
+ __exportStar(require("./StringUtil"), exports);
22
+ __exportStar(require("./ObjectUtils"), exports);
23
+ __exportStar(require("./Logger"), exports);
@@ -0,0 +1,15 @@
1
+ import { PluginExtension } from '../framework';
2
+ import { HMRouterExtensionContext } from './HMRouterExtensionContext';
3
+ import { SourceFile } from 'ts-morph';
4
+ export declare class HMRouterDefaultExtension extends PluginExtension<HMRouterExtensionContext> {
5
+ get name(): string;
6
+ afterInitialize(context: HMRouterExtensionContext): void;
7
+ afterAnnotationAnalysis(sourceFile: SourceFile, filePath: string, context: HMRouterExtensionContext): void;
8
+ private executeConstantParsing;
9
+ afterCodeGeneration(context: HMRouterExtensionContext): void;
10
+ afterRouterMapBuilding(context: HMRouterExtensionContext): void;
11
+ afterConfigUpdate(context: HMRouterExtensionContext): void;
12
+ afterObfuscationProcess(context: HMRouterExtensionContext): void;
13
+ afterResourceProcess(context: HMRouterExtensionContext): void;
14
+ afterCompletion(context: HMRouterExtensionContext): void;
15
+ }
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HMRouterDefaultExtension = void 0;
4
+ const framework_1 = require("../framework");
5
+ const AnnotationAnalyzerRegistry_1 = require("./analyzer/AnnotationAnalyzerRegistry");
6
+ const ConstantAnalyzer_1 = require("./analyzer/utils/ConstantAnalyzer");
7
+ const processor_1 = require("./processor");
8
+ const framework_2 = require("../framework");
9
+ class HMRouterDefaultExtension extends framework_1.PluginExtension {
10
+ get name() {
11
+ return 'HMRouterExtension';
12
+ }
13
+ afterInitialize(context) {
14
+ const initializer = new processor_1.InitializerProcessor(context);
15
+ initializer.execute();
16
+ }
17
+ afterAnnotationAnalysis(sourceFile, filePath, context) {
18
+ AnnotationAnalyzerRegistry_1.AnnotationAnalyzerRegistry.getInstance().initialize(context.config.modulePath);
19
+ const analyzers = AnnotationAnalyzerRegistry_1.AnnotationAnalyzerRegistry.getInstance().getAnalyzers();
20
+ for (const analyzer of analyzers) {
21
+ analyzer.analyze(sourceFile, filePath, context);
22
+ }
23
+ this.executeConstantParsing(filePath, context);
24
+ }
25
+ executeConstantParsing(filePath, context) {
26
+ try {
27
+ const contextImpl = context;
28
+ const analyzeResults = contextImpl.analyzeResults;
29
+ const currentView = contextImpl._currentView;
30
+ const currentFilePath = contextImpl._currentFilePath;
31
+ const currentFileResults = [];
32
+ analyzeResults.forEach((result) => {
33
+ if (result.sourceFilePath === currentFilePath) {
34
+ currentFileResults.push(result);
35
+ }
36
+ });
37
+ if (currentFileResults.length === 0) {
38
+ return;
39
+ }
40
+ framework_2.Logger.debug(this.name, `Start constant parsing for ${currentFileResults.length} results in file: ${filePath}`);
41
+ const constantResolver = AnnotationAnalyzerRegistry_1.AnnotationAnalyzerRegistry.getInstance().getConstantResolver();
42
+ if (!constantResolver) {
43
+ framework_2.Logger.warn(this.name, `Constant resolver not available, skip constant parsing for file: ${filePath}`);
44
+ return;
45
+ }
46
+ const constantAnalyzer = new ConstantAnalyzer_1.ConstantAnalyzer(constantResolver);
47
+ const currentFileResultsCopy = currentFileResults.map((result) => ({ ...result }));
48
+ const resultsSet = new Set(currentFileResultsCopy);
49
+ constantAnalyzer.parseConstants(resultsSet);
50
+ const updatedResults = new Set();
51
+ analyzeResults.forEach((result) => {
52
+ if (result.sourceFilePath !== currentFilePath) {
53
+ updatedResults.add(result);
54
+ }
55
+ });
56
+ resultsSet.forEach((parsedResult) => {
57
+ updatedResults.add(parsedResult);
58
+ });
59
+ contextImpl.analyzeResults = updatedResults;
60
+ for (let i = 0; i < currentView.length; i++) {
61
+ const viewResult = currentView[i];
62
+ if (viewResult.sourceFilePath === currentFilePath) {
63
+ for (const parsedResult of resultsSet) {
64
+ if (parsedResult.name === viewResult.name && parsedResult.sourceFilePath === viewResult.sourceFilePath) {
65
+ currentView[i] = parsedResult;
66
+ break;
67
+ }
68
+ }
69
+ }
70
+ }
71
+ framework_2.Logger.debug(this.name, `Constant parsing completed for file: ${filePath}`);
72
+ }
73
+ catch (error) {
74
+ framework_2.Logger.warn(this.name, `Failed to execute constant parsing for file ${filePath}: ${error}`);
75
+ }
76
+ }
77
+ afterCodeGeneration(context) {
78
+ const generator = new processor_1.CodeGenerationProcessor(context);
79
+ generator.execute();
80
+ }
81
+ afterRouterMapBuilding(context) {
82
+ const builder = new processor_1.RouterMapBuildingProcessor(context);
83
+ builder.execute();
84
+ }
85
+ afterConfigUpdate(context) {
86
+ const processor = new processor_1.ConfigUpdateProcessor(context);
87
+ processor.execute();
88
+ }
89
+ afterObfuscationProcess(context) {
90
+ const processor = new processor_1.ObfuscationProcessor(context);
91
+ processor.execute();
92
+ }
93
+ afterResourceProcess(context) {
94
+ const processor = new processor_1.ResourceProcessProcessor(context);
95
+ processor.execute();
96
+ }
97
+ afterCompletion(context) {
98
+ const processor = new processor_1.CompletionProcessor(context);
99
+ processor.execute();
100
+ }
101
+ }
102
+ exports.HMRouterDefaultExtension = HMRouterDefaultExtension;
@@ -0,0 +1,8 @@
1
+ import { ExtensionContext } from '../framework';
2
+ import { HMRouterPluginConfig } from './config/HMRouterPluginConfig';
3
+ import { RouterInfo } from './model';
4
+ export interface HMRouterExtensionContext extends ExtensionContext {
5
+ config: HMRouterPluginConfig;
6
+ routerMap: RouterInfo[];
7
+ generatedPaths: Map<string, string>;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ import { IConstantResolver } from './interface/IConstantResolver';
2
+ import { AbstractAnnotationAnalyzer } from './interface/AbstractAnnotationAnalyzer';
3
+ export declare class AnnotationAnalyzerRegistry {
4
+ private static instance;
5
+ private analyzers;
6
+ private constantResolver;
7
+ private constructor();
8
+ static getInstance(): AnnotationAnalyzerRegistry;
9
+ initialize(modulePath: string): void;
10
+ registerAnalyzer(analyzer: AbstractAnnotationAnalyzer): void;
11
+ getAnalyzers(): AbstractAnnotationAnalyzer[];
12
+ getConstantResolver(): IConstantResolver;
13
+ private registerDefaultAnalyzers;
14
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AnnotationAnalyzerRegistry = void 0;
4
+ const RouterAnalyzer_1 = require("./RouterAnalyzer");
5
+ const ComponentAnalyzer_1 = require("./ComponentAnalyzer");
6
+ const ConstantResolver_1 = require("./utils/ConstantResolver");
7
+ class AnnotationAnalyzerRegistry {
8
+ constructor() {
9
+ this.analyzers = new Set();
10
+ this.constantResolver = null;
11
+ }
12
+ static getInstance() {
13
+ if (!this.instance) {
14
+ this.instance = new AnnotationAnalyzerRegistry();
15
+ }
16
+ return this.instance;
17
+ }
18
+ initialize(modulePath) {
19
+ if (this.constantResolver) {
20
+ return;
21
+ }
22
+ this.constantResolver = new ConstantResolver_1.ConstantResolver(modulePath);
23
+ this.registerDefaultAnalyzers();
24
+ }
25
+ registerAnalyzer(analyzer) {
26
+ this.analyzers.add(analyzer);
27
+ }
28
+ getAnalyzers() {
29
+ return Array.from(this.analyzers);
30
+ }
31
+ getConstantResolver() {
32
+ if (!this.constantResolver) {
33
+ throw new Error('AnnotationAnalyzerRegistry not initialized. Call initialize() first.');
34
+ }
35
+ return this.constantResolver;
36
+ }
37
+ registerDefaultAnalyzers() {
38
+ if (!this.constantResolver) {
39
+ throw new Error('AnnotationAnalyzerRegistry not initialized properly.');
40
+ }
41
+ this.registerAnalyzer(new RouterAnalyzer_1.RouterAnalyzer(this.constantResolver));
42
+ this.registerAnalyzer(new ComponentAnalyzer_1.ComponentAnalyzer(this.constantResolver));
43
+ }
44
+ }
45
+ exports.AnnotationAnalyzerRegistry = AnnotationAnalyzerRegistry;
@@ -0,0 +1,12 @@
1
+ import { SourceFile } from 'ts-morph';
2
+ import { AbstractAnnotationAnalyzer } from './interface/AbstractAnnotationAnalyzer';
3
+ import { IConstantResolver } from './interface/IConstantResolver';
4
+ import { HMRouterExtensionContext } from '../HMRouterExtensionContext';
5
+ export declare class ComponentAnalyzer extends AbstractAnnotationAnalyzer {
6
+ readonly name = "ComponentAnalyzer";
7
+ constructor(constantResolver: IConstantResolver);
8
+ analyze(sourceFile: SourceFile, filePath: string, context: HMRouterExtensionContext): void;
9
+ private analyzeClassDecorators;
10
+ private analyzeMethodDecorators;
11
+ private addToResultSet;
12
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ComponentAnalyzer = void 0;
4
+ const AbstractAnnotationAnalyzer_1 = require("./interface/AbstractAnnotationAnalyzer");
5
+ const DecoratorParser_1 = require("./utils/DecoratorParser");
6
+ const constants_1 = require("../constants");
7
+ class ComponentAnalyzer extends AbstractAnnotationAnalyzer_1.AbstractAnnotationAnalyzer {
8
+ constructor(constantResolver) {
9
+ super(constantResolver);
10
+ this.name = 'ComponentAnalyzer';
11
+ }
12
+ analyze(sourceFile, filePath, context) {
13
+ const results = [];
14
+ sourceFile.getClasses().forEach((cls) => {
15
+ this.analyzeClassDecorators(cls, filePath, sourceFile, results);
16
+ this.analyzeMethodDecorators(cls, filePath, sourceFile, results);
17
+ });
18
+ context.addAnalyzeResults(results);
19
+ }
20
+ analyzeClassDecorators(cls, filePath, sourceFile, results) {
21
+ cls.getDecorators().forEach((decorator) => {
22
+ if ([
23
+ constants_1.AnnotationConstants.INTERCEPTOR_ANNOTATION,
24
+ constants_1.AnnotationConstants.LIFECYCLE_ANNOTATION,
25
+ constants_1.AnnotationConstants.ANIMATOR_ANNOTATION,
26
+ constants_1.AnnotationConstants.SERVICE_PROVIDE_ANNOTATION,
27
+ ].includes(decorator.getName())) {
28
+ const result = this.addToResultSet(decorator, cls.getName(), filePath, sourceFile);
29
+ results.push(result);
30
+ }
31
+ });
32
+ }
33
+ analyzeMethodDecorators(cls, filePath, sourceFile, results) {
34
+ cls.getMethods().forEach((method) => {
35
+ method.getDecorators().forEach((decorator) => {
36
+ if (decorator.getName() === constants_1.AnnotationConstants.SERVICE_ANNOTATION) {
37
+ const serviceResult = this.addToResultSet(decorator, cls.getName(), filePath, sourceFile);
38
+ serviceResult.functionName = method.getName();
39
+ results.push(serviceResult);
40
+ }
41
+ });
42
+ });
43
+ }
44
+ addToResultSet(decorator, componentName, filePath, sourceFile) {
45
+ const decoratorResult = DecoratorParser_1.DecoratorParser.parseDecorator(decorator, this.constantResolver, sourceFile, filePath);
46
+ decoratorResult.name = componentName;
47
+ decoratorResult.sourceFilePath = filePath;
48
+ return decoratorResult;
49
+ }
50
+ }
51
+ exports.ComponentAnalyzer = ComponentAnalyzer;
@@ -0,0 +1,12 @@
1
+ import { SourceFile } from 'ts-morph';
2
+ import { AbstractAnnotationAnalyzer } from './interface/AbstractAnnotationAnalyzer';
3
+ import { IConstantResolver } from './interface/IConstantResolver';
4
+ import { HMRouterExtensionContext } from '../HMRouterExtensionContext';
5
+ export declare class RouterAnalyzer extends AbstractAnnotationAnalyzer {
6
+ readonly name = "RouterAnalyzer";
7
+ constructor(constantResolver: IConstantResolver);
8
+ analyze(sourceFile: SourceFile, filePath: string, context: HMRouterExtensionContext): void;
9
+ private addToResultSet;
10
+ private checkNavDestinationUsage;
11
+ private extractComponentNameFromNode;
12
+ }