@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.
Files changed (147) hide show
  1. package/LICENSE +176 -77
  2. package/NOTICE +1365 -0
  3. package/README.md +254 -71
  4. package/dist/HMRouterAnalyzer.d.ts +24 -1
  5. package/dist/HMRouterAnalyzer.js +154 -55
  6. package/dist/HMRouterHvigorPlugin.js +23 -4
  7. package/dist/HMRouterPluginConfig.d.ts +1 -0
  8. package/dist/HMRouterPluginConfig.js +7 -3
  9. package/dist/HMRouterPluginHandle.d.ts +1 -0
  10. package/dist/HMRouterPluginHandle.js +81 -55
  11. package/dist/HMRouterPluginManager.d.ts +9 -0
  12. package/dist/HMRouterPluginManager.js +55 -0
  13. package/dist/Index.d.ts +9 -3
  14. package/dist/Index.js +33 -103
  15. package/dist/common/Logger.js +1 -1
  16. package/dist/common/PluginModel.d.ts +4 -1
  17. package/dist/common/PluginModel.js +2 -1
  18. package/dist/constants/CommonConstants.d.ts +10 -5
  19. package/dist/constants/CommonConstants.js +11 -6
  20. package/dist/constants/ConfigConstants.d.ts +2 -1
  21. package/dist/constants/ConfigConstants.js +3 -2
  22. package/dist/constants/TaskConstants.js +1 -1
  23. package/dist/framework/constants/TaskConstants.d.ts +8 -0
  24. package/dist/framework/constants/TaskConstants.js +12 -0
  25. package/dist/framework/constants/index.d.ts +1 -0
  26. package/dist/framework/constants/index.js +17 -0
  27. package/dist/framework/core/PluginExecutionController.d.ts +15 -0
  28. package/dist/framework/core/PluginExecutionController.js +62 -0
  29. package/dist/framework/core/TaskManager.d.ts +12 -0
  30. package/dist/framework/core/TaskManager.js +67 -0
  31. package/dist/framework/core/TaskStage.d.ts +10 -0
  32. package/dist/framework/core/TaskStage.js +14 -0
  33. package/dist/framework/core/index.d.ts +3 -0
  34. package/dist/framework/core/index.js +19 -0
  35. package/dist/framework/extension/ExtensionManager.d.ts +11 -0
  36. package/dist/framework/extension/ExtensionManager.js +33 -0
  37. package/dist/framework/extension/PluginExtension.d.ts +13 -0
  38. package/dist/framework/extension/PluginExtension.js +6 -0
  39. package/dist/framework/extension/context/ExtensionContextImpl.d.ts +23 -0
  40. package/dist/framework/extension/context/ExtensionContextImpl.js +64 -0
  41. package/dist/framework/extension/context/Interface.d.ts +21 -0
  42. package/dist/framework/extension/context/Interface.js +2 -0
  43. package/dist/framework/extension/context/TemplateMetadataImpl.d.ts +12 -0
  44. package/dist/framework/extension/context/TemplateMetadataImpl.js +22 -0
  45. package/dist/framework/extension/index.d.ts +4 -0
  46. package/dist/framework/extension/index.js +20 -0
  47. package/dist/framework/index.d.ts +4 -0
  48. package/dist/framework/index.js +20 -0
  49. package/dist/framework/utils/FileUtil.d.ts +13 -0
  50. package/dist/framework/utils/FileUtil.js +20 -0
  51. package/dist/framework/utils/Logger.d.ts +12 -0
  52. package/dist/framework/utils/Logger.js +31 -0
  53. package/dist/framework/utils/ModuleTypeUtil.d.ts +4 -0
  54. package/dist/framework/utils/ModuleTypeUtil.js +16 -0
  55. package/dist/framework/utils/ObjectUtils.d.ts +3 -0
  56. package/dist/framework/utils/ObjectUtils.js +14 -0
  57. package/dist/framework/utils/PluginStore.d.ts +10 -0
  58. package/dist/framework/utils/PluginStore.js +29 -0
  59. package/dist/framework/utils/StringUtil.d.ts +3 -0
  60. package/dist/framework/utils/StringUtil.js +18 -0
  61. package/dist/framework/utils/TsAstUtil.d.ts +6 -0
  62. package/dist/framework/utils/TsAstUtil.js +19 -0
  63. package/dist/framework/utils/index.d.ts +7 -0
  64. package/dist/framework/utils/index.js +23 -0
  65. package/dist/hmrouter_extension/HMRouterExtension.d.ts +14 -0
  66. package/dist/hmrouter_extension/HMRouterExtension.js +47 -0
  67. package/dist/hmrouter_extension/HMRouterExtensionContext.d.ts +8 -0
  68. package/dist/hmrouter_extension/HMRouterExtensionContext.js +2 -0
  69. package/dist/hmrouter_extension/analyzer/AnnotationAnalyzerRegistry.d.ts +14 -0
  70. package/dist/hmrouter_extension/analyzer/AnnotationAnalyzerRegistry.js +45 -0
  71. package/dist/hmrouter_extension/analyzer/ComponentAnalyzer.d.ts +12 -0
  72. package/dist/hmrouter_extension/analyzer/ComponentAnalyzer.js +52 -0
  73. package/dist/hmrouter_extension/analyzer/RouterAnalyzer.d.ts +11 -0
  74. package/dist/hmrouter_extension/analyzer/RouterAnalyzer.js +79 -0
  75. package/dist/hmrouter_extension/analyzer/interface/AbstractAnnotationAnalyzer.d.ts +9 -0
  76. package/dist/hmrouter_extension/analyzer/interface/AbstractAnnotationAnalyzer.js +9 -0
  77. package/dist/hmrouter_extension/analyzer/interface/IConstantResolver.d.ts +7 -0
  78. package/dist/hmrouter_extension/analyzer/interface/IConstantResolver.js +2 -0
  79. package/dist/hmrouter_extension/analyzer/utils/ConstantAnalyzer.d.ts +9 -0
  80. package/dist/hmrouter_extension/analyzer/utils/ConstantAnalyzer.js +32 -0
  81. package/dist/hmrouter_extension/analyzer/utils/ConstantResolver.d.ts +15 -0
  82. package/dist/hmrouter_extension/analyzer/utils/ConstantResolver.js +217 -0
  83. package/dist/hmrouter_extension/analyzer/utils/DecoratorParser.d.ts +7 -0
  84. package/dist/hmrouter_extension/analyzer/utils/DecoratorParser.js +41 -0
  85. package/dist/hmrouter_extension/analyzer/utils/ImportAnalyzer.d.ts +4 -0
  86. package/dist/hmrouter_extension/analyzer/utils/ImportAnalyzer.js +35 -0
  87. package/dist/hmrouter_extension/config/HMRouterPluginConfig.d.ts +38 -0
  88. package/dist/hmrouter_extension/config/HMRouterPluginConfig.js +64 -0
  89. package/dist/hmrouter_extension/constants/AnnotationConstants.d.ts +8 -0
  90. package/dist/hmrouter_extension/constants/AnnotationConstants.js +11 -0
  91. package/dist/hmrouter_extension/constants/FilePathConstants.d.ts +19 -0
  92. package/dist/hmrouter_extension/constants/FilePathConstants.js +26 -0
  93. package/dist/hmrouter_extension/constants/ObfuscationConstants.d.ts +5 -0
  94. package/dist/hmrouter_extension/constants/ObfuscationConstants.js +8 -0
  95. package/dist/hmrouter_extension/constants/PluginConstants.d.ts +6 -0
  96. package/dist/hmrouter_extension/constants/PluginConstants.js +9 -0
  97. package/dist/hmrouter_extension/constants/PrefixConstants.d.ts +8 -0
  98. package/dist/hmrouter_extension/constants/PrefixConstants.js +11 -0
  99. package/dist/hmrouter_extension/constants/RouterMapConstants.d.ts +5 -0
  100. package/dist/hmrouter_extension/constants/RouterMapConstants.js +8 -0
  101. package/dist/hmrouter_extension/constants/TemplateConstants.d.ts +6 -0
  102. package/dist/hmrouter_extension/constants/TemplateConstants.js +9 -0
  103. package/dist/hmrouter_extension/constants/VersionConstants.d.ts +6 -0
  104. package/dist/hmrouter_extension/constants/VersionConstants.js +9 -0
  105. package/dist/hmrouter_extension/constants/index.d.ts +8 -0
  106. package/dist/hmrouter_extension/constants/index.js +22 -0
  107. package/dist/hmrouter_extension/error/PluginError.d.ts +29 -0
  108. package/dist/hmrouter_extension/error/PluginError.js +75 -0
  109. package/dist/hmrouter_extension/model/HMAnnotationModel.d.ts +28 -0
  110. package/dist/hmrouter_extension/model/HMAnnotationModel.js +2 -0
  111. package/dist/hmrouter_extension/model/RouterInfo.d.ts +6 -0
  112. package/dist/hmrouter_extension/model/RouterInfo.js +2 -0
  113. package/dist/hmrouter_extension/model/TemplateModel.d.ts +8 -0
  114. package/dist/hmrouter_extension/model/TemplateModel.js +2 -0
  115. package/dist/hmrouter_extension/model/index.d.ts +3 -0
  116. package/dist/hmrouter_extension/model/index.js +19 -0
  117. package/dist/hmrouter_extension/processor/CodeGenerationProcessor.d.ts +13 -0
  118. package/dist/hmrouter_extension/processor/CodeGenerationProcessor.js +117 -0
  119. package/dist/hmrouter_extension/processor/CompletionProcessor.d.ts +11 -0
  120. package/dist/hmrouter_extension/processor/CompletionProcessor.js +59 -0
  121. package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.d.ts +11 -0
  122. package/dist/hmrouter_extension/processor/ConfigUpdateProcessor.js +53 -0
  123. package/dist/hmrouter_extension/processor/InitializerProcessor.d.ts +15 -0
  124. package/dist/hmrouter_extension/processor/InitializerProcessor.js +95 -0
  125. package/dist/hmrouter_extension/processor/ObfuscationProcessor.d.ts +13 -0
  126. package/dist/hmrouter_extension/processor/ObfuscationProcessor.js +121 -0
  127. package/dist/hmrouter_extension/processor/ResourceProcessor.d.ts +9 -0
  128. package/dist/hmrouter_extension/processor/ResourceProcessor.js +53 -0
  129. package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.d.ts +9 -0
  130. package/dist/hmrouter_extension/processor/RouterMapBuildingProcessor.js +122 -0
  131. package/dist/hmrouter_extension/processor/index.d.ts +7 -0
  132. package/dist/hmrouter_extension/processor/index.js +23 -0
  133. package/dist/store/PluginStore.d.ts +14 -0
  134. package/dist/store/PluginStore.js +20 -0
  135. package/dist/utils/FileUtil.d.ts +2 -0
  136. package/dist/utils/ObfuscationUtil.js +7 -1
  137. package/dist/utils/TsAstUtil.d.ts +3 -2
  138. package/dist/utils/TsAstUtil.js +51 -11
  139. package/examples/CustomExtension.ts +256 -0
  140. package/package.json +8 -7
  141. package/template/customBuilder.ejs +25 -0
  142. package/template/viewBuilder.ejs +51 -0
  143. package/{viewBuilder.ejs → template/viewBuilder_v1.ejs} +11 -4
  144. package/dist/common/Constant.d.ts +0 -27
  145. package/dist/common/Constant.js +0 -35
  146. package/dist/utils/ConfusionUtil.d.ts +0 -4
  147. package/dist/utils/ConfusionUtil.js +0 -27
@@ -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,14 @@
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
+ afterCodeGeneration(context: HMRouterExtensionContext): void;
9
+ afterRouterMapBuilding(context: HMRouterExtensionContext): void;
10
+ afterConfigUpdate(context: HMRouterExtensionContext): void;
11
+ afterObfuscationProcess(context: HMRouterExtensionContext): void;
12
+ afterResourceProcess(context: HMRouterExtensionContext): void;
13
+ afterCompletion(context: HMRouterExtensionContext): void;
14
+ }
@@ -0,0 +1,47 @@
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 processor_1 = require("./processor");
7
+ class HMRouterDefaultExtension extends framework_1.PluginExtension {
8
+ get name() {
9
+ return 'HMRouterExtension';
10
+ }
11
+ afterInitialize(context) {
12
+ const initializer = new processor_1.InitializerProcessor(context);
13
+ initializer.execute();
14
+ }
15
+ afterAnnotationAnalysis(sourceFile, filePath, context) {
16
+ AnnotationAnalyzerRegistry_1.AnnotationAnalyzerRegistry.getInstance().initialize(context.config.modulePath);
17
+ const analyzers = AnnotationAnalyzerRegistry_1.AnnotationAnalyzerRegistry.getInstance().getAnalyzers();
18
+ for (const analyzer of analyzers) {
19
+ analyzer.analyze(sourceFile, filePath, context);
20
+ }
21
+ }
22
+ afterCodeGeneration(context) {
23
+ const generator = new processor_1.CodeGenerationProcessor(context);
24
+ generator.execute();
25
+ }
26
+ afterRouterMapBuilding(context) {
27
+ const builder = new processor_1.RouterMapBuildingProcessor(context);
28
+ builder.execute();
29
+ }
30
+ afterConfigUpdate(context) {
31
+ const processor = new processor_1.ConfigUpdateProcessor(context);
32
+ processor.execute();
33
+ }
34
+ afterObfuscationProcess(context) {
35
+ const processor = new processor_1.ObfuscationProcessor(context);
36
+ processor.execute();
37
+ }
38
+ afterResourceProcess(context) {
39
+ const processor = new processor_1.ResourceProcessProcessor(context);
40
+ processor.execute();
41
+ }
42
+ afterCompletion(context) {
43
+ const processor = new processor_1.CompletionProcessor(context);
44
+ processor.execute();
45
+ }
46
+ }
47
+ 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,52 @@
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.SERVICE_ANNOTATION,
24
+ constants_1.AnnotationConstants.INTERCEPTOR_ANNOTATION,
25
+ constants_1.AnnotationConstants.LIFECYCLE_ANNOTATION,
26
+ constants_1.AnnotationConstants.ANIMATOR_ANNOTATION,
27
+ constants_1.AnnotationConstants.SERVICE_PROVIDE_ANNOTATION,
28
+ ].includes(decorator.getName())) {
29
+ const result = this.addToResultSet(decorator, cls.getName(), filePath, sourceFile);
30
+ results.push(result);
31
+ }
32
+ });
33
+ }
34
+ analyzeMethodDecorators(cls, filePath, sourceFile, results) {
35
+ cls.getMethods().forEach((method) => {
36
+ method.getDecorators().forEach((decorator) => {
37
+ if (decorator.getName() === constants_1.AnnotationConstants.SERVICE_ANNOTATION) {
38
+ const serviceResult = this.addToResultSet(decorator, cls.getName(), filePath, sourceFile);
39
+ serviceResult.functionName = method.getName();
40
+ results.push(serviceResult);
41
+ }
42
+ });
43
+ });
44
+ }
45
+ addToResultSet(decorator, componentName, filePath, sourceFile) {
46
+ const decoratorResult = DecoratorParser_1.DecoratorParser.parseDecorator(decorator, this.constantResolver, sourceFile, filePath);
47
+ decoratorResult.name = componentName;
48
+ decoratorResult.sourceFilePath = filePath;
49
+ return decoratorResult;
50
+ }
51
+ }
52
+ exports.ComponentAnalyzer = ComponentAnalyzer;
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RouterAnalyzer = void 0;
4
+ const ts_morph_1 = require("ts-morph");
5
+ const AbstractAnnotationAnalyzer_1 = require("./interface/AbstractAnnotationAnalyzer");
6
+ const DecoratorParser_1 = require("./utils/DecoratorParser");
7
+ const constants_1 = require("../constants");
8
+ const framework_1 = require("../../framework");
9
+ const PluginError_1 = require("../error/PluginError");
10
+ class RouterAnalyzer extends AbstractAnnotationAnalyzer_1.AbstractAnnotationAnalyzer {
11
+ constructor(constantResolver) {
12
+ super(constantResolver);
13
+ this.name = 'RouterAnalyzer';
14
+ }
15
+ analyze(sourceFile, filePath, context) {
16
+ framework_1.Logger.debug('', `Start to analyze source file: ${filePath}`);
17
+ const viewNameArr = sourceFile
18
+ .getChildrenOfKind(ts_morph_1.SyntaxKind.ExpressionStatement)
19
+ .map((node) => node.getText())
20
+ .filter((text) => text !== 'struct');
21
+ sourceFile.getChildrenOfKind(ts_morph_1.SyntaxKind.MissingDeclaration).forEach((node, index) => {
22
+ node.getChildrenOfKind(ts_morph_1.SyntaxKind.Decorator).forEach((decorator) => {
23
+ if (decorator.getName() === constants_1.AnnotationConstants.ROUTER_ANNOTATION) {
24
+ const result = this.addToResultSet(decorator, viewNameArr[index], filePath, sourceFile);
25
+ context.addAnalyzeResults(result);
26
+ }
27
+ });
28
+ });
29
+ sourceFile.getExportAssignments().forEach((exportAssignment, index) => {
30
+ exportAssignment.getDescendantsOfKind(ts_morph_1.SyntaxKind.Decorator).forEach((decorator) => {
31
+ if (decorator.getName() === constants_1.AnnotationConstants.ROUTER_ANNOTATION) {
32
+ const result = this.addToResultSet(decorator, viewNameArr[index], filePath, sourceFile);
33
+ context.addAnalyzeResults(result);
34
+ context.addTemplateData(result.name, { isDefaultExport: 'true' });
35
+ }
36
+ });
37
+ });
38
+ this.checkNavDestinationUsage(sourceFile, filePath);
39
+ }
40
+ addToResultSet(decorator, componentName, filePath, sourceFile) {
41
+ const decoratorResult = DecoratorParser_1.DecoratorParser.parseDecorator(decorator, this.constantResolver, sourceFile, filePath);
42
+ decoratorResult.name = componentName;
43
+ decoratorResult.sourceFilePath = filePath;
44
+ return decoratorResult;
45
+ }
46
+ checkNavDestinationUsage(sourceFile, filePath) {
47
+ const statements = sourceFile.getStatements();
48
+ const sortedStatements = statements.sort((a, b) => a.getStart() - b.getStart());
49
+ let HMRouterExists = false;
50
+ let useNavDst = false;
51
+ sortedStatements.forEach((statement) => {
52
+ if (statement.getKind() === ts_morph_1.SyntaxKind.MissingDeclaration &&
53
+ statement.getText().includes(constants_1.AnnotationConstants.ROUTER_ANNOTATION)) {
54
+ HMRouterExists = true;
55
+ useNavDst = false;
56
+ const text = statement.getText();
57
+ if (/(useNavDst\s*:\s*true)/.test(text)) {
58
+ framework_1.Logger.debug('', `Found useNavDst: true in @HMRouter annotation, skip NavDestination check, filePath: ${filePath}`);
59
+ useNavDst = true;
60
+ }
61
+ }
62
+ if (statement.getKind() === ts_morph_1.SyntaxKind.Block && HMRouterExists) {
63
+ HMRouterExists = false;
64
+ if (useNavDst) {
65
+ return;
66
+ }
67
+ const reg = new RegExp(/NavDestination\s*\(\s*\)/);
68
+ const text = statement.getText();
69
+ const cleanedCodeBlock = text
70
+ .replace(/(["'`]).*?\1/g, '')
71
+ .replace(/\/\/.*|\/\*[\s\S]*?\*\//g, '');
72
+ if (reg.test(cleanedCodeBlock)) {
73
+ throw PluginError_1.PluginError.create(PluginError_1.ErrorCode.WRONG_DECORATION, '', filePath);
74
+ }
75
+ }
76
+ });
77
+ }
78
+ }
79
+ exports.RouterAnalyzer = RouterAnalyzer;
@@ -0,0 +1,9 @@
1
+ import { SourceFile } from 'ts-morph';
2
+ import { IConstantResolver } from './IConstantResolver';
3
+ import { HMRouterExtensionContext } from '../../HMRouterExtensionContext';
4
+ export declare abstract class AbstractAnnotationAnalyzer {
5
+ abstract readonly name: string;
6
+ protected constantResolver: IConstantResolver;
7
+ protected constructor(constantResolver: IConstantResolver);
8
+ abstract analyze(sourceFile: SourceFile, filePath: string, context: HMRouterExtensionContext): void;
9
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractAnnotationAnalyzer = void 0;
4
+ class AbstractAnnotationAnalyzer {
5
+ constructor(constantResolver) {
6
+ this.constantResolver = constantResolver;
7
+ }
8
+ }
9
+ exports.AbstractAnnotationAnalyzer = AbstractAnnotationAnalyzer;
@@ -0,0 +1,7 @@
1
+ import { Expression, SourceFile } from 'ts-morph';
2
+ export interface IConstantResolver {
3
+ resolveConstant(value: any, sourceFile: SourceFile, filePath: string): any;
4
+ resolvePropertyValue(value: Expression, sourceFile: SourceFile, filePath: string): any;
5
+ getVariableFilePath(variableName: string, sourceFile: SourceFile, filePath: string): string;
6
+ getOtherModuleVariableFilePath(moduleName: string, variableName: string, modulePath: string): string;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import { IConstantResolver } from '../interface/IConstantResolver';
2
+ import { BaseAnalyzeResult } from '../../../framework';
3
+ export declare class ConstantAnalyzer {
4
+ private constantResolver;
5
+ constructor(constantResolver: IConstantResolver);
6
+ parseConstants(analyzeResults: Set<BaseAnalyzeResult>): void;
7
+ private parseResult;
8
+ private parsePropertyValue;
9
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConstantAnalyzer = void 0;
4
+ const framework_1 = require("../../../framework");
5
+ class ConstantAnalyzer {
6
+ constructor(constantResolver) {
7
+ this.constantResolver = constantResolver;
8
+ }
9
+ parseConstants(analyzeResults) {
10
+ analyzeResults.forEach((item) => {
11
+ this.parseResult(item);
12
+ });
13
+ }
14
+ parseResult(result) {
15
+ if (!result.sourceFilePath) {
16
+ return;
17
+ }
18
+ Object.getOwnPropertyNames(result).forEach((key) => {
19
+ let propertyValue = Reflect.get(result, key);
20
+ propertyValue = this.parsePropertyValue(result.sourceFilePath, propertyValue);
21
+ if (propertyValue === '') {
22
+ throw new Error(`Constants value cannot be an empty string, filePath: ${result.sourceFilePath}`);
23
+ }
24
+ Reflect.set(result, key, propertyValue);
25
+ });
26
+ }
27
+ parsePropertyValue(filePath, propertyValue) {
28
+ const sourceFile = framework_1.TsAstUtil.getSourceFile(filePath);
29
+ return this.constantResolver.resolveConstant(propertyValue, sourceFile, filePath);
30
+ }
31
+ }
32
+ exports.ConstantAnalyzer = ConstantAnalyzer;
@@ -0,0 +1,15 @@
1
+ import { Expression, SourceFile } from 'ts-morph';
2
+ import { IConstantResolver } from '../interface/IConstantResolver';
3
+ export declare class ConstantResolver implements IConstantResolver {
4
+ private importMapCache;
5
+ private readonly modulePath;
6
+ constructor(modulePath: string);
7
+ resolveConstant(value: any, sourceFile: SourceFile, filePath: string): any;
8
+ resolvePropertyValue(value: Expression, sourceFile: SourceFile, filePath: string): any;
9
+ getVariableFilePath(variableName: string, sourceFile: SourceFile, filePath: string): string;
10
+ getOtherModuleVariableFilePath(moduleName: string, variableName: string, modulePath: string): string;
11
+ private parsePrimitiveValue;
12
+ private parseConstantValue;
13
+ private parseCrossModuleVariable;
14
+ getExportedVariables(sourceFile: SourceFile): string[];
15
+ }