@simplysm/sd-cli 6.4.3 → 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 -58
  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 -144
  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 -637
  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 -240
  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 -794
  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,794 +0,0 @@
1
- import { EventEmitter } from "events";
2
- import {
3
- INpmConfig,
4
- ISdClientCordovaPlatformConfig,
5
- ISdClientPackageConfig,
6
- ISdPackageBuildResult,
7
- ITsconfig,
8
- TSdClientPlatformConfig
9
- } from "../commons";
10
- import * as webpack from "webpack";
11
- import * as path from "path";
12
- import * as ts from "typescript";
13
- import { FsUtil, Logger, PathUtil, SdProcessWorker } from "@simplysm/sd-core-node";
14
- import {
15
- JavaScriptOptimizerPlugin
16
- } from "@angular-devkit/build-angular/src/webpack/plugins/javascript-optimizer-plugin";
17
- import * as CssMinimizerPlugin from "css-minimizer-webpack-plugin";
18
- import * as esbuild from "esbuild";
19
- import {
20
- CommonJsUsageWarnPlugin,
21
- DedupeModuleResolvePlugin,
22
- SuppressExtractedTextChunksWebpackPlugin
23
- } from "@angular-devkit/build-angular/src/webpack/plugins";
24
- import { LicenseWebpackPlugin } from "license-webpack-plugin";
25
- import { SassWorkerImplementation } from "@angular-devkit/build-angular/src/sass/sass-service";
26
- import * as MiniCssExtractPlugin from "mini-css-extract-plugin";
27
- import { AngularWebpackPlugin } from "@ngtools/webpack";
28
- import { SdWebpackUtil } from "../utils/SdWebpackUtil";
29
- import { IndexHtmlWebpackPlugin } from "@angular-devkit/build-angular/src/webpack/plugins/index-html-webpack-plugin";
30
- import * as CopyWebpackPlugin from "copy-webpack-plugin";
31
- import { NextHandleFunction } from "connect";
32
- import { HmrLoader } from "@angular-devkit/build-angular/src/webpack/plugins/hmr/hmr-loader";
33
- import * as WebpackDevMiddleware from "webpack-dev-middleware";
34
- import { StringUtil, Wait } from "@simplysm/sd-core-common";
35
- import { augmentAppWithServiceWorker } from "@angular-devkit/build-angular/src/utils/service-worker";
36
- import * as browserslist from "browserslist";
37
- import * as WebpackHotMiddleware from "webpack-hot-middleware";
38
- import * as os from "os";
39
- import { LintResult } from "eslint-webpack-plugin/declarations/options";
40
- import { SdCliCordova } from "../build-tools/SdCliCordova";
41
- import * as JSZip from "jszip";
42
-
43
- // eslint-disable-next-line @typescript-eslint/naming-convention
44
- const ESLintWebpackPlugin = require("eslint-webpack-plugin");
45
-
46
- export class SdCliNgClientBuilder extends EventEmitter {
47
- public parsedTsconfig: ts.ParsedCommandLine;
48
- public readonly npmConfig: INpmConfig;
49
-
50
- private _ngGenWorker?: SdProcessWorker;
51
-
52
- protected readonly _logger: Logger;
53
-
54
- private get _platformConfig(): TSdClientPlatformConfig {
55
- return this.config.platforms!.single((item) => item.type === this.platformType)!;
56
- }
57
-
58
- public constructor(public rootPath: string,
59
- public tsconfigFilePath: string,
60
- public projectRootPath: string,
61
- public config: ISdClientPackageConfig,
62
- public platformType: TSdClientPlatformConfig["type"],
63
- public skipProcesses: ("lint" | "genNgModule")[]) {
64
- super();
65
-
66
- const tsconfig: ITsconfig = FsUtil.readJson(this.tsconfigFilePath);
67
- this.parsedTsconfig = ts.parseJsonConfigFileContent(tsconfig, ts.sys, this.rootPath, tsconfig.angularCompilerOptions);
68
-
69
- this.npmConfig = FsUtil.readJson(path.resolve(this.rootPath, "package.json"));
70
-
71
- this._logger = Logger.get(["simplysm", "sd-cli", this.constructor.name, this.npmConfig.name]);
72
- }
73
-
74
- public on(event: "change", listener: () => void): this;
75
- public on(event: "complete", listener: (results: ISdPackageBuildResult[]) => void): this;
76
- public on(event: string | symbol, listener: (...args: any[]) => void): this {
77
- return super.on(event, listener);
78
- }
79
-
80
- public async buildAsync(): Promise<void> {
81
- this.emit("change");
82
-
83
- await FsUtil.removeAsync(this.parsedTsconfig.options.outDir!);
84
-
85
- const buildResult: ISdPackageBuildResult[] = [];
86
-
87
- // CORDOVA 초기화
88
- const cordova = this.platformType !== "cordova" ? undefined
89
- : new SdCliCordova(this.rootPath, this._platformConfig as ISdClientCordovaPlatformConfig);
90
- if (cordova) {
91
- await cordova.initializeAsync();
92
- }
93
-
94
- // GENERATOR
95
- if (!this.skipProcesses.includes("genNgModule")) {
96
- this._logger.debug("NgGen 수행");
97
- const genResult = await this._runNgGenWorkerAsync(false);
98
- buildResult.push(...genResult.result);
99
- this._logger.debug("NgGen 수행 결과", genResult);
100
- }
101
-
102
- // WEBPACK 빌드
103
- this._logger.debug("Webpack 빌드 수행");
104
- const webpackConfig = this._getWebpackConfig(false);
105
- const compiler = webpack(webpackConfig);
106
- const webpackBuildResults = await new Promise<ISdPackageBuildResult[]>((resolve, reject) => {
107
- compiler.run(async (err, stat) => {
108
- if (err != null) {
109
- reject(err);
110
- return;
111
- }
112
-
113
- if (cordova) {
114
- await cordova.buildAsync(this.parsedTsconfig.options.outDir!);
115
-
116
- const platformConfig = this._platformConfig as ISdClientCordovaPlatformConfig;
117
-
118
- const zip = new JSZip();
119
- const resultFiles = await FsUtil.globAsync(path.resolve(this.rootPath, ".cordova", "www", "**/*"), {
120
- dot: true,
121
- nodir: true
122
- });
123
- for (const resultFile of resultFiles) {
124
- const contentBuffer = await FsUtil.readFileBufferAsync(resultFile);
125
-
126
- const relativePath = path.relative(path.resolve(this.rootPath, ".cordova", "www"), resultFile);
127
- zip.file("/" + relativePath, contentBuffer);
128
- }
129
-
130
- const zipFileName = path.basename(`${platformConfig.appName}-v${this.npmConfig.version}.zip`);
131
- const resultBuffer = await zip.generateAsync({ type: "nodebuffer" });
132
-
133
- await FsUtil.writeFileAsync(path.resolve(this.parsedTsconfig.options.outDir!, "updates/", zipFileName), resultBuffer);
134
- }
135
-
136
- const results = SdWebpackUtil.getWebpackResults(stat!);
137
- resolve(results);
138
- });
139
- });
140
- this._logger.debug("Webpack 빌드 결과", webpackBuildResults);
141
- buildResult.push(...webpackBuildResults);
142
-
143
- // .config.json 파일 쓰기
144
-
145
- const targetPath = path.resolve(this.parsedTsconfig.options.outDir!, ".config.json");
146
- await FsUtil.writeFileAsync(targetPath, JSON.stringify(this.config.configs ?? {}, undefined, 2));
147
-
148
- // service-worker 처리
149
-
150
- if (FsUtil.exists(path.resolve(this.rootPath, "ngsw-config.json"))) {
151
- const packageKey = this.npmConfig.name.split("/").last()!;
152
- await augmentAppWithServiceWorker(
153
- PathUtil.posix(this.projectRootPath) as any,
154
- PathUtil.posix(path.relative(this.projectRootPath, this.rootPath)) as any,
155
- PathUtil.posix(path.relative(this.projectRootPath, this.parsedTsconfig.options.outDir!)) as any,
156
- `/${packageKey}/`,
157
- PathUtil.posix(path.relative(this.projectRootPath, path.resolve(this.rootPath, "ngsw-config.json")))
158
- );
159
- }
160
-
161
- this.emit("complete", buildResult.distinct());
162
- }
163
-
164
- public async watchAsync(serverPath?: string): Promise<NextHandleFunction[]> {
165
- await FsUtil.removeAsync(this.parsedTsconfig.options.outDir!);
166
-
167
- const ngGenResultsMap = new Map<string, ISdPackageBuildResult[]>();
168
- const addNgGenResults = (r: ISdPackageBuildResult[]): void => {
169
- for (const item of r) {
170
- const arr = ngGenResultsMap.getOrCreate(item.filePath !== undefined ? PathUtil.posix(item.filePath) : "undefined", []);
171
- arr.push(item);
172
- }
173
- };
174
- const removeNgGenResults = (filePaths: string[]): void => {
175
- for (const filePath of filePaths) {
176
- ngGenResultsMap.delete(PathUtil.posix(filePath));
177
- }
178
- };
179
- const getNgGenResults = (): ISdPackageBuildResult[] => {
180
- return Array.from(ngGenResultsMap.values()).mapMany().distinct();
181
- };
182
-
183
- // CORDOVA 초기화
184
- const cordova = this.platformType !== "cordova" ? undefined
185
- : new SdCliCordova(this.rootPath, this._platformConfig as ISdClientCordovaPlatformConfig);
186
- if (cordova) {
187
- await cordova.initializeAsync();
188
- }
189
-
190
- // WEBPACK 빌드
191
- let invalidFiles = new Set<string>();
192
- const webpackConfig = this._getWebpackConfig(true);
193
- const compiler = webpack(webpackConfig);
194
- return await new Promise<NextHandleFunction[]>((resolve, reject) => {
195
- compiler.hooks.invalid.tap(this.constructor.name, (fileName) => {
196
- if (fileName != null) {
197
- invalidFiles.add(fileName);
198
- }
199
- });
200
-
201
- compiler.hooks.watchRun.tapAsync(this.constructor.name, async (compiler1, callback) => {
202
- this.emit("change");
203
-
204
- // -- FIRST
205
-
206
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition,@typescript-eslint/strict-boolean-expressions
207
- if (invalidFiles.size === 0) {
208
- if (!this.skipProcesses.includes("genNgModule")) {
209
- this._logger.debug("첫 NgGen 수행");
210
- const genResult = await this._runNgGenWorkerAsync(true);
211
- addNgGenResults(genResult.result);
212
- this._logger.debug("첫 NgGen 수행 결과", genResult);
213
- }
214
-
215
- this._logger.debug("Webpack 빌드 수행");
216
- callback();
217
- }
218
-
219
- // -- NOT FIRST
220
- else {
221
- // 변경파일 중, 유효한 파일 추출
222
- const changedFiles = [...invalidFiles];
223
- invalidFiles = new Set<string>();
224
-
225
- const changedFilePaths = changedFiles
226
- .map((item) => PathUtil.posix(item))
227
- .filter((item) => path.basename(item).includes("."))
228
- .distinct();
229
- if (changedFilePaths.length === 0) {
230
- this._logger.debug("Webpack 빌드 수행");
231
- callback();
232
- return;
233
- }
234
- removeNgGenResults(["undefined"]);
235
- removeNgGenResults(changedFilePaths);
236
-
237
- if (!this.skipProcesses.includes("genNgModule")) {
238
- this._logger.debug("변경파일에 대한, NgGen 수행", changedFilePaths);
239
-
240
- const genResult = await this._runNgGenWorkerAsync(true, changedFilePaths);
241
- if (genResult.dirtyFilePaths.length === 0) {
242
- this._logger.debug("변경파일에 대한, NgGen 결과", genResult);
243
- this._logger.debug("Webpack 빌드 수행");
244
- callback();
245
- return;
246
- }
247
- removeNgGenResults(genResult.dirtyFilePaths);
248
- addNgGenResults(genResult.result);
249
-
250
- this._logger.debug("변경파일에 대한, NgGen 결과", genResult);
251
-
252
- const modifiedFiles = [...compiler.modifiedFiles];
253
- const removedFiles = [...compiler.removedFiles];
254
- for (const genFilePath of genResult.dirtyFilePaths.distinct()) {
255
- if (FsUtil.exists(genFilePath)) {
256
- modifiedFiles.push(genFilePath);
257
- }
258
- else {
259
- removedFiles.push(genFilePath);
260
- }
261
- }
262
- compiler.modifiedFiles = new Set(modifiedFiles.distinct());
263
- compiler.removedFiles = new Set(removedFiles.distinct());
264
- }
265
-
266
- this._logger.debug("Webpack 빌드 수행");
267
- callback();
268
- }
269
- });
270
-
271
- // eslint-disable-next-line prefer-const
272
- let devMiddleware: NextHandleFunction | undefined;
273
- // eslint-disable-next-line prefer-const
274
- let hotMiddleware: NextHandleFunction | undefined;
275
-
276
- compiler.hooks.failed.tap(this.constructor.name, (err) => {
277
- const results = SdWebpackUtil.getWebpackResults(err);
278
- const allResults = [...getNgGenResults(), ...results].distinct();
279
- this.emit("complete", allResults);
280
- this._logger.debug("Webpack 빌드 수행 결과", allResults);
281
- reject(err);
282
- });
283
-
284
- compiler.hooks.done.tap("SdCliClientCompiler", async (stats) => {
285
- const results = SdWebpackUtil.getWebpackResults(stats);
286
-
287
- // .config.json 파일 쓰기
288
- const packageKey = this.npmConfig.name.split("/").last()!;
289
- const configDistPath = !StringUtil.isNullOrEmpty(serverPath)
290
- ? path.resolve(serverPath, "dist/www", packageKey, ".config.json")
291
- : path.resolve(this.parsedTsconfig.options.outDir!, ".config.json");
292
- await FsUtil.writeFileAsync(configDistPath, JSON.stringify(this.config.configs ?? {}, undefined, 2));
293
-
294
- /*if (cordova) {
295
- const platformConfig = this._platformConfig as ISdClientCordovaPlatformConfig;
296
-
297
- const zip = new JSZip();
298
- const resultFiles = await FsUtil.globAsync(path.resolve(this.rootPath, ".cordova", "www", "**!/!*"), {
299
- dot: true,
300
- nodir: true
301
- });
302
- for (const resultFile of resultFiles) {
303
- const contentBuffer = await FsUtil.readFileBufferAsync(resultFile);
304
-
305
- const relativePath = path.relative(path.resolve(this.rootPath, ".cordova", "www"), resultFile);
306
- zip.file("/" + relativePath, contentBuffer);
307
- }
308
-
309
- const zipFileName = path.basename(`${platformConfig.appName}-v${this.npmConfig.version}.zip`);
310
- const resultBuffer = await zip.generateAsync({ type: "nodebuffer" });
311
-
312
- await FsUtil.writeFileAsync(path.resolve(this.parsedTsconfig.options.outDir!, "updates/", zipFileName), resultBuffer);
313
- }*/
314
-
315
- await Wait.true(() => devMiddleware !== undefined && hotMiddleware !== undefined);
316
- const allResults = [...getNgGenResults(), ...results].distinct();
317
- this.emit("complete", allResults);
318
- this._logger.debug("Webpack 빌드 수행 결과", allResults);
319
- resolve([devMiddleware!, hotMiddleware!]);
320
- });
321
-
322
- devMiddleware = WebpackDevMiddleware(compiler, {
323
- publicPath: webpackConfig.output!.publicPath as string,
324
- index: "index.html",
325
- headers: { "Access-Control-Allow-Origin": "*" },
326
- stats: false
327
- });
328
-
329
- hotMiddleware = WebpackHotMiddleware(compiler, {
330
- path: `${webpackConfig.output!.publicPath as string}__webpack_hmr`,
331
- log: false
332
- });
333
- });
334
- }
335
-
336
- private _getWebpackConfig(watch: boolean): webpack.Configuration {
337
- const nodeSass = new SassWorkerImplementation();
338
-
339
- const packageKey = this.npmConfig.name.split("/").last()!;
340
-
341
- const distPath = (this.platformType === "cordova" && !watch) ? path.resolve(this.rootPath, ".cordova", "www")
342
- : this.parsedTsconfig.options.outDir;
343
-
344
- const publicPath = (this.platformType === "cordova" && !watch) ? ""
345
- : (this.platformType !== "browser" ? `/__${this.platformType}` : "") + `/${packageKey}/`;
346
-
347
- return {
348
- mode: watch ? "development" : "production",
349
- devtool: false,
350
- target: ["web", "es2015"],
351
- profile: false,
352
- resolve: {
353
- roots: [this.rootPath],
354
- extensions: [".ts", ".js"],
355
- symlinks: true,
356
- // modules: allNodeModulePaths,
357
- mainFields: ["es2015", "browser", "module", "main"],
358
- fallback: this.config.resolveFallback
359
- },
360
- /*resolveLoader: {
361
- symlinks: true,
362
- modules: allNodeModulePaths
363
- },*/
364
- context: this.projectRootPath,
365
- entry: {
366
- main: [
367
- ...watch ? [
368
- `webpack-hot-middleware/client?path=${publicPath}__webpack_hmr&timeout=20000&reload=true&overlay=true`
369
- ] : [],
370
- path.resolve(this.rootPath, "src/main.ts")
371
- ],
372
- polyfills: [
373
- path.resolve(this.rootPath, "src/polyfills.ts")
374
- ],
375
- styles: [
376
- path.resolve(this.rootPath, "src/styles.scss")
377
- ]
378
- },
379
- output: {
380
- clean: true,
381
- path: distPath,
382
- publicPath,
383
- // filename: watch ? "[name].js" : `[name].[chunkhash:20].js`,
384
- // chunkFilename: watch ? "[name].js" : "[name].[chunkhash:20].js",
385
- filename: "[name].js",
386
- chunkFilename: "[name].js",
387
- assetModuleFilename: "resources/[name][ext][query]",
388
- crossOriginLoading: false,
389
- trustedTypes: "angular#bundler"
390
- },
391
- ...watch ? {
392
- watchOptions: { poll: undefined, ignored: "**/$_lazy_route_resources" }
393
- } : {
394
- watch: false
395
- },
396
- performance: { hints: false },
397
- ignoreWarnings: [
398
- /System.import\(\) is deprecated and will be removed soon/i,
399
- /Failed to parse source map from/,
400
- /Add postcss as project dependency/
401
- ],
402
- module: {
403
- strictExportPresence: true,
404
- rules: [
405
- ...watch ? [
406
- {
407
- loader: HmrLoader,
408
- include: [path.resolve(this.rootPath, "src/main.ts")]
409
- }
410
- ] : [],
411
- {
412
- test: /[/\\]@angular[/\\]core[/\\].+\.js$/,
413
- parser: { system: true }
414
- },
415
- {
416
- test: /[/\\]rxjs[/\\]add[/\\].+\.js$/,
417
- sideEffects: true
418
- },
419
- ...watch ? [
420
- {
421
- test: /\.m?js$/,
422
- enforce: "pre",
423
- loader: require.resolve("source-map-loader"),
424
- options: {
425
- filterSourceMappingUrl: (mapUri: string, resourcePath: string) => {
426
- return !resourcePath.includes("node_modules") || (/@simplysm[\\/]sd/).test(resourcePath);
427
- }
428
- }
429
- }
430
- ] as any : [],
431
- /*
432
- {
433
- test: /\.m?js/,
434
- resolve: {
435
- fullySpecified: false
436
- }
437
- },*/
438
- {
439
- test: /\.scss$/i,
440
- rules: [
441
- {
442
- oneOf: [
443
- {
444
- include: path.resolve(this.rootPath, "src/styles.scss"),
445
- use: [
446
- {
447
- loader: MiniCssExtractPlugin.loader
448
- },
449
- {
450
- loader: "css-loader",
451
- options: {
452
- url: false,
453
- sourceMap: watch
454
- }
455
- }
456
- ]
457
- },
458
- {
459
- exclude: path.resolve(this.rootPath, "src/styles.scss"),
460
- type: "asset/source"
461
- }
462
- ]
463
- },
464
- {
465
- use: [
466
- {
467
- loader: "resolve-url-loader",
468
- options: {
469
- sourceMap: watch
470
- }
471
- },
472
- {
473
- loader: "sass-loader",
474
- options: {
475
- implementation: nodeSass,
476
- sourceMap: true,
477
- sassOptions: {
478
- fiber: false,
479
- precision: 8,
480
- includePaths: [],
481
- outputStyle: "expanded",
482
- quietDeps: true,
483
- verbose: false
484
- }
485
- }
486
- }
487
- ]
488
- }
489
- ]
490
- },
491
- {
492
- test: /\.[jt]sx?$/,
493
- loader: "@ngtools/webpack"
494
- },
495
- {
496
- test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|otf|xlsx?|pptx?|docx?|zip|pfx|pkl)$/,
497
- type: "asset/resource"
498
- }
499
- ]
500
- },
501
- experiments: { syncWebAssembly: true, asyncWebAssembly: true },
502
- ...watch ? {
503
- cache: { type: "memory", maxGenerations: 1 },
504
- snapshot: {
505
- immutablePaths: this._findAllInternalModuleCachePaths(),
506
- managedPaths: this._findAllInternalModuleCachePaths()
507
- }
508
- } : {
509
- cache: false
510
- },
511
- optimization: {
512
- minimizer: watch ? [] : [
513
- new JavaScriptOptimizerPlugin({
514
- define: { ngDevMode: false, ngI18nClosureMode: false, ngJitMode: false },
515
- sourcemap: false,
516
- target: this.parsedTsconfig.options.target,
517
- keepNames: true,
518
- removeLicenses: true,
519
- advanced: true
520
- }) as any,
521
- new CssMinimizerPlugin({
522
- test: /\.(css|scss)$/,
523
- exclude: "styles.css",
524
- parallel: false,
525
- minify: async (data: string) => {
526
- const [[sourcefile, input]] = Object.entries(data);
527
- const { code, warnings } = await esbuild.transform(input, {
528
- loader: "css",
529
- minify: true,
530
- sourcefile,
531
- target: browserslist([
532
- "last 2 Chrome versions",
533
- "last 2 Edge major versions"
534
- ]).map((item) => item.replace(/ /g, ""))
535
- });
536
-
537
- return {
538
- code,
539
- warnings:
540
- warnings.length > 0
541
- ? await esbuild.formatMessages(warnings, { kind: "warning" })
542
- : []
543
- };
544
- }
545
- }),
546
- new CssMinimizerPlugin({
547
- test: /\.css$/,
548
- include: "styles.css",
549
- parallel: 4,
550
- minify: [CssMinimizerPlugin.cssnanoMinify],
551
- minimizerOptions: {
552
- preset: [
553
- "default",
554
- {
555
- svgo: false,
556
- calc: false,
557
- cssDeclarationSorter: false,
558
- minifyParams: false
559
- }
560
- ]
561
- }
562
- })
563
- ],
564
- moduleIds: "deterministic",
565
- chunkIds: watch ? "named" : "deterministic",
566
- emitOnErrors: watch,
567
- runtimeChunk: "single",
568
- splitChunks: {
569
- maxAsyncRequests: Infinity,
570
- cacheGroups: {
571
- default: { chunks: "async", minChunks: 2, priority: 10 },
572
- common: {
573
- name: "common",
574
- chunks: "async",
575
- minChunks: 2,
576
- enforce: true,
577
- priority: 5
578
- },
579
- vendors: false,
580
- defaultVendors: watch ? {
581
- name: "vendor",
582
- chunks: (chunk) => chunk.name === "main",
583
- enforce: true,
584
- test: /[\\/]node_modules[\\/]/
585
- } : false
586
- }
587
- }
588
- },
589
- plugins: [
590
- new webpack.ContextReplacementPlugin(
591
- /@angular[\\/]core[\\/]/,
592
- path.join(this.rootPath, "$_lazy_route_resources"),
593
- {}
594
- ),
595
- new DedupeModuleResolvePlugin({ verbose: false }) as any,
596
- new CopyWebpackPlugin({
597
- patterns: [
598
- ...["favicon.ico", "assets/", "manifest.webmanifest"].map((item) => ({
599
- context: this.rootPath,
600
- to: item,
601
- from: `src/${item}`,
602
- noErrorOnMissing: true,
603
- force: true,
604
- globOptions: {
605
- dot: true,
606
- followSymbolicLinks: false,
607
- ignore: [
608
- ".gitkeep",
609
- "**/.DS_Store",
610
- "**/Thumbs.db"
611
- ].map((i) => PathUtil.posix(this.rootPath, i))
612
- },
613
- priority: 0
614
- })),
615
- ...this.platformType === "cordova" ? [
616
- ...(this._platformConfig as ISdClientCordovaPlatformConfig).targets.map((target) => ({
617
- context: this.rootPath,
618
- to: `cordova-${target}`,
619
- from: `.cordova/platforms/${target}/platform_www`
620
- })),
621
- ...watch ? [{
622
- context: this.rootPath,
623
- to: `cordova-browser`,
624
- from: `.cordova/platforms/browser/platform_www`
625
- }] : []
626
- ] : []
627
- ]
628
- }),
629
- ...watch ? [] : [
630
- new LicenseWebpackPlugin({
631
- stats: { warnings: false, errors: false },
632
- perChunkOutput: false,
633
- outputFilename: "3rdpartylicenses.txt",
634
- skipChildCompilers: true
635
- })
636
- ],
637
- new CommonJsUsageWarnPlugin(),
638
- ...watch ? [
639
- new webpack.SourceMapDevToolPlugin({
640
- filename: "[file].map",
641
- include: [/js$/, /css$/],
642
- sourceRoot: "webpack:///",
643
- moduleFilenameTemplate: "[resource-path]",
644
- append: undefined
645
- })
646
- ] : [],
647
- /*new AnyComponentStyleBudgetChecker(watch ? [] : [
648
- {
649
- type: Type.Any,
650
- maximumWarning: "2kb",
651
- maximumError: "4kb"
652
- }
653
- ]),*/
654
- {
655
- apply(compiler) {
656
- compiler.hooks.shutdown.tap("sass-worker", () => {
657
- nodeSass.close();
658
- });
659
- }
660
- },
661
- new MiniCssExtractPlugin({
662
- // filename: watch ? "[name].css" : `[name].[contenthash:20].css`
663
- filename: "[name].css"
664
- }),
665
- ...watch ? [] : [
666
- new SuppressExtractedTextChunksWebpackPlugin()
667
- ],
668
- new AngularWebpackPlugin({
669
- tsconfig: this.tsconfigFilePath,
670
- compilerOptions: this.parsedTsconfig.options,
671
- jitMode: false,
672
- emitNgModuleScope: watch,
673
- inlineStyleFileExtension: "scss"
674
- }),
675
- new IndexHtmlWebpackPlugin({
676
- indexPath: path.resolve(this.rootPath, "src/index.html"),
677
- outputPath: "index.html",
678
- baseHref: publicPath,
679
- entrypoints: [
680
- "runtime",
681
- "polyfills",
682
- "sw-register",
683
- "styles",
684
- "vendor",
685
- "main"
686
- ],
687
- moduleEntrypoints: [],
688
- noModuleEntrypoints: [],
689
- deployUrl: undefined,
690
- sri: false,
691
- postTransform: undefined,
692
- optimization: {
693
- scripts: !watch,
694
- styles: { minify: !watch, inlineCritical: !watch },
695
- fonts: { inline: !watch }
696
- },
697
- WOFFSupportNeeded: false,
698
- crossOrigin: "none",
699
- lang: undefined
700
- }),
701
- new webpack.ProvidePlugin({
702
- "Buffer": ["buffer", "Buffer"]
703
- }),
704
- new webpack.EnvironmentPlugin({
705
- SD_VERSION: this.npmConfig.version,
706
- ...this.config.env
707
- }),
708
- ...!this.skipProcesses.includes("lint") ? [
709
- new ESLintWebpackPlugin({
710
- context: this.rootPath,
711
- eslintPath: path.resolve(this.projectRootPath, "node_modules", "eslint"),
712
- extensions: ["js", "ts"],
713
- exclude: ["node_modules"],
714
- fix: false,
715
- threads: false,
716
- formatter: (results: LintResult[]) => {
717
- const resultMessages: string[] = [];
718
- for (const result of results) {
719
- for (const msg of result.messages) {
720
- resultMessages.push(`${result.filePath}(${msg.line}, ${msg.column}): ${msg.ruleId ?? ""}: ${msg.severity === 1 ? "warning" : msg.severity === 2 ? "error" : ""} ${msg.message}`);
721
- }
722
- }
723
- return resultMessages.join(os.EOL);
724
- }
725
- })
726
- ] : [],
727
- ...watch ? [
728
- new webpack.HotModuleReplacementPlugin()
729
- ] : [],
730
- /*...watch ? [
731
- new webpack.WatchIgnorePlugin({
732
- paths: [
733
- path.resolve(this.rootPath, "src/_modules/"),
734
- path.resolve(this.rootPath, "src/_routes.ts")
735
- ]
736
- })
737
- ] : [],*/
738
- new webpack.ProgressPlugin({
739
- handler: (per: number, msg: string, ...args: string[]) => {
740
- const phaseText = msg ? ` - phase: ${msg}` : "";
741
- const argsText = args.length > 0 ? ` - args: [${args.join(", ")}]` : "";
742
- this._logger.debug(`Webpack 빌드 수행중...(${Math.round(per * 100)}%)${phaseText}${argsText}`);
743
- }
744
- })
745
- ],
746
- node: false,
747
- stats: "errors-warnings"
748
- };
749
- }
750
-
751
- private _findAllInternalModuleCachePaths(): string[] {
752
- return this._findAllNodeModules(this.rootPath, this.projectRootPath)
753
- .mapMany((item) => (
754
- FsUtil.readdir(item)
755
- .filter((item1) => item1 !== "@simplysm")
756
- .map((item1) => path.resolve(item, item1))
757
- ));
758
- }
759
-
760
- private _findAllNodeModules(from: string, root: string): string[] {
761
- const nodeModules: string[] = [];
762
-
763
- let current = from;
764
- while (current) {
765
- const potential = path.join(current, "node_modules");
766
- if (FsUtil.exists(potential) && FsUtil.isDirectory(potential)) {
767
- nodeModules.push(potential);
768
- }
769
-
770
- if (current === root) break;
771
-
772
- const next = path.dirname(current);
773
- if (next === current) break;
774
- current = next;
775
- }
776
-
777
- return nodeModules;
778
- }
779
-
780
- private async _runNgGenWorkerAsync(watch: boolean, changedFilePaths?: string[]): Promise<{ dirtyFilePaths: string[]; result: ISdPackageBuildResult[] }> {
781
- if (!this._ngGenWorker) {
782
- this._ngGenWorker = await SdProcessWorker.createAsync(path.resolve(__dirname, `../workers/client-ng-gen-worker`), []);
783
- }
784
-
785
- const sender = this._ngGenWorker.createWorkSender();
786
- return await new Promise<{ dirtyFilePaths: string[]; result: ISdPackageBuildResult[] }>(async (resolve) => {
787
- await sender
788
- .on("complete", (result) => {
789
- resolve(result);
790
- })
791
- .sendAsync(this.rootPath, watch, changedFilePaths);
792
- });
793
- }
794
- }