@simplysm/sd-cli 6.4.5 → 7.0.9

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 (185) hide show
  1. package/.eslintrc.cjs +11 -0
  2. package/dist/bin/sd-cli.d.ts +1 -0
  3. package/dist/bin/sd-cli.mjs +86 -0
  4. package/dist/build-tool/SdCliCacheCompilerHost.d.ts +10 -0
  5. package/dist/build-tool/SdCliCacheCompilerHost.mjs +44 -0
  6. package/dist/build-tool/SdCliNgCacheCompilerHost.d.ts +11 -0
  7. package/dist/build-tool/SdCliNgCacheCompilerHost.mjs +36 -0
  8. package/dist/build-tool/SdCliPackageLinter.d.ts +8 -0
  9. package/dist/build-tool/SdCliPackageLinter.mjs +41 -0
  10. package/dist/builder/SdCliJsLibBuilder.d.ts +14 -0
  11. package/dist/builder/SdCliJsLibBuilder.mjs +50 -0
  12. package/dist/builder/SdCliTsLibBuilder.d.ts +27 -0
  13. package/dist/builder/SdCliTsLibBuilder.mjs +226 -0
  14. package/dist/commons.d.ts +46 -0
  15. package/dist/commons.mjs +2 -0
  16. package/dist/entry-points/SdCliWorkspace.d.ts +18 -0
  17. package/dist/entry-points/SdCliWorkspace.mjs +193 -0
  18. package/dist/packages/SdCliPackage.d.ts +19 -0
  19. package/dist/packages/SdCliPackage.mjs +89 -0
  20. package/dist/utils/SdCliBuildResultUtil.d.ts +6 -0
  21. package/dist/utils/SdCliBuildResultUtil.mjs +38 -0
  22. package/dist/utils/SdCliConfigUtil.d.ts +7 -0
  23. package/dist/utils/SdCliConfigUtil.mjs +69 -0
  24. package/lib/ts-node-esm-paths.mjs +15 -0
  25. package/package.json +27 -59
  26. package/src/bin/sd-cli.ts +86 -214
  27. package/src/build-tool/SdCliCacheCompilerHost.ts +71 -0
  28. package/src/build-tool/SdCliNgCacheCompilerHost.ts +50 -0
  29. package/src/build-tool/SdCliPackageLinter.ts +54 -0
  30. package/src/builder/SdCliJsLibBuilder.ts +66 -0
  31. package/src/builder/SdCliTsLibBuilder.ts +335 -0
  32. package/src/commons.ts +17 -122
  33. package/src/entry-points/SdCliWorkspace.ts +229 -0
  34. package/src/packages/SdCliPackage.ts +111 -0
  35. package/src/utils/SdCliBuildResultUtil.ts +43 -0
  36. package/src/utils/SdCliConfigUtil.ts +94 -0
  37. package/tsconfig-build.json +9 -0
  38. package/tsconfig.json +7 -18
  39. package/.eslintrc.js +0 -19
  40. package/dist-node/bin/sd-cli.js +0 -197
  41. package/dist-node/bin/sd-cli.js.map +0 -1
  42. package/dist-node/build-tools/SdCliCordova.js +0 -144
  43. package/dist-node/build-tools/SdCliCordova.js.map +0 -1
  44. package/dist-node/build-tools/SdCliIndexFileGenerator.js +0 -51
  45. package/dist-node/build-tools/SdCliIndexFileGenerator.js.map +0 -1
  46. package/dist-node/build-tools/SdCliNgModuleFilesGenerator.js +0 -675
  47. package/dist-node/build-tools/SdCliNgModuleFilesGenerator.js.map +0 -1
  48. package/dist-node/build-tools/metadata/SdAotMetadataReader.js +0 -274
  49. package/dist-node/build-tools/metadata/SdAotMetadataReader.js.map +0 -1
  50. package/dist-node/build-tools/metadata/SdIvyMetadataReader.js +0 -124
  51. package/dist-node/build-tools/metadata/SdIvyMetadataReader.js.map +0 -1
  52. package/dist-node/build-tools/metadata/SdMetadataError.js +0 -13
  53. package/dist-node/build-tools/metadata/SdMetadataError.js.map +0 -1
  54. package/dist-node/build-tools/metadata/SdMyMetadataReader.js +0 -321
  55. package/dist-node/build-tools/metadata/SdMyMetadataReader.js.map +0 -1
  56. package/dist-node/builders/SdCliJavascriptLinter.js +0 -65
  57. package/dist-node/builders/SdCliJavascriptLinter.js.map +0 -1
  58. package/dist-node/builders/SdCliNgClientBuilder.js +0 -636
  59. package/dist-node/builders/SdCliNgClientBuilder.js.map +0 -1
  60. package/dist-node/builders/SdCliNgLibraryBuilder.js +0 -217
  61. package/dist-node/builders/SdCliNgLibraryBuilder.js.map +0 -1
  62. package/dist-node/builders/SdCliPublisher.js +0 -129
  63. package/dist-node/builders/SdCliPublisher.js.map +0 -1
  64. package/dist-node/builders/SdCliServerBuilder.js +0 -452
  65. package/dist-node/builders/SdCliServerBuilder.js.map +0 -1
  66. package/dist-node/builders/SdCliTypescriptBuilder.js +0 -347
  67. package/dist-node/builders/SdCliTypescriptBuilder.js.map +0 -1
  68. package/dist-node/commons.js +0 -3
  69. package/dist-node/commons.js.map +0 -1
  70. package/dist-node/entry-points/SdCliLocalUpdater.js +0 -88
  71. package/dist-node/entry-points/SdCliLocalUpdater.js.map +0 -1
  72. package/dist-node/entry-points/SdCliPrepare.js +0 -56
  73. package/dist-node/entry-points/SdCliPrepare.js.map +0 -1
  74. package/dist-node/entry-points/SdCliProject.js +0 -302
  75. package/dist-node/entry-points/SdCliProject.js.map +0 -1
  76. package/dist-node/packages/SdCliClientPackage.js +0 -91
  77. package/dist-node/packages/SdCliClientPackage.js.map +0 -1
  78. package/dist-node/packages/SdCliLibraryPackage.js +0 -99
  79. package/dist-node/packages/SdCliLibraryPackage.js.map +0 -1
  80. package/dist-node/packages/SdCliPackageBase.js +0 -33
  81. package/dist-node/packages/SdCliPackageBase.js.map +0 -1
  82. package/dist-node/packages/SdCliServerPackage.js +0 -69
  83. package/dist-node/packages/SdCliServerPackage.js.map +0 -1
  84. package/dist-node/packages/SdCliUnknownPackage.js +0 -15
  85. package/dist-node/packages/SdCliUnknownPackage.js.map +0 -1
  86. package/dist-node/utils/SdCliFileCrypto.js +0 -76
  87. package/dist-node/utils/SdCliFileCrypto.js.map +0 -1
  88. package/dist-node/utils/SdProjectConfigUtil.js +0 -62
  89. package/dist-node/utils/SdProjectConfigUtil.js.map +0 -1
  90. package/dist-node/utils/SdTsDiagnosticUtil.js +0 -45
  91. package/dist-node/utils/SdTsDiagnosticUtil.js.map +0 -1
  92. package/dist-node/utils/SdWebpackUtil.js +0 -63
  93. package/dist-node/utils/SdWebpackUtil.js.map +0 -1
  94. package/dist-node/workers/client-ng-gen-worker.js +0 -57
  95. package/dist-node/workers/client-ng-gen-worker.js.map +0 -1
  96. package/dist-node/workers/lib-build-worker.js +0 -88
  97. package/dist-node/workers/lib-build-worker.js.map +0 -1
  98. package/dist-types/bin/sd-cli.d.ts +0 -3
  99. package/dist-types/bin/sd-cli.d.ts.map +0 -1
  100. package/dist-types/build-tools/SdCliCordova.d.ts +0 -15
  101. package/dist-types/build-tools/SdCliCordova.d.ts.map +0 -1
  102. package/dist-types/build-tools/SdCliIndexFileGenerator.d.ts +0 -13
  103. package/dist-types/build-tools/SdCliIndexFileGenerator.d.ts.map +0 -1
  104. package/dist-types/build-tools/SdCliNgModuleFilesGenerator.d.ts +0 -43
  105. package/dist-types/build-tools/SdCliNgModuleFilesGenerator.d.ts.map +0 -1
  106. package/dist-types/build-tools/metadata/SdAotMetadataReader.d.ts +0 -58
  107. package/dist-types/build-tools/metadata/SdAotMetadataReader.d.ts.map +0 -1
  108. package/dist-types/build-tools/metadata/SdIvyMetadataReader.d.ts +0 -43
  109. package/dist-types/build-tools/metadata/SdIvyMetadataReader.d.ts.map +0 -1
  110. package/dist-types/build-tools/metadata/SdMetadataError.d.ts +0 -7
  111. package/dist-types/build-tools/metadata/SdMetadataError.d.ts.map +0 -1
  112. package/dist-types/build-tools/metadata/SdMyMetadataReader.d.ts +0 -59
  113. package/dist-types/build-tools/metadata/SdMyMetadataReader.d.ts.map +0 -1
  114. package/dist-types/builders/SdCliJavascriptLinter.d.ts +0 -14
  115. package/dist-types/builders/SdCliJavascriptLinter.d.ts.map +0 -1
  116. package/dist-types/builders/SdCliNgClientBuilder.d.ts +0 -29
  117. package/dist-types/builders/SdCliNgClientBuilder.d.ts.map +0 -1
  118. package/dist-types/builders/SdCliNgLibraryBuilder.d.ts +0 -30
  119. package/dist-types/builders/SdCliNgLibraryBuilder.d.ts.map +0 -1
  120. package/dist-types/builders/SdCliPublisher.d.ts +0 -9
  121. package/dist-types/builders/SdCliPublisher.d.ts.map +0 -1
  122. package/dist-types/builders/SdCliServerBuilder.d.ts +0 -31
  123. package/dist-types/builders/SdCliServerBuilder.d.ts.map +0 -1
  124. package/dist-types/builders/SdCliTypescriptBuilder.d.ts +0 -56
  125. package/dist-types/builders/SdCliTypescriptBuilder.d.ts.map +0 -1
  126. package/dist-types/commons.d.ts +0 -134
  127. package/dist-types/commons.d.ts.map +0 -1
  128. package/dist-types/entry-points/SdCliLocalUpdater.d.ts +0 -12
  129. package/dist-types/entry-points/SdCliLocalUpdater.d.ts.map +0 -1
  130. package/dist-types/entry-points/SdCliPrepare.d.ts +0 -6
  131. package/dist-types/entry-points/SdCliPrepare.d.ts.map +0 -1
  132. package/dist-types/entry-points/SdCliProject.d.ts +0 -32
  133. package/dist-types/entry-points/SdCliProject.d.ts.map +0 -1
  134. package/dist-types/packages/SdCliClientPackage.d.ts +0 -17
  135. package/dist-types/packages/SdCliClientPackage.d.ts.map +0 -1
  136. package/dist-types/packages/SdCliLibraryPackage.d.ts +0 -20
  137. package/dist-types/packages/SdCliLibraryPackage.d.ts.map +0 -1
  138. package/dist-types/packages/SdCliPackageBase.d.ts +0 -11
  139. package/dist-types/packages/SdCliPackageBase.d.ts.map +0 -1
  140. package/dist-types/packages/SdCliServerPackage.d.ts +0 -16
  141. package/dist-types/packages/SdCliServerPackage.d.ts.map +0 -1
  142. package/dist-types/packages/SdCliUnknownPackage.d.ts +0 -9
  143. package/dist-types/packages/SdCliUnknownPackage.d.ts.map +0 -1
  144. package/dist-types/utils/SdCliFileCrypto.d.ts +0 -8
  145. package/dist-types/utils/SdCliFileCrypto.d.ts.map +0 -1
  146. package/dist-types/utils/SdProjectConfigUtil.d.ts +0 -7
  147. package/dist-types/utils/SdProjectConfigUtil.d.ts.map +0 -1
  148. package/dist-types/utils/SdTsDiagnosticUtil.d.ts +0 -6
  149. package/dist-types/utils/SdTsDiagnosticUtil.d.ts.map +0 -1
  150. package/dist-types/utils/SdWebpackUtil.d.ts +0 -7
  151. package/dist-types/utils/SdWebpackUtil.d.ts.map +0 -1
  152. package/dist-types/workers/client-ng-gen-worker.d.ts +0 -2
  153. package/dist-types/workers/client-ng-gen-worker.d.ts.map +0 -1
  154. package/dist-types/workers/lib-build-worker.d.ts +0 -2
  155. package/dist-types/workers/lib-build-worker.d.ts.map +0 -1
  156. package/schema/schema.json +0 -447
  157. package/sd-tsconfig.node.json +0 -18
  158. package/src/build-tools/SdCliCordova.ts +0 -240
  159. package/src/build-tools/SdCliIndexFileGenerator.ts +0 -61
  160. package/src/build-tools/SdCliNgModuleFilesGenerator.ts +0 -894
  161. package/src/build-tools/metadata/SdAotMetadataReader.ts +0 -374
  162. package/src/build-tools/metadata/SdIvyMetadataReader.ts +0 -183
  163. package/src/build-tools/metadata/SdMetadataError.ts +0 -7
  164. package/src/build-tools/metadata/SdMyMetadataReader.ts +0 -407
  165. package/src/builders/SdCliJavascriptLinter.ts +0 -81
  166. package/src/builders/SdCliNgClientBuilder.ts +0 -793
  167. package/src/builders/SdCliNgLibraryBuilder.ts +0 -301
  168. package/src/builders/SdCliPublisher.ts +0 -144
  169. package/src/builders/SdCliServerBuilder.ts +0 -555
  170. package/src/builders/SdCliTypescriptBuilder.ts +0 -552
  171. package/src/entry-points/SdCliLocalUpdater.ts +0 -114
  172. package/src/entry-points/SdCliPrepare.ts +0 -104
  173. package/src/entry-points/SdCliProject.ts +0 -405
  174. package/src/packages/SdCliClientPackage.ts +0 -111
  175. package/src/packages/SdCliLibraryPackage.ts +0 -118
  176. package/src/packages/SdCliPackageBase.ts +0 -34
  177. package/src/packages/SdCliServerPackage.ts +0 -85
  178. package/src/packages/SdCliUnknownPackage.ts +0 -14
  179. package/src/utils/SdCliFileCrypto.ts +0 -87
  180. package/src/utils/SdCliUtils.ts +0 -56
  181. package/src/utils/SdProjectConfigUtil.ts +0 -145
  182. package/src/utils/SdTsDiagnosticUtil.ts +0 -46
  183. package/src/utils/SdWebpackUtil.ts +0 -71
  184. package/src/workers/client-ng-gen-worker.ts +0 -63
  185. package/src/workers/lib-build-worker.ts +0 -97
@@ -1,407 +0,0 @@
1
- import * as ts from "typescript";
2
- import { NeverEntryError } from "@simplysm/sd-core-common";
3
- import { PathUtil } from "@simplysm/sd-core-node";
4
- import { SdMetadataError } from "./SdMetadataError";
5
-
6
- export class SdMyMetadataReader {
7
- private readonly _typeChecker: ts.TypeChecker;
8
-
9
- public constructor(private readonly _sourceFile: ts.SourceFile,
10
- private readonly _program: ts.Program) {
11
- this._typeChecker = this._program.getTypeChecker();
12
- }
13
-
14
- public getMetadatas(): TMyNgMetadata[] {
15
- const result: TMyNgMetadata[] = [];
16
-
17
- ts.forEachChild(this._sourceFile, (node) => {
18
- if (!ts.isClassDeclaration(node) || !node.name) return;
19
- if (!node.modifiers || !node.modifiers.some((item) => item.kind === ts.SyntaxKind.ExportKeyword)) return;
20
- const className = node.name.text;
21
-
22
- const ngModuleDec = this._getDecorator(node, "NgModule");
23
- if (ngModuleDec) {
24
- const decParam = this._getNgModuleDecoratorParam(ngModuleDec);
25
- const staticProviders = this._getNgModuleStaticProviders(node);
26
-
27
- result.push({
28
- type: "NgModule",
29
- className,
30
- exports: decParam.exports,
31
- providers: [
32
- ...decParam.providers,
33
- ...staticProviders
34
- ]
35
- });
36
- }
37
-
38
- const injectableDec = this._getDecorator(node, "Injectable");
39
- if (injectableDec) {
40
- result.push({
41
- type: "Injectable",
42
- className,
43
- moduleImports: this._getModuleImports(),
44
- ...this._getInjectableDecoratorParam(injectableDec)
45
- });
46
- }
47
-
48
- const directiveDec = this._getDecorator(node, "Directive");
49
- if (directiveDec) {
50
- result.push({
51
- type: "Directive",
52
- className,
53
- moduleImports: this._getModuleImports(),
54
- ...this._getDirectiveDecoratorParam(directiveDec)
55
- });
56
- }
57
-
58
- const pipeDec = this._getDecorator(node, "Pipe");
59
- if (pipeDec) {
60
- result.push({
61
- type: "Pipe",
62
- className,
63
- moduleImports: this._getModuleImports(),
64
- ...this._getPipeDecoratorParam(pipeDec)
65
- });
66
- }
67
-
68
- const componentDec = this._getDecorator(node, "Component");
69
- if (componentDec) {
70
- result.push({
71
- type: "Component",
72
- className,
73
- moduleImports: this._getModuleImports(),
74
- ...this._getComponentDecoratorParam(componentDec)
75
- });
76
- }
77
- });
78
-
79
- return result;
80
- }
81
-
82
- private _getDecorator(node: ts.ClassDeclaration, name: string): ts.CallExpression | undefined {
83
- if (!node.decorators) return undefined;
84
-
85
- for (const dec of node.decorators) {
86
- if (!ts.isCallExpression(dec.expression)) continue;
87
- if (!ts.isIdentifier(dec.expression.expression)) continue;
88
-
89
- if (dec.expression.expression.text === name) {
90
- return dec.expression;
91
- }
92
- }
93
-
94
- return undefined;
95
- }
96
-
97
- private _getModuleImports(): IMyModuleImport[] {
98
- const result: IMyModuleImport[] = [];
99
-
100
- ts.forEachChild(this._sourceFile, (node) => {
101
- if (!ts.isImportDeclaration(node) && !ts.isImportEqualsDeclaration(node) && !ts.isExportDeclaration(node)) return;
102
-
103
- if (ts.isImportDeclaration(node)) {
104
- const importNamedBindings = node.importClause?.namedBindings;
105
- if (importNamedBindings && ts.isNamedImports(importNamedBindings)) {
106
- for (const el of importNamedBindings.elements) {
107
- result.push(this._getAliasedModuleImportInfo(el.name));
108
- }
109
- }
110
- else {
111
- result.push(...this._getAliasedModuleImportsInfoForAllExports(node.moduleSpecifier));
112
- }
113
- }
114
- else if (ts.isExportDeclaration(node)) {
115
- const exportNamedBindings = node.exportClause;
116
- if (exportNamedBindings && ts.isNamedExports(exportNamedBindings)) {
117
- for (const el of exportNamedBindings.elements) {
118
- result.push(this._getAliasedModuleImportInfo(el.name));
119
- }
120
- }
121
- else if (node.moduleSpecifier) {
122
- result.push(...this._getAliasedModuleImportsInfoForAllExports(node.moduleSpecifier));
123
- }
124
- else {
125
- throw new NeverEntryError();
126
- }
127
- }
128
- });
129
-
130
- return result;
131
- }
132
-
133
- private _getAliasedModuleImportsInfoForAllExports(expression: ts.Expression): IMyModuleImport[] {
134
- const moduleSymbol = this._typeChecker.getSymbolAtLocation(expression);
135
- if (!moduleSymbol) throw new NeverEntryError();
136
- const declarations = moduleSymbol.getDeclarations();
137
- if (!declarations || declarations.length !== 1) throw new NeverEntryError();
138
- const moduleFilePath = PathUtil.posix(declarations[0].getSourceFile().fileName);
139
- if (!moduleSymbol.exports) throw new NeverEntryError();
140
-
141
- return Array.from(moduleSymbol.exports.keys() as any).map((key) => ({ name: key as string, moduleFilePath }));
142
- }
143
-
144
- private _getAliasedModuleImportInfo(identifier: ts.Identifier): IMyModuleImport {
145
- const moduleSymbol = this._typeChecker.getSymbolAtLocation(identifier);
146
- if (!moduleSymbol) throw new NeverEntryError();
147
- if (moduleSymbol.valueDeclaration) {
148
- const moduleFilePath = PathUtil.posix(moduleSymbol.valueDeclaration.getSourceFile().fileName);
149
- return { name: identifier.text, moduleFilePath };
150
- }
151
- else {
152
- const aliasedTargetSymbol = this._typeChecker.getAliasedSymbol(moduleSymbol);
153
- const declarations = aliasedTargetSymbol.getDeclarations();
154
- if (!declarations || declarations.length < 1) {
155
- throw new SdMetadataError(this._sourceFile.fileName, `'${identifier.text}'를 찾을 수 없습니다.`);
156
- }
157
-
158
- if (declarations.length === 1) {
159
- return { name: identifier.text, moduleFilePath: PathUtil.posix(declarations[0].getSourceFile().fileName) };
160
- }
161
-
162
- const moduleFilePaths = declarations
163
- .filter((item) => this._hasParentsOrMe(item, (item1) => Boolean(item1.modifiers?.some((mod) => mod.kind === ts.SyntaxKind.ExportKeyword))))
164
- .map((item) => PathUtil.posix(item.getSourceFile().fileName))
165
- .distinct();
166
- if (moduleFilePaths.length === 0) {
167
- throw new SdMetadataError(this._sourceFile.fileName, `'${identifier.text}'의 경로를 찾을 수 없습니다.`);
168
- }
169
- if (moduleFilePaths.length !== 1) {
170
- throw new SdMetadataError(this._sourceFile.fileName, `'${identifier.text}'의 경로가 중복되었습니다.\n${moduleFilePaths.join("\n")}`);
171
- }
172
-
173
- const moduleFilePath = moduleFilePaths[0];
174
-
175
- return { name: identifier.text, moduleFilePath };
176
- }
177
- }
178
-
179
- private _hasParentsOrMe(node: ts.Node, fn: (node1: ts.Node) => boolean): boolean {
180
- let currNode = node as ts.Node | undefined;
181
- while (true) {
182
- if (!currNode) return false;
183
-
184
- const result = fn(currNode);
185
- if (result) return true;
186
-
187
- currNode = currNode.parent as ts.Node | undefined;
188
- }
189
- }
190
-
191
- private _getNgModuleDecoratorParam(decExp: ts.CallExpression): { exports: IMyModuleImport[]; providers: IMyModuleImport[] } {
192
- const result: { exports: IMyModuleImport[]; providers: IMyModuleImport[] } = {
193
- exports: [],
194
- providers: []
195
- };
196
-
197
- if (decExp.arguments.length === 0 || !ts.isObjectLiteralExpression(decExp.arguments[0])) {
198
- throw new NeverEntryError();
199
- }
200
-
201
- const exportsPropInitializer = this._getObjectPropertyValueInitializer(decExp.arguments[0], "exports");
202
- if (exportsPropInitializer) {
203
- if (ts.isArrayLiteralExpression(exportsPropInitializer)) {
204
- for (const el of exportsPropInitializer.elements) {
205
- if (ts.isIdentifier(el)) {
206
- result.exports.push(this._getAliasedModuleImportInfo(el));
207
- }
208
- else {
209
- throw new NeverEntryError();
210
- }
211
- }
212
- }
213
- else {
214
- throw new NeverEntryError();
215
- }
216
- }
217
-
218
- const providersPropInitializer = this._getObjectPropertyValueInitializer(decExp.arguments[0], "providers");
219
- if (providersPropInitializer) {
220
- result.providers.push(...this._getProviders(providersPropInitializer));
221
- }
222
-
223
- return result;
224
- }
225
-
226
- private _getProviders(initializer: ts.Expression): IMyModuleImport[] {
227
- const result: IMyModuleImport[] = [];
228
-
229
- if (ts.isArrayLiteralExpression(initializer)) {
230
- for (const el of initializer.elements) {
231
- result.push(...this._getProviders(el));
232
- }
233
- }
234
- else if (ts.isObjectLiteralExpression(initializer)) {
235
- const propInitializer = this._getObjectPropertyValueInitializer(initializer, "provide");
236
- if (propInitializer) {
237
- result.push(...this._getProviders(propInitializer));
238
- }
239
- }
240
- else if (ts.isIdentifier(initializer)) {
241
- result.push(this._getAliasedModuleImportInfo(initializer));
242
- }
243
- else {
244
- throw new NeverEntryError();
245
- }
246
-
247
- return result;
248
- }
249
-
250
- private _getInjectableDecoratorParam(decExp: ts.CallExpression): { providedIn?: string } {
251
- const result: { providedIn?: string } = {};
252
-
253
- if (decExp.arguments.length !== 0) {
254
- if (!ts.isObjectLiteralExpression(decExp.arguments[0])) {
255
- throw new NeverEntryError();
256
- }
257
-
258
- const providersPropInitializer = this._getObjectPropertyValueInitializer(decExp.arguments[0], "providedIn");
259
- if (providersPropInitializer) {
260
- result.providedIn = this._getExpStringValue(providersPropInitializer);
261
- }
262
- }
263
-
264
- return result;
265
- }
266
-
267
- private _getDirectiveDecoratorParam(decExp: ts.CallExpression): { selector?: string } {
268
- const result: { selector?: string } = {};
269
-
270
- if (decExp.arguments.length === 0 || !ts.isObjectLiteralExpression(decExp.arguments[0])) {
271
- throw new NeverEntryError();
272
- }
273
-
274
- const selectorPropInitializer = this._getObjectPropertyValueInitializer(decExp.arguments[0], "selector");
275
- if (selectorPropInitializer) {
276
- result.selector = this._getExpStringValue(selectorPropInitializer);
277
- }
278
-
279
- return result;
280
- }
281
-
282
- private _getPipeDecoratorParam(decExp: ts.CallExpression): { name?: string } {
283
- const result: { name?: string } = {};
284
-
285
- if (decExp.arguments.length === 0 || !ts.isObjectLiteralExpression(decExp.arguments[0])) {
286
- throw new NeverEntryError();
287
- }
288
-
289
- const namePropInitializer = this._getObjectPropertyValueInitializer(decExp.arguments[0], "name");
290
- if (namePropInitializer) {
291
- result.name = this._getExpStringValue(namePropInitializer);
292
- }
293
-
294
- return result;
295
- }
296
-
297
- private _getComponentDecoratorParam(decExp: ts.CallExpression): { selector?: string; template?: string } {
298
- const result: { selector?: string; template?: string } = {};
299
-
300
- if (decExp.arguments.length === 0 || !ts.isObjectLiteralExpression(decExp.arguments[0])) {
301
- throw new NeverEntryError();
302
- }
303
-
304
- const selectorPropInitializer = this._getObjectPropertyValueInitializer(decExp.arguments[0], "selector");
305
- if (selectorPropInitializer) {
306
- result.selector = this._getExpStringValue(selectorPropInitializer);
307
- }
308
-
309
- const templatePropInitializer = this._getObjectPropertyValueInitializer(decExp.arguments[0], "template");
310
- if (templatePropInitializer) {
311
- result.template = this._getExpStringValue(templatePropInitializer);
312
- }
313
-
314
- return result;
315
- }
316
-
317
- private _getExpStringValue(exp: ts.Expression): string | undefined {
318
- if (ts.isStringLiteral(exp) || ts.isNoSubstitutionTemplateLiteral(exp)) {
319
- return exp.text;
320
- }
321
- else if (exp.kind === ts.SyntaxKind.NullKeyword) {
322
- return undefined;
323
- }
324
- else {
325
- throw new NeverEntryError();
326
- }
327
- }
328
-
329
- private _getObjectPropertyValueInitializer(node: ts.ObjectLiteralExpression, propName: string): ts.Expression | undefined {
330
- for (const prop of node.properties) {
331
- if (!ts.isPropertyAssignment(prop)) continue;
332
- if (!ts.isIdentifier(prop.name)) continue;
333
-
334
- if (prop.name.text === propName) {
335
- return prop.initializer;
336
- }
337
- }
338
-
339
- return undefined;
340
- }
341
-
342
- private _getNgModuleStaticProviders(node: ts.ClassDeclaration): IMyModuleImport[] {
343
- const result: IMyModuleImport[] = [];
344
-
345
- for (const member of node.members) {
346
- if (!member.modifiers || !member.modifiers.some((item) => item.kind === ts.SyntaxKind.StaticKeyword) || !ts.isMethodDeclaration(member)) continue;
347
- if (!member.body) throw new NeverEntryError();
348
- const returnStat = member.body.statements.single((item) => ts.isReturnStatement(item));
349
- if (!returnStat || !ts.isReturnStatement(returnStat) || !returnStat.expression) throw new NeverEntryError();
350
- if (!ts.isObjectLiteralExpression(returnStat.expression)) throw new NeverEntryError();
351
- const providersPropInitializer = this._getObjectPropertyValueInitializer(returnStat.expression, "providers");
352
- if (providersPropInitializer) {
353
- result.push(...this._getProviders(providersPropInitializer));
354
- }
355
- }
356
-
357
- return result;
358
- }
359
- }
360
-
361
- export type TMyNgMetadata =
362
- IMyNgModuleMetadata
363
- | IMyInjectableMetadata
364
- | IMyDirectiveMetadata
365
- | IMyPipeMetadata
366
- | IMyComponentMetadata;
367
-
368
- export interface IMyNgModuleMetadata {
369
- type: "NgModule";
370
- className: string;
371
- exports: IMyModuleImport[];
372
- providers: IMyModuleImport[];
373
- }
374
-
375
- export interface IMyInjectableMetadata {
376
- type: "Injectable";
377
- moduleImports: IMyModuleImport[];
378
- className: string;
379
- providedIn?: string;
380
- }
381
-
382
- export interface IMyDirectiveMetadata {
383
- type: "Directive";
384
- moduleImports: IMyModuleImport[];
385
- className: string;
386
- selector?: string;
387
- }
388
-
389
- export interface IMyPipeMetadata {
390
- type: "Pipe";
391
- moduleImports: IMyModuleImport[];
392
- className: string;
393
- name?: string;
394
- }
395
-
396
- export interface IMyComponentMetadata {
397
- type: "Component";
398
- moduleImports: IMyModuleImport[];
399
- className: string;
400
- selector?: string;
401
- template?: string;
402
- }
403
-
404
- export interface IMyModuleImport {
405
- moduleFilePath: string;
406
- name: string;
407
- }
@@ -1,81 +0,0 @@
1
- import { ISdPackageBuildResult } from "../commons";
2
- import { EventEmitter } from "events";
3
- import { FsUtil, SdFsWatcher } from "@simplysm/sd-core-node";
4
- import * as path from "path";
5
- import { ESLint } from "eslint";
6
-
7
- export class SdCliJavascriptLinter extends EventEmitter {
8
- public constructor(public rootPath: string) {
9
- super();
10
- }
11
-
12
- public on(event: "change", listener: () => void): this;
13
- public on(event: "complete", listener: (results: ISdPackageBuildResult[]) => void): this;
14
- public on(event: string | symbol, listener: (...args: any[]) => void): this {
15
- return super.on(event, listener);
16
- }
17
-
18
- public async lintAsync(watch: boolean): Promise<void> {
19
- this.emit("change");
20
-
21
- if (watch) {
22
- const watchPaths = await this._getWatchPathsAsync();
23
- const watcher = new SdFsWatcher();
24
- watcher
25
- .onChange(async (changeInfos) => {
26
- const dirtyFilePaths = changeInfos
27
- .map((changeInfo) => changeInfo.filePath)
28
- .filter((item) => path.basename(item).includes("."))
29
- .distinct();
30
-
31
- if (dirtyFilePaths.length === 0) return;
32
-
33
- this.emit("change");
34
-
35
- const watchPaths2 = await this._getWatchPathsAsync();
36
- watcher.replaceWatchPaths(watchPaths2);
37
-
38
- const watchResults = await this._lintAsync(dirtyFilePaths);
39
- this.emit("complete", watchResults);
40
- })
41
- .watch(watchPaths);
42
- }
43
-
44
- const results = await this._lintAsync();
45
- this.emit("complete", results);
46
- }
47
-
48
- private async _lintAsync(dirtyFilePaths?: string[]): Promise<ISdPackageBuildResult[]> {
49
- const linter = new ESLint();
50
-
51
- const filePaths = (await this._getFilePathsAsync())
52
- .filter((item) => !dirtyFilePaths || dirtyFilePaths.includes(item));
53
-
54
- const lintResults = await linter.lintFiles(filePaths);
55
-
56
- return lintResults.mapMany((report) => (
57
- report.messages.map((msg) => {
58
- const severity: "warning" | "error" = msg.severity === 1 ? "warning" : "error";
59
-
60
- return {
61
- filePath: report.filePath,
62
- severity,
63
- message: `${report.filePath}(${msg.line}, ${msg.column}): ${msg.ruleId ?? ""}: ${severity} ${msg.message}`
64
- };
65
- })
66
- ));
67
- }
68
-
69
- private async _getWatchPathsAsync(): Promise<string[]> {
70
- return (await FsUtil.globAsync(path.resolve(this.rootPath, "**"), { ignore: "node_modules" }))
71
- .filter((item) => (
72
- !item.includes("node_modules")
73
- && FsUtil.exists(item)
74
- && FsUtil.isDirectory(item)
75
- ));
76
- }
77
-
78
- private async _getFilePathsAsync(): Promise<string[]> {
79
- return await FsUtil.globAsync(path.resolve(this.rootPath, "**/*.js"), { ignore: "node_modules", nodir: true });
80
- }
81
- }