@simplysm/sd-cli 6.0.19 → 6.0.27

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