@simplysm/sd-cli 6.4.6 → 7.0.6

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 (182) 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 +60 -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 +43 -0
  15. package/dist/commons.mjs +2 -0
  16. package/dist/entry-points/SdCliWorkspace.d.ts +17 -0
  17. package/dist/entry-points/SdCliWorkspace.mjs +186 -0
  18. package/dist/packages/SdCliPackage.d.ts +19 -0
  19. package/dist/packages/SdCliPackage.mjs +89 -0
  20. package/dist/utils/SdBuildResultUtil.d.ts +6 -0
  21. package/dist/utils/SdBuildResultUtil.mjs +38 -0
  22. package/lib/ts-node-esm-paths.mjs +15 -0
  23. package/package.json +27 -59
  24. package/src/bin/sd-cli.ts +54 -220
  25. package/src/build-tool/SdCliCacheCompilerHost.ts +71 -0
  26. package/src/build-tool/SdCliNgCacheCompilerHost.ts +50 -0
  27. package/src/build-tool/SdCliPackageLinter.ts +54 -0
  28. package/src/builder/SdCliJsLibBuilder.ts +66 -0
  29. package/src/builder/SdCliTsLibBuilder.ts +335 -0
  30. package/src/commons.ts +15 -124
  31. package/src/entry-points/SdCliWorkspace.ts +222 -0
  32. package/src/packages/SdCliPackage.ts +111 -0
  33. package/src/utils/SdBuildResultUtil.ts +43 -0
  34. package/tsconfig-build.json +9 -0
  35. package/tsconfig.json +7 -18
  36. package/.eslintrc.js +0 -19
  37. package/dist-node/bin/sd-cli.js +0 -197
  38. package/dist-node/bin/sd-cli.js.map +0 -1
  39. package/dist-node/build-tools/SdCliCordova.js +0 -145
  40. package/dist-node/build-tools/SdCliCordova.js.map +0 -1
  41. package/dist-node/build-tools/SdCliIndexFileGenerator.js +0 -51
  42. package/dist-node/build-tools/SdCliIndexFileGenerator.js.map +0 -1
  43. package/dist-node/build-tools/SdCliNgModuleFilesGenerator.js +0 -675
  44. package/dist-node/build-tools/SdCliNgModuleFilesGenerator.js.map +0 -1
  45. package/dist-node/build-tools/metadata/SdAotMetadataReader.js +0 -274
  46. package/dist-node/build-tools/metadata/SdAotMetadataReader.js.map +0 -1
  47. package/dist-node/build-tools/metadata/SdIvyMetadataReader.js +0 -124
  48. package/dist-node/build-tools/metadata/SdIvyMetadataReader.js.map +0 -1
  49. package/dist-node/build-tools/metadata/SdMetadataError.js +0 -13
  50. package/dist-node/build-tools/metadata/SdMetadataError.js.map +0 -1
  51. package/dist-node/build-tools/metadata/SdMyMetadataReader.js +0 -321
  52. package/dist-node/build-tools/metadata/SdMyMetadataReader.js.map +0 -1
  53. package/dist-node/builders/SdCliJavascriptLinter.js +0 -65
  54. package/dist-node/builders/SdCliJavascriptLinter.js.map +0 -1
  55. package/dist-node/builders/SdCliNgClientBuilder.js +0 -636
  56. package/dist-node/builders/SdCliNgClientBuilder.js.map +0 -1
  57. package/dist-node/builders/SdCliNgLibraryBuilder.js +0 -217
  58. package/dist-node/builders/SdCliNgLibraryBuilder.js.map +0 -1
  59. package/dist-node/builders/SdCliPublisher.js +0 -129
  60. package/dist-node/builders/SdCliPublisher.js.map +0 -1
  61. package/dist-node/builders/SdCliServerBuilder.js +0 -452
  62. package/dist-node/builders/SdCliServerBuilder.js.map +0 -1
  63. package/dist-node/builders/SdCliTypescriptBuilder.js +0 -347
  64. package/dist-node/builders/SdCliTypescriptBuilder.js.map +0 -1
  65. package/dist-node/commons.js +0 -3
  66. package/dist-node/commons.js.map +0 -1
  67. package/dist-node/entry-points/SdCliLocalUpdater.js +0 -88
  68. package/dist-node/entry-points/SdCliLocalUpdater.js.map +0 -1
  69. package/dist-node/entry-points/SdCliPrepare.js +0 -56
  70. package/dist-node/entry-points/SdCliPrepare.js.map +0 -1
  71. package/dist-node/entry-points/SdCliProject.js +0 -302
  72. package/dist-node/entry-points/SdCliProject.js.map +0 -1
  73. package/dist-node/packages/SdCliClientPackage.js +0 -91
  74. package/dist-node/packages/SdCliClientPackage.js.map +0 -1
  75. package/dist-node/packages/SdCliLibraryPackage.js +0 -99
  76. package/dist-node/packages/SdCliLibraryPackage.js.map +0 -1
  77. package/dist-node/packages/SdCliPackageBase.js +0 -33
  78. package/dist-node/packages/SdCliPackageBase.js.map +0 -1
  79. package/dist-node/packages/SdCliServerPackage.js +0 -69
  80. package/dist-node/packages/SdCliServerPackage.js.map +0 -1
  81. package/dist-node/packages/SdCliUnknownPackage.js +0 -15
  82. package/dist-node/packages/SdCliUnknownPackage.js.map +0 -1
  83. package/dist-node/utils/SdCliFileCrypto.js +0 -76
  84. package/dist-node/utils/SdCliFileCrypto.js.map +0 -1
  85. package/dist-node/utils/SdProjectConfigUtil.js +0 -62
  86. package/dist-node/utils/SdProjectConfigUtil.js.map +0 -1
  87. package/dist-node/utils/SdTsDiagnosticUtil.js +0 -45
  88. package/dist-node/utils/SdTsDiagnosticUtil.js.map +0 -1
  89. package/dist-node/utils/SdWebpackUtil.js +0 -63
  90. package/dist-node/utils/SdWebpackUtil.js.map +0 -1
  91. package/dist-node/workers/client-ng-gen-worker.js +0 -57
  92. package/dist-node/workers/client-ng-gen-worker.js.map +0 -1
  93. package/dist-node/workers/lib-build-worker.js +0 -88
  94. package/dist-node/workers/lib-build-worker.js.map +0 -1
  95. package/dist-types/bin/sd-cli.d.ts +0 -3
  96. package/dist-types/bin/sd-cli.d.ts.map +0 -1
  97. package/dist-types/build-tools/SdCliCordova.d.ts +0 -15
  98. package/dist-types/build-tools/SdCliCordova.d.ts.map +0 -1
  99. package/dist-types/build-tools/SdCliIndexFileGenerator.d.ts +0 -13
  100. package/dist-types/build-tools/SdCliIndexFileGenerator.d.ts.map +0 -1
  101. package/dist-types/build-tools/SdCliNgModuleFilesGenerator.d.ts +0 -43
  102. package/dist-types/build-tools/SdCliNgModuleFilesGenerator.d.ts.map +0 -1
  103. package/dist-types/build-tools/metadata/SdAotMetadataReader.d.ts +0 -58
  104. package/dist-types/build-tools/metadata/SdAotMetadataReader.d.ts.map +0 -1
  105. package/dist-types/build-tools/metadata/SdIvyMetadataReader.d.ts +0 -43
  106. package/dist-types/build-tools/metadata/SdIvyMetadataReader.d.ts.map +0 -1
  107. package/dist-types/build-tools/metadata/SdMetadataError.d.ts +0 -7
  108. package/dist-types/build-tools/metadata/SdMetadataError.d.ts.map +0 -1
  109. package/dist-types/build-tools/metadata/SdMyMetadataReader.d.ts +0 -59
  110. package/dist-types/build-tools/metadata/SdMyMetadataReader.d.ts.map +0 -1
  111. package/dist-types/builders/SdCliJavascriptLinter.d.ts +0 -14
  112. package/dist-types/builders/SdCliJavascriptLinter.d.ts.map +0 -1
  113. package/dist-types/builders/SdCliNgClientBuilder.d.ts +0 -29
  114. package/dist-types/builders/SdCliNgClientBuilder.d.ts.map +0 -1
  115. package/dist-types/builders/SdCliNgLibraryBuilder.d.ts +0 -30
  116. package/dist-types/builders/SdCliNgLibraryBuilder.d.ts.map +0 -1
  117. package/dist-types/builders/SdCliPublisher.d.ts +0 -9
  118. package/dist-types/builders/SdCliPublisher.d.ts.map +0 -1
  119. package/dist-types/builders/SdCliServerBuilder.d.ts +0 -31
  120. package/dist-types/builders/SdCliServerBuilder.d.ts.map +0 -1
  121. package/dist-types/builders/SdCliTypescriptBuilder.d.ts +0 -56
  122. package/dist-types/builders/SdCliTypescriptBuilder.d.ts.map +0 -1
  123. package/dist-types/commons.d.ts +0 -134
  124. package/dist-types/commons.d.ts.map +0 -1
  125. package/dist-types/entry-points/SdCliLocalUpdater.d.ts +0 -12
  126. package/dist-types/entry-points/SdCliLocalUpdater.d.ts.map +0 -1
  127. package/dist-types/entry-points/SdCliPrepare.d.ts +0 -6
  128. package/dist-types/entry-points/SdCliPrepare.d.ts.map +0 -1
  129. package/dist-types/entry-points/SdCliProject.d.ts +0 -32
  130. package/dist-types/entry-points/SdCliProject.d.ts.map +0 -1
  131. package/dist-types/packages/SdCliClientPackage.d.ts +0 -17
  132. package/dist-types/packages/SdCliClientPackage.d.ts.map +0 -1
  133. package/dist-types/packages/SdCliLibraryPackage.d.ts +0 -20
  134. package/dist-types/packages/SdCliLibraryPackage.d.ts.map +0 -1
  135. package/dist-types/packages/SdCliPackageBase.d.ts +0 -11
  136. package/dist-types/packages/SdCliPackageBase.d.ts.map +0 -1
  137. package/dist-types/packages/SdCliServerPackage.d.ts +0 -16
  138. package/dist-types/packages/SdCliServerPackage.d.ts.map +0 -1
  139. package/dist-types/packages/SdCliUnknownPackage.d.ts +0 -9
  140. package/dist-types/packages/SdCliUnknownPackage.d.ts.map +0 -1
  141. package/dist-types/utils/SdCliFileCrypto.d.ts +0 -8
  142. package/dist-types/utils/SdCliFileCrypto.d.ts.map +0 -1
  143. package/dist-types/utils/SdProjectConfigUtil.d.ts +0 -7
  144. package/dist-types/utils/SdProjectConfigUtil.d.ts.map +0 -1
  145. package/dist-types/utils/SdTsDiagnosticUtil.d.ts +0 -6
  146. package/dist-types/utils/SdTsDiagnosticUtil.d.ts.map +0 -1
  147. package/dist-types/utils/SdWebpackUtil.d.ts +0 -7
  148. package/dist-types/utils/SdWebpackUtil.d.ts.map +0 -1
  149. package/dist-types/workers/client-ng-gen-worker.d.ts +0 -2
  150. package/dist-types/workers/client-ng-gen-worker.d.ts.map +0 -1
  151. package/dist-types/workers/lib-build-worker.d.ts +0 -2
  152. package/dist-types/workers/lib-build-worker.d.ts.map +0 -1
  153. package/schema/schema.json +0 -447
  154. package/sd-tsconfig.node.json +0 -18
  155. package/src/build-tools/SdCliCordova.ts +0 -242
  156. package/src/build-tools/SdCliIndexFileGenerator.ts +0 -61
  157. package/src/build-tools/SdCliNgModuleFilesGenerator.ts +0 -894
  158. package/src/build-tools/metadata/SdAotMetadataReader.ts +0 -374
  159. package/src/build-tools/metadata/SdIvyMetadataReader.ts +0 -183
  160. package/src/build-tools/metadata/SdMetadataError.ts +0 -7
  161. package/src/build-tools/metadata/SdMyMetadataReader.ts +0 -407
  162. package/src/builders/SdCliJavascriptLinter.ts +0 -81
  163. package/src/builders/SdCliNgClientBuilder.ts +0 -793
  164. package/src/builders/SdCliNgLibraryBuilder.ts +0 -301
  165. package/src/builders/SdCliPublisher.ts +0 -144
  166. package/src/builders/SdCliServerBuilder.ts +0 -555
  167. package/src/builders/SdCliTypescriptBuilder.ts +0 -552
  168. package/src/entry-points/SdCliLocalUpdater.ts +0 -114
  169. package/src/entry-points/SdCliPrepare.ts +0 -104
  170. package/src/entry-points/SdCliProject.ts +0 -405
  171. package/src/packages/SdCliClientPackage.ts +0 -111
  172. package/src/packages/SdCliLibraryPackage.ts +0 -118
  173. package/src/packages/SdCliPackageBase.ts +0 -34
  174. package/src/packages/SdCliServerPackage.ts +0 -85
  175. package/src/packages/SdCliUnknownPackage.ts +0 -14
  176. package/src/utils/SdCliFileCrypto.ts +0 -87
  177. package/src/utils/SdCliUtils.ts +0 -56
  178. package/src/utils/SdProjectConfigUtil.ts +0 -145
  179. package/src/utils/SdTsDiagnosticUtil.ts +0 -46
  180. package/src/utils/SdWebpackUtil.ts +0 -71
  181. package/src/workers/client-ng-gen-worker.ts +0 -63
  182. package/src/workers/lib-build-worker.ts +0 -97
@@ -1,675 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SdCliNgModuleFilesGenerator = void 0;
4
- const sd_core_common_1 = require("@simplysm/sd-core-common");
5
- const ts = require("typescript");
6
- const sd_core_node_1 = require("@simplysm/sd-core-node");
7
- const path = require("path");
8
- const jsdom_1 = require("jsdom");
9
- const os = require("os");
10
- const SdMyMetadataReader_1 = require("./metadata/SdMyMetadataReader");
11
- const SdAotMetadataReader_1 = require("./metadata/SdAotMetadataReader");
12
- const SdIvyMetadataReader_1 = require("./metadata/SdIvyMetadataReader");
13
- const SdMetadataError_1 = require("./metadata/SdMetadataError");
14
- class SdCliNgModuleFilesGenerator {
15
- constructor(_rootDir) {
16
- this._rootDir = _rootDir;
17
- this._fileCache = new Map();
18
- this._sourceDirPath = path.resolve(this._rootDir, "src");
19
- this._moduleDistDirPath = path.resolve(this._rootDir, "src/_modules");
20
- }
21
- deleteFileCaches(filePaths) {
22
- for (const filePath of filePaths) {
23
- this._fileCache.delete(sd_core_node_1.PathUtil.posix(filePath));
24
- }
25
- }
26
- async reloadSourceFilesAsync(dirtyFilePaths, compilerHost, moduleResolutionCache, ngProgram) {
27
- this._compilerHost = compilerHost;
28
- this._moduleResolutionCache = moduleResolutionCache;
29
- this._program = ngProgram.getTsProgram();
30
- const result = [];
31
- let changed = false;
32
- for (const dirtyFilePath of dirtyFilePaths) {
33
- try {
34
- if (sd_core_node_1.PathUtil.isChildPath(dirtyFilePath, this._moduleDistDirPath))
35
- continue;
36
- this._fileCache.delete(dirtyFilePath);
37
- if (dirtyFilePath.endsWith(".ts") && !dirtyFilePath.endsWith(".d.ts")) {
38
- const sourceFile = this._program.getSourceFile(dirtyFilePath);
39
- if (!sourceFile) {
40
- changed = true;
41
- continue;
42
- }
43
- this._fileCache.set(dirtyFilePath, {
44
- type: "my",
45
- sourceFile,
46
- metadata: new SdMyMetadataReader_1.SdMyMetadataReader(sourceFile, this._program).getMetadatas()
47
- });
48
- changed = true;
49
- }
50
- else if (dirtyFilePath.endsWith(".d.ts")) {
51
- const sourceFile = this._program.getSourceFile(dirtyFilePath);
52
- if (!sourceFile) {
53
- changed = true;
54
- continue;
55
- }
56
- const metadataFilePath = dirtyFilePath.replace(/\.d\.ts$/, ".metadata.json");
57
- const sdMetadataFilePath = dirtyFilePath.replace(/\.d\.ts$/, ".sd-metadata.json");
58
- if (sd_core_node_1.FsUtil.exists(metadataFilePath)) {
59
- const metadataRoot = await sd_core_node_1.FsUtil.readJsonAsync(metadataFilePath);
60
- this._fileCache.set(dirtyFilePath, {
61
- type: "aot",
62
- sourceFile,
63
- ...new SdAotMetadataReader_1.SdAotMetadataReader(metadataRoot).getMetadatas()
64
- });
65
- changed = true;
66
- }
67
- else if (sd_core_node_1.FsUtil.exists(sdMetadataFilePath)) {
68
- const metadataRoot = await sd_core_node_1.FsUtil.readJsonAsync(sdMetadataFilePath);
69
- this._fileCache.set(dirtyFilePath, {
70
- type: "aot",
71
- sourceFile,
72
- ...new SdAotMetadataReader_1.SdAotMetadataReader(metadataRoot).getMetadatas()
73
- });
74
- changed = true;
75
- }
76
- else {
77
- this._fileCache.set(dirtyFilePath, {
78
- type: "ivy",
79
- sourceFile,
80
- ...new SdIvyMetadataReader_1.SdIvyMetadataReader(sourceFile, ngProgram).getMetadatas()
81
- });
82
- changed = true;
83
- }
84
- }
85
- }
86
- catch (err) {
87
- if (err instanceof SdMetadataError_1.SdMetadataError) {
88
- result.push({
89
- filePath: err.fileName,
90
- severity: "error",
91
- message: `${err.fileName}(0, 0): error ${err.message}`
92
- });
93
- }
94
- else {
95
- if (err instanceof Error) {
96
- throw new sd_core_common_1.SdError(err, "'" + dirtyFilePath + "' 메타데이터 로딩중 에러");
97
- }
98
- else {
99
- throw err;
100
- }
101
- }
102
- }
103
- }
104
- return { result, changed };
105
- }
106
- async generateAsync() {
107
- try {
108
- let moduleInfoMap = this._getModuleInfoMap();
109
- moduleInfoMap = this._mergeCircularModuleInfoMap(moduleInfoMap);
110
- const routingModuleMap = await this._getRoutingModuleInfoMapAsync();
111
- const changedFilePaths = [
112
- ...await this._writeNgModuleFileAsync(moduleInfoMap),
113
- ...await this._writeRoutingModuleFileAsync(moduleInfoMap, routingModuleMap)
114
- ];
115
- const genFilePaths = [...moduleInfoMap.keys(), ...routingModuleMap.keys()].distinct();
116
- const delFilePaths = (await sd_core_node_1.FsUtil.globAsync(path.resolve(this._moduleDistDirPath, "**", "*")))
117
- .filter((item) => (!genFilePaths.includes(sd_core_node_1.PathUtil.posix(item))
118
- && !genFilePaths.some((item1) => sd_core_node_1.PathUtil.isChildPath(item1, item))))
119
- .map((item) => sd_core_node_1.PathUtil.posix(item));
120
- for (const delFilePath of delFilePaths) {
121
- changedFilePaths.push(delFilePath);
122
- await sd_core_node_1.FsUtil.removeAsync(delFilePath);
123
- }
124
- return { result: [], changedFilePaths: changedFilePaths.distinct() };
125
- }
126
- catch (err) {
127
- if (err instanceof SdMetadataError_1.SdMetadataError) {
128
- return {
129
- result: [{
130
- filePath: err.fileName,
131
- severity: "error",
132
- message: `${err.fileName}(0, 0): error ${err.message}`
133
- }],
134
- changedFilePaths: []
135
- };
136
- }
137
- else if (err instanceof Error) {
138
- throw new sd_core_common_1.SdError(err, "메타데이터 생성중 에러");
139
- }
140
- else {
141
- throw err;
142
- }
143
- }
144
- }
145
- _getModuleInfoMap() {
146
- const moduleInfoMap = new Map();
147
- const ngModuleExportInfos = this._getAllNgModuleExportInfos();
148
- const ngModuleExportMap = ngModuleExportInfos.groupBy((item) => item.exportModuleFilePath + "#" + item.exportName)
149
- .toMap((item) => item.key, (item) => item.values);
150
- for (const filePath of Array.from(this._fileCache.keys())) {
151
- const fileCache = this._fileCache.get(filePath);
152
- if (fileCache.type !== "my")
153
- continue;
154
- for (const metadata of fileCache.metadata) {
155
- if ((metadata.type === "Injectable"
156
- && (metadata.className.endsWith("Provider")
157
- && metadata.providedIn !== "root"))
158
- || (metadata.type === "Directive"
159
- && metadata.className.endsWith("Directive"))
160
- || (metadata.type === "Pipe"
161
- && metadata.className.endsWith("Pipe"))
162
- || (metadata.type === "Component"
163
- && (metadata.className.endsWith("Page")
164
- || metadata.className.endsWith("Component")
165
- || metadata.className.endsWith("Modal")
166
- || metadata.className.endsWith("Control")
167
- || metadata.className.endsWith("PrintTemplate")
168
- || metadata.className.endsWith("Toast")))) {
169
- const newModuleInfo = {
170
- moduleImportMap: new Map(),
171
- imports: [],
172
- exports: [],
173
- providers: [],
174
- className: metadata.className + "Module"
175
- };
176
- if (metadata.type === "Injectable") {
177
- newModuleInfo.providers.push({ moduleFilePath: filePath, name: metadata.className });
178
- }
179
- else {
180
- newModuleInfo.exports.push({ moduleFilePath: filePath, name: metadata.className });
181
- }
182
- const moduleImport = newModuleInfo.moduleImportMap.getOrCreate(filePath, []);
183
- moduleImport.push(metadata.className);
184
- const ngModuleImportInfos = this._getNgModuleImportInfos(metadata, ngModuleExportMap);
185
- for (const ngModuleImportInfo of ngModuleImportInfos) {
186
- newModuleInfo.imports.push({ moduleFilePath: ngModuleImportInfo.filePath, name: ngModuleImportInfo.name });
187
- const moduleImportMapValues = newModuleInfo.moduleImportMap.getOrCreate(ngModuleImportInfo.filePath, []);
188
- moduleImportMapValues.push(ngModuleImportInfo.name);
189
- }
190
- moduleInfoMap.set(this._getNgModulePath(filePath, metadata.className), {
191
- moduleImportMap: Array.from(newModuleInfo.moduleImportMap.entries())
192
- .toMap((item) => item[0], (item) => item[1].distinct()),
193
- className: newModuleInfo.className,
194
- imports: newModuleInfo.imports.distinct(),
195
- exports: newModuleInfo.exports.distinct(),
196
- providers: newModuleInfo.providers.distinct()
197
- });
198
- }
199
- }
200
- }
201
- const changed = this._reloadModuleInfoFileCache(moduleInfoMap);
202
- if (changed) {
203
- return this._getModuleInfoMap();
204
- }
205
- return moduleInfoMap;
206
- }
207
- _reloadModuleInfoFileCache(moduleInfoMap) {
208
- let changed = false;
209
- for (const moduleInfoMapEntry of moduleInfoMap.entries()) {
210
- const moduleFilePath = moduleInfoMapEntry[0];
211
- const moduleInfo = moduleInfoMapEntry[1];
212
- const newFileCache = {
213
- type: "my",
214
- sourceFile: undefined,
215
- metadata: [
216
- {
217
- type: "NgModule",
218
- className: moduleInfo.className,
219
- exports: moduleInfo.exports,
220
- providers: moduleInfo.providers
221
- }
222
- ]
223
- };
224
- const prevFileCache = this._fileCache.get(moduleFilePath);
225
- if (!prevFileCache) {
226
- this._fileCache.set(moduleFilePath, newFileCache);
227
- changed = true;
228
- }
229
- else if (!sd_core_common_1.ObjectUtil.equal(prevFileCache.metadata, newFileCache.metadata, { ignoreArrayIndex: true })) {
230
- prevFileCache.metadata = newFileCache.metadata;
231
- changed = true;
232
- }
233
- }
234
- return changed;
235
- }
236
- _mergeCircularModuleInfoMap(moduleInfoMap) {
237
- const result = sd_core_common_1.ObjectUtil.clone(moduleInfoMap);
238
- const fnMerge = () => {
239
- const moduleFilePaths = Array.from(result.keys()).orderBy().orderBy((item) => item.length);
240
- for (const moduleFilePath of moduleFilePaths) {
241
- const circularFilePaths = this._getModuleInfoMapExportCircular(result, [moduleFilePath]);
242
- if (circularFilePaths.length === 0)
243
- continue;
244
- for (const circularFilePath of circularFilePaths) {
245
- const thisModuleInfo = result.get(moduleFilePath);
246
- const circularModuleInfo = result.get(circularFilePath);
247
- const mergedModuleInfo = sd_core_common_1.ObjectUtil.merge(circularModuleInfo, thisModuleInfo, { arrayProcess: "concat" });
248
- mergedModuleInfo.moduleImportMap.delete(moduleFilePath);
249
- mergedModuleInfo.moduleImportMap.delete(circularFilePath);
250
- mergedModuleInfo.imports.remove((item) => item.moduleFilePath === moduleFilePath && item.name === thisModuleInfo.className);
251
- mergedModuleInfo.imports.remove((item) => item.moduleFilePath === circularFilePath && item.name === circularModuleInfo.className);
252
- result.set(moduleFilePath, mergedModuleInfo);
253
- result.delete(circularFilePath);
254
- this._fileCache.delete(circularFilePath);
255
- for (const otherModuleInfoFilePath of result.keys()) {
256
- const otherModuleInfo = result.get(otherModuleInfoFilePath);
257
- if (otherModuleInfo.moduleImportMap.has(circularFilePath)) {
258
- otherModuleInfo.moduleImportMap.set(moduleFilePath, [
259
- ...otherModuleInfo.moduleImportMap.get(moduleFilePath) ?? [],
260
- thisModuleInfo.className
261
- ].distinct());
262
- otherModuleInfo.moduleImportMap.delete(circularFilePath);
263
- otherModuleInfo.imports.remove((item) => item.moduleFilePath === circularFilePath && item.name === circularModuleInfo.className);
264
- }
265
- }
266
- }
267
- return true;
268
- }
269
- return false;
270
- };
271
- while (fnMerge()) {
272
- }
273
- return result;
274
- }
275
- async _writeNgModuleFileAsync(moduleInfoMap) {
276
- const changedDistFilePaths = [];
277
- for (const distFilePath of moduleInfoMap.keys()) {
278
- const moduleInfo = moduleInfoMap.get(distFilePath);
279
- const moduleImportMap = Array.from(moduleInfo.moduleImportMap.entries())
280
- .map((item) => ({
281
- moduleName: this._getModuleModuleImportName(path.dirname(distFilePath), item[0]),
282
- targetNames: item[1]
283
- }))
284
- .groupBy((item) => item.moduleName)
285
- .toMap((item) => item.key, (item) => item.values.mapMany((v) => v.targetNames).distinct());
286
- moduleImportMap.getOrCreate("@angular/core", []).push("NgModule");
287
- moduleImportMap.getOrCreate("@angular/common", []).push("CommonModule");
288
- const moduleImportTexts = [];
289
- for (const moduleImportName of Array.from(moduleImportMap.keys()).orderBy()) {
290
- const moduleImportInfo = moduleImportMap.get(moduleImportName).distinct();
291
- if (moduleImportInfo.length === 0)
292
- continue;
293
- moduleImportTexts.push(`import { ${moduleImportInfo.join(", ")} } from "${moduleImportName}";`);
294
- }
295
- const content = `
296
- ${moduleImportTexts.join(os.EOL)}
297
-
298
- @NgModule({
299
- imports: [${moduleInfo.imports.map((item) => item.name).concat(["CommonModule"]).distinct().orderBy().join(", ")}],
300
- declarations: [${moduleInfo.exports.map((item) => item.name).distinct().orderBy().join(", ")}],
301
- exports: [${moduleInfo.exports.map((item) => item.name).distinct().orderBy().join(", ")}],
302
- providers: [${moduleInfo.providers.map((item) => item.name).distinct().orderBy().join(", ")}]
303
- })
304
- export class ${moduleInfo.className} {
305
- }`.split("\n").map((item) => item.trimEnd()).join(os.EOL).trim();
306
- if (!sd_core_node_1.FsUtil.exists(distFilePath) || await sd_core_node_1.FsUtil.readFileAsync(distFilePath) !== content) {
307
- await sd_core_node_1.FsUtil.writeFileAsync(distFilePath, content);
308
- changedDistFilePaths.push(distFilePath);
309
- }
310
- }
311
- return changedDistFilePaths;
312
- }
313
- _getNgModuleImportInfos(metadata, ngModuleExportMap) {
314
- const importTargets = [];
315
- for (const metadataModuleImport of metadata.moduleImports) {
316
- importTargets.push({
317
- filePath: metadataModuleImport.moduleFilePath,
318
- name: metadataModuleImport.name
319
- });
320
- }
321
- if ("template" in metadata && !sd_core_common_1.StringUtil.isNullOrEmpty(metadata.template)) {
322
- const selectorInfos = this._getAllSelectorInfos();
323
- const templateDOM = new jsdom_1.JSDOM(metadata.template);
324
- for (const selectorInfo of selectorInfos) {
325
- if (templateDOM.window.document.querySelector([
326
- selectorInfo.selector,
327
- selectorInfo.selector.replace(/\[/g, "[\\[").replace(/]/g, "\\]]"),
328
- selectorInfo.selector.replace(/\[/g, "[\\(").replace(/]/g, "\\)]")
329
- ].join(", ")) != null) {
330
- importTargets.push({ filePath: selectorInfo.filePath, name: selectorInfo.className });
331
- }
332
- }
333
- const pipeInfos = this._getAllPipeInfos();
334
- for (const pipeInfo of pipeInfos) {
335
- if (new RegExp("| *" + pipeInfo.name + "[^\\w]").test(metadata.template)) {
336
- importTargets.push({ filePath: pipeInfo.filePath, name: pipeInfo.className });
337
- }
338
- }
339
- }
340
- const result = [];
341
- for (const importTarget of importTargets) {
342
- const ngModules = ngModuleExportMap.get(importTarget.filePath + "#" + importTarget.name);
343
- if (ngModules) {
344
- if (ngModules.length !== 1)
345
- throw new sd_core_common_1.NeverEntryError();
346
- result.push({ filePath: ngModules[0].filePath, name: ngModules[0].className });
347
- }
348
- }
349
- return result;
350
- }
351
- _getAllNgModuleExportInfos() {
352
- const result = [];
353
- for (const filePath of this._fileCache.keys()) {
354
- const fileCache = this._fileCache.get(filePath);
355
- if (fileCache.type === "my") {
356
- const ngModules = fileCache.metadata.filter((item) => item.type === "NgModule");
357
- for (const ngModule of ngModules) {
358
- for (const exp of ngModule.exports.concat(ngModule.providers)) {
359
- result.push({
360
- moduleName: undefined,
361
- filePath,
362
- className: ngModule.className,
363
- exportModuleFilePath: exp.moduleFilePath,
364
- exportName: exp.name
365
- });
366
- }
367
- }
368
- }
369
- else if (fileCache.type === "aot") {
370
- const ngModules = fileCache.metadata.filter((item) => item.type === "NgModule");
371
- for (const ngModule of ngModules) {
372
- for (const exp of ngModule.exports.concat(ngModule.providers)) {
373
- if (!sd_core_common_1.StringUtil.isNullOrEmpty(exp.moduleName)) {
374
- const newExp = this._getAotReferenceLastFilePath(filePath, exp.moduleName, exp.name);
375
- if (!newExp)
376
- throw new sd_core_common_1.NeverEntryError();
377
- result.push({
378
- moduleName: fileCache.moduleName,
379
- filePath,
380
- className: ngModule.className,
381
- exportModuleFilePath: newExp.moduleFilePath,
382
- exportName: newExp.name
383
- });
384
- }
385
- else {
386
- if (!fileCache.exports.some((item) => (item.as ?? item.name) === exp.name))
387
- throw new sd_core_common_1.NeverEntryError();
388
- result.push({
389
- moduleName: fileCache.moduleName,
390
- filePath,
391
- className: ngModule.className,
392
- exportModuleFilePath: filePath,
393
- exportName: exp.name
394
- });
395
- }
396
- }
397
- }
398
- }
399
- else {
400
- const ngModules = fileCache.metadata.filter((item) => item.type === "NgModule");
401
- for (const ngModule of ngModules) {
402
- for (const exp of ngModule.exports) {
403
- result.push({
404
- moduleName: fileCache.moduleName,
405
- filePath,
406
- className: ngModule.className,
407
- exportModuleFilePath: exp.moduleFilePath,
408
- exportName: exp.name
409
- });
410
- }
411
- }
412
- }
413
- }
414
- return result.distinct();
415
- }
416
- _getModuleInfoMapExportCircular(moduleInfoMap, arr) {
417
- if (moduleInfoMap.has(arr.last())) {
418
- const moduleInfo = moduleInfoMap.get(arr.last());
419
- const result = [];
420
- for (const moduleImportFilePath of moduleInfo.moduleImportMap.keys()) {
421
- if (arr.includes(moduleImportFilePath)) {
422
- if (arr[0] === moduleImportFilePath) {
423
- result.push(...arr.slice(1));
424
- }
425
- }
426
- else {
427
- result.push(...this._getModuleInfoMapExportCircular(moduleInfoMap, arr.concat([moduleImportFilePath])));
428
- }
429
- }
430
- return result.distinct();
431
- }
432
- else {
433
- return [];
434
- }
435
- }
436
- _getNgModulePath(pageFilePath, pageClassName) {
437
- return sd_core_node_1.PathUtil.posix(this._getGenNgModuleDistPath(pageFilePath), pageClassName + "Module.ts");
438
- }
439
- _getAotReferenceLastFilePath(filePath, moduleName, targetName) {
440
- const expFilePath = this._getResolvedFilePath(filePath, moduleName);
441
- if (sd_core_common_1.StringUtil.isNullOrEmpty(expFilePath))
442
- throw new sd_core_common_1.NeverEntryError();
443
- const expFileCache = this._fileCache.get(expFilePath);
444
- if (!expFileCache) {
445
- this._fileCache.get(expFilePath.replace(/[\\/]/g, "\\"));
446
- throw new SdMetadataError_1.SdMetadataError(filePath, `'${moduleName}'에 대한 파일 '${expFilePath}'을 찾을 수 없습니다.`);
447
- }
448
- if (expFileCache.type !== "aot")
449
- throw new sd_core_common_1.NeverEntryError();
450
- const newExp = expFileCache.exports.single((item) => (item.as ?? item.name) === targetName);
451
- if (!newExp)
452
- throw new sd_core_common_1.NeverEntryError();
453
- if (!sd_core_common_1.StringUtil.isNullOrEmpty(newExp.moduleName)) {
454
- return this._getAotReferenceLastFilePath(expFilePath, newExp.moduleName, newExp.name);
455
- }
456
- else {
457
- return {
458
- moduleFilePath: expFilePath,
459
- name: newExp.as ?? newExp.name
460
- };
461
- }
462
- }
463
- _getAllSelectorInfos() {
464
- const result = [];
465
- for (const filePath of this._fileCache.keys()) {
466
- const fileCache = this._fileCache.get(filePath);
467
- const selectorMetadata = fileCache.metadata
468
- .filter((item) => item.type === "Component" || item.type === "Directive");
469
- for (const selectorMetadataItem of selectorMetadata) {
470
- if (sd_core_common_1.StringUtil.isNullOrEmpty(selectorMetadataItem.selector))
471
- continue;
472
- result.push(({
473
- selector: selectorMetadataItem.selector,
474
- className: selectorMetadataItem.className,
475
- filePath
476
- }));
477
- }
478
- }
479
- return result;
480
- }
481
- _getAllPipeInfos() {
482
- const result = [];
483
- for (const filePath of this._fileCache.keys()) {
484
- const fileCache = this._fileCache.get(filePath);
485
- const pipeMetadata = fileCache.metadata
486
- .filter((item) => item.type === "Component" || item.type === "Directive");
487
- for (const pipeMetadataItem of pipeMetadata) {
488
- if (sd_core_common_1.StringUtil.isNullOrEmpty(pipeMetadataItem.name))
489
- continue;
490
- result.push(({
491
- name: pipeMetadataItem.name,
492
- className: pipeMetadataItem.className,
493
- filePath
494
- }));
495
- }
496
- }
497
- return result;
498
- }
499
- _getModuleModuleImportName(distDirPath, filePath) {
500
- const fileCache = this._fileCache.get(filePath);
501
- const presetModuleName = !fileCache || fileCache.type === "my" ? undefined : fileCache.moduleName;
502
- if (!sd_core_common_1.StringUtil.isNullOrEmpty(presetModuleName))
503
- return presetModuleName;
504
- const relativeFilePath = sd_core_node_1.PathUtil.posix(path.relative(distDirPath, filePath));
505
- return (relativeFilePath.startsWith(".") ? relativeFilePath : "./" + relativeFilePath)
506
- .replace(/\.ts$/, "")
507
- .replace(/\\/g, "/");
508
- }
509
- _getResolvedFilePath(sourceFilePath, moduleName) {
510
- const resolvedModule = ts.resolveModuleName(moduleName, sourceFilePath, this._program.getCompilerOptions(), this._compilerHost, this._moduleResolutionCache).resolvedModule;
511
- if (resolvedModule) {
512
- return sd_core_node_1.PathUtil.posix(resolvedModule.resolvedFileName);
513
- }
514
- return undefined;
515
- }
516
- _getGenNgModuleDistPath(filePath) {
517
- return path.resolve(this._moduleDistDirPath, path.relative(this._sourceDirPath, path.dirname(filePath)));
518
- }
519
- async _getRoutingModuleInfoMapAsync() {
520
- const result = new Map();
521
- for (const filePath of Array.from(this._fileCache.keys())) {
522
- const fileCache = this._fileCache.get(filePath);
523
- if (fileCache.type !== "my")
524
- continue;
525
- for (const metadata of fileCache.metadata) {
526
- if (!metadata.className.endsWith("Page"))
527
- continue;
528
- const newRoutingModuleInfo = {
529
- path: "",
530
- page: {
531
- moduleFilePath: filePath,
532
- name: metadata.className
533
- },
534
- children: []
535
- };
536
- const childDirName = sd_core_common_1.StringUtil.toKebabCase(path.basename(filePath, path.extname(filePath)).replace(/Page$/, ""));
537
- const childDirPath = path.resolve(path.dirname(filePath), childDirName);
538
- if (sd_core_node_1.FsUtil.exists(childDirPath)) {
539
- newRoutingModuleInfo.children = await this._getRoutingModuleChildInfoAsync(childDirPath);
540
- }
541
- result.set(this._getRoutingModulePath(filePath, metadata.className), newRoutingModuleInfo);
542
- }
543
- }
544
- return result;
545
- }
546
- async _getRoutingModuleChildInfoAsync(childDirPath) {
547
- const result = [];
548
- const childDirChildPaths = (await sd_core_node_1.FsUtil.readdirAsync(childDirPath)).map((item) => path.resolve(childDirPath, item));
549
- const ignoreDirPaths = [];
550
- for (const childDirChildPath of childDirChildPaths) {
551
- if (childDirChildPath.endsWith("Page.ts")) {
552
- const childDirChildDirName = sd_core_common_1.StringUtil.toKebabCase(path.basename(childDirChildPath, path.extname(childDirChildPath)).replace(/Page$/, ""));
553
- result.push({
554
- path: childDirChildDirName,
555
- page: {
556
- moduleFilePath: childDirChildPath,
557
- name: path.basename(childDirChildPath, path.extname(childDirChildPath))
558
- }
559
- });
560
- ignoreDirPaths.push(path.resolve(path.dirname(childDirChildPath), childDirChildDirName));
561
- }
562
- }
563
- for (const childDirChildPath of childDirChildPaths) {
564
- if (sd_core_node_1.FsUtil.isDirectory(childDirChildPath) && !ignoreDirPaths.includes(childDirChildPath)) {
565
- result.push({
566
- path: path.basename(childDirChildPath),
567
- children: await this._getRoutingModuleChildInfoAsync(childDirChildPath)
568
- });
569
- }
570
- }
571
- return result;
572
- }
573
- async _writeRoutingModuleFileAsync(moduleInfoMap, routingModuleInfoMap) {
574
- const changedDistFilePaths = [];
575
- for (const distFilePath of routingModuleInfoMap.keys()) {
576
- const routingModuleInfo = routingModuleInfoMap.get(distFilePath);
577
- const routingModuleText = this._getRoutingModuleText(routingModuleInfo, distFilePath);
578
- const moduleImportTexts = [];
579
- const pageFilePath = this._getModuleModuleImportName(path.dirname(distFilePath), routingModuleInfo.page.moduleFilePath);
580
- let content;
581
- if (path.basename(distFilePath) === "_routes.ts") {
582
- moduleImportTexts.push(`import { Routes } from "@angular/router";`);
583
- content = `
584
- ${moduleImportTexts.join(os.EOL)}
585
-
586
- export const routes: Routes = [
587
- ${routingModuleText.replace(/\r\n/g, "\r\n ")}
588
- ];`.split("\n").map((item) => item.trimEnd()).join(os.EOL).trim();
589
- }
590
- else {
591
- moduleImportTexts.push(`import { NgModule } from "@angular/core";`);
592
- moduleImportTexts.push(`import { RouterModule } from "@angular/router";`);
593
- if (path.basename(distFilePath) !== "_routes.ts") {
594
- moduleImportTexts.push(`import { SdCanDeactivateGuardProvider } from "@simplysm/sd-angular";`);
595
- }
596
- moduleImportTexts.push(`import { ${routingModuleInfo.page.name} } from "${pageFilePath}";`);
597
- const thisPageModuleInfoEntry = Array.from(moduleInfoMap.entries())
598
- .single((item) => item[1].exports.some((exp) => exp.moduleFilePath === routingModuleInfo.page.moduleFilePath && exp.name === routingModuleInfo.page.name));
599
- if (!thisPageModuleInfoEntry)
600
- throw new sd_core_common_1.NeverEntryError();
601
- const thisPageModuleInfo = {
602
- filePath: thisPageModuleInfoEntry[0],
603
- className: thisPageModuleInfoEntry[1].className
604
- };
605
- const pageNgModuleFilePath = this._getModuleModuleImportName(path.dirname(distFilePath), thisPageModuleInfo.filePath);
606
- moduleImportTexts.push(`import { ${thisPageModuleInfo.className} } from "${pageNgModuleFilePath}";`);
607
- content = `
608
- ${moduleImportTexts.join(os.EOL)}
609
-
610
- @NgModule({
611
- imports: [
612
- ${thisPageModuleInfo.className},
613
- RouterModule.forChild([
614
- ${routingModuleText.replace(/\r\n/g, "\r\n ")}
615
- ])
616
- ]
617
- })
618
- export class ${routingModuleInfo.page.name}RoutingModule {
619
- }`.split("\n").map((item) => item.trimEnd()).join(os.EOL).trim();
620
- }
621
- if (!sd_core_node_1.FsUtil.exists(distFilePath) || await sd_core_node_1.FsUtil.readFileAsync(distFilePath) !== content) {
622
- await sd_core_node_1.FsUtil.writeFileAsync(distFilePath, content);
623
- changedDistFilePaths.push(distFilePath);
624
- }
625
- }
626
- return changedDistFilePaths;
627
- }
628
- _getRoutingModulePath(pageFilePath, pageClassName) {
629
- if (pageFilePath === sd_core_node_1.PathUtil.posix(this._sourceDirPath, "AppPage.ts")) {
630
- return sd_core_node_1.PathUtil.posix(this._sourceDirPath, "_routes.ts");
631
- }
632
- else {
633
- return sd_core_node_1.PathUtil.posix(this._getGenNgModuleDistPath(pageFilePath), pageClassName + "RoutingModule.ts");
634
- }
635
- }
636
- _getRoutingModuleText(routingModuleInfo, distFilePath) {
637
- let content = "{\r\n";
638
- content += ` path: "${routingModuleInfo.path}",\r\n`;
639
- if (path.basename(distFilePath) !== "_routes.ts") {
640
- content += ` component: ${routingModuleInfo.page.name},\r\n`;
641
- content += ` canDeactivate: [SdCanDeactivateGuardProvider],\r\n`;
642
- }
643
- if (routingModuleInfo.children.length > 0) {
644
- content += ` children: [\r\n`;
645
- for (const child of routingModuleInfo.children) {
646
- const childText = this._getRoutingModuleChildText(child, path.dirname(distFilePath));
647
- content += " " + childText.replace(/\r\n/g, "\r\n ") + ",\r\n";
648
- }
649
- content = content.slice(0, -3) + "\r\n";
650
- content += ` ],\r\n`;
651
- }
652
- return content.slice(0, -3) + "\r\n}";
653
- }
654
- _getRoutingModuleChildText(routingModuleChildInfo, distDirPath) {
655
- let content = "{\r\n";
656
- content += ` path: "${routingModuleChildInfo.path}",\r\n`;
657
- if (routingModuleChildInfo.page) {
658
- const routingModuleFilePath = this._getRoutingModulePath(routingModuleChildInfo.page.moduleFilePath, routingModuleChildInfo.page.name);
659
- const moduleDirPath = "./" + sd_core_node_1.PathUtil.posix(path.dirname(path.relative(distDirPath, routingModuleFilePath)));
660
- content += ` loadChildren: async () => await import("${moduleDirPath}/${routingModuleChildInfo.page.name}RoutingModule").then((m) => m.${routingModuleChildInfo.page.name}RoutingModule),\r\n`;
661
- }
662
- else if (routingModuleChildInfo.children && routingModuleChildInfo.children.length > 0) {
663
- content += ` children: [\r\n`;
664
- for (const child of routingModuleChildInfo.children) {
665
- const childText = this._getRoutingModuleChildText(child, distDirPath);
666
- content += " " + childText.replace(/\r\n/g, "\r\n ") + ",\r\n";
667
- }
668
- content = content.slice(0, -3) + "\r\n";
669
- content += ` ],\r\n`;
670
- }
671
- return content.slice(0, -3) + "\r\n}";
672
- }
673
- }
674
- exports.SdCliNgModuleFilesGenerator = SdCliNgModuleFilesGenerator;
675
- //# sourceMappingURL=SdCliNgModuleFilesGenerator.js.map