@simplysm/sd-cli 6.4.6 → 7.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/.eslintrc.cjs +11 -0
  2. package/dist/bin/sd-cli.d.ts +1 -0
  3. package/dist/bin/sd-cli.mjs +86 -0
  4. package/dist/build-tool/SdCliCacheCompilerHost.d.ts +10 -0
  5. package/dist/build-tool/SdCliCacheCompilerHost.mjs +44 -0
  6. package/dist/build-tool/SdCliNgCacheCompilerHost.d.ts +11 -0
  7. package/dist/build-tool/SdCliNgCacheCompilerHost.mjs +36 -0
  8. package/dist/build-tool/SdCliPackageLinter.d.ts +8 -0
  9. package/dist/build-tool/SdCliPackageLinter.mjs +41 -0
  10. package/dist/builder/SdCliJsLibBuilder.d.ts +14 -0
  11. package/dist/builder/SdCliJsLibBuilder.mjs +50 -0
  12. package/dist/builder/SdCliTsLibBuilder.d.ts +27 -0
  13. package/dist/builder/SdCliTsLibBuilder.mjs +226 -0
  14. package/dist/commons.d.ts +46 -0
  15. package/dist/commons.mjs +2 -0
  16. package/dist/entry-points/SdCliWorkspace.d.ts +18 -0
  17. package/dist/entry-points/SdCliWorkspace.mjs +193 -0
  18. package/dist/packages/SdCliPackage.d.ts +19 -0
  19. package/dist/packages/SdCliPackage.mjs +89 -0
  20. package/dist/utils/SdCliBuildResultUtil.d.ts +6 -0
  21. package/dist/utils/SdCliBuildResultUtil.mjs +38 -0
  22. package/dist/utils/SdCliConfigUtil.d.ts +7 -0
  23. package/dist/utils/SdCliConfigUtil.mjs +69 -0
  24. package/lib/ts-node-esm-paths.mjs +15 -0
  25. package/package.json +27 -59
  26. package/src/bin/sd-cli.ts +86 -214
  27. package/src/build-tool/SdCliCacheCompilerHost.ts +71 -0
  28. package/src/build-tool/SdCliNgCacheCompilerHost.ts +50 -0
  29. package/src/build-tool/SdCliPackageLinter.ts +54 -0
  30. package/src/builder/SdCliJsLibBuilder.ts +66 -0
  31. package/src/builder/SdCliTsLibBuilder.ts +335 -0
  32. package/src/commons.ts +17 -122
  33. package/src/entry-points/SdCliWorkspace.ts +229 -0
  34. package/src/packages/SdCliPackage.ts +111 -0
  35. package/src/utils/SdCliBuildResultUtil.ts +43 -0
  36. package/src/utils/SdCliConfigUtil.ts +94 -0
  37. package/tsconfig-build.json +9 -0
  38. package/tsconfig.json +7 -18
  39. package/.eslintrc.js +0 -19
  40. package/dist-node/bin/sd-cli.js +0 -197
  41. package/dist-node/bin/sd-cli.js.map +0 -1
  42. package/dist-node/build-tools/SdCliCordova.js +0 -145
  43. package/dist-node/build-tools/SdCliCordova.js.map +0 -1
  44. package/dist-node/build-tools/SdCliIndexFileGenerator.js +0 -51
  45. package/dist-node/build-tools/SdCliIndexFileGenerator.js.map +0 -1
  46. package/dist-node/build-tools/SdCliNgModuleFilesGenerator.js +0 -675
  47. package/dist-node/build-tools/SdCliNgModuleFilesGenerator.js.map +0 -1
  48. package/dist-node/build-tools/metadata/SdAotMetadataReader.js +0 -274
  49. package/dist-node/build-tools/metadata/SdAotMetadataReader.js.map +0 -1
  50. package/dist-node/build-tools/metadata/SdIvyMetadataReader.js +0 -124
  51. package/dist-node/build-tools/metadata/SdIvyMetadataReader.js.map +0 -1
  52. package/dist-node/build-tools/metadata/SdMetadataError.js +0 -13
  53. package/dist-node/build-tools/metadata/SdMetadataError.js.map +0 -1
  54. package/dist-node/build-tools/metadata/SdMyMetadataReader.js +0 -321
  55. package/dist-node/build-tools/metadata/SdMyMetadataReader.js.map +0 -1
  56. package/dist-node/builders/SdCliJavascriptLinter.js +0 -65
  57. package/dist-node/builders/SdCliJavascriptLinter.js.map +0 -1
  58. package/dist-node/builders/SdCliNgClientBuilder.js +0 -636
  59. package/dist-node/builders/SdCliNgClientBuilder.js.map +0 -1
  60. package/dist-node/builders/SdCliNgLibraryBuilder.js +0 -217
  61. package/dist-node/builders/SdCliNgLibraryBuilder.js.map +0 -1
  62. package/dist-node/builders/SdCliPublisher.js +0 -129
  63. package/dist-node/builders/SdCliPublisher.js.map +0 -1
  64. package/dist-node/builders/SdCliServerBuilder.js +0 -452
  65. package/dist-node/builders/SdCliServerBuilder.js.map +0 -1
  66. package/dist-node/builders/SdCliTypescriptBuilder.js +0 -347
  67. package/dist-node/builders/SdCliTypescriptBuilder.js.map +0 -1
  68. package/dist-node/commons.js +0 -3
  69. package/dist-node/commons.js.map +0 -1
  70. package/dist-node/entry-points/SdCliLocalUpdater.js +0 -88
  71. package/dist-node/entry-points/SdCliLocalUpdater.js.map +0 -1
  72. package/dist-node/entry-points/SdCliPrepare.js +0 -56
  73. package/dist-node/entry-points/SdCliPrepare.js.map +0 -1
  74. package/dist-node/entry-points/SdCliProject.js +0 -302
  75. package/dist-node/entry-points/SdCliProject.js.map +0 -1
  76. package/dist-node/packages/SdCliClientPackage.js +0 -91
  77. package/dist-node/packages/SdCliClientPackage.js.map +0 -1
  78. package/dist-node/packages/SdCliLibraryPackage.js +0 -99
  79. package/dist-node/packages/SdCliLibraryPackage.js.map +0 -1
  80. package/dist-node/packages/SdCliPackageBase.js +0 -33
  81. package/dist-node/packages/SdCliPackageBase.js.map +0 -1
  82. package/dist-node/packages/SdCliServerPackage.js +0 -69
  83. package/dist-node/packages/SdCliServerPackage.js.map +0 -1
  84. package/dist-node/packages/SdCliUnknownPackage.js +0 -15
  85. package/dist-node/packages/SdCliUnknownPackage.js.map +0 -1
  86. package/dist-node/utils/SdCliFileCrypto.js +0 -76
  87. package/dist-node/utils/SdCliFileCrypto.js.map +0 -1
  88. package/dist-node/utils/SdProjectConfigUtil.js +0 -62
  89. package/dist-node/utils/SdProjectConfigUtil.js.map +0 -1
  90. package/dist-node/utils/SdTsDiagnosticUtil.js +0 -45
  91. package/dist-node/utils/SdTsDiagnosticUtil.js.map +0 -1
  92. package/dist-node/utils/SdWebpackUtil.js +0 -63
  93. package/dist-node/utils/SdWebpackUtil.js.map +0 -1
  94. package/dist-node/workers/client-ng-gen-worker.js +0 -57
  95. package/dist-node/workers/client-ng-gen-worker.js.map +0 -1
  96. package/dist-node/workers/lib-build-worker.js +0 -88
  97. package/dist-node/workers/lib-build-worker.js.map +0 -1
  98. package/dist-types/bin/sd-cli.d.ts +0 -3
  99. package/dist-types/bin/sd-cli.d.ts.map +0 -1
  100. package/dist-types/build-tools/SdCliCordova.d.ts +0 -15
  101. package/dist-types/build-tools/SdCliCordova.d.ts.map +0 -1
  102. package/dist-types/build-tools/SdCliIndexFileGenerator.d.ts +0 -13
  103. package/dist-types/build-tools/SdCliIndexFileGenerator.d.ts.map +0 -1
  104. package/dist-types/build-tools/SdCliNgModuleFilesGenerator.d.ts +0 -43
  105. package/dist-types/build-tools/SdCliNgModuleFilesGenerator.d.ts.map +0 -1
  106. package/dist-types/build-tools/metadata/SdAotMetadataReader.d.ts +0 -58
  107. package/dist-types/build-tools/metadata/SdAotMetadataReader.d.ts.map +0 -1
  108. package/dist-types/build-tools/metadata/SdIvyMetadataReader.d.ts +0 -43
  109. package/dist-types/build-tools/metadata/SdIvyMetadataReader.d.ts.map +0 -1
  110. package/dist-types/build-tools/metadata/SdMetadataError.d.ts +0 -7
  111. package/dist-types/build-tools/metadata/SdMetadataError.d.ts.map +0 -1
  112. package/dist-types/build-tools/metadata/SdMyMetadataReader.d.ts +0 -59
  113. package/dist-types/build-tools/metadata/SdMyMetadataReader.d.ts.map +0 -1
  114. package/dist-types/builders/SdCliJavascriptLinter.d.ts +0 -14
  115. package/dist-types/builders/SdCliJavascriptLinter.d.ts.map +0 -1
  116. package/dist-types/builders/SdCliNgClientBuilder.d.ts +0 -29
  117. package/dist-types/builders/SdCliNgClientBuilder.d.ts.map +0 -1
  118. package/dist-types/builders/SdCliNgLibraryBuilder.d.ts +0 -30
  119. package/dist-types/builders/SdCliNgLibraryBuilder.d.ts.map +0 -1
  120. package/dist-types/builders/SdCliPublisher.d.ts +0 -9
  121. package/dist-types/builders/SdCliPublisher.d.ts.map +0 -1
  122. package/dist-types/builders/SdCliServerBuilder.d.ts +0 -31
  123. package/dist-types/builders/SdCliServerBuilder.d.ts.map +0 -1
  124. package/dist-types/builders/SdCliTypescriptBuilder.d.ts +0 -56
  125. package/dist-types/builders/SdCliTypescriptBuilder.d.ts.map +0 -1
  126. package/dist-types/commons.d.ts +0 -134
  127. package/dist-types/commons.d.ts.map +0 -1
  128. package/dist-types/entry-points/SdCliLocalUpdater.d.ts +0 -12
  129. package/dist-types/entry-points/SdCliLocalUpdater.d.ts.map +0 -1
  130. package/dist-types/entry-points/SdCliPrepare.d.ts +0 -6
  131. package/dist-types/entry-points/SdCliPrepare.d.ts.map +0 -1
  132. package/dist-types/entry-points/SdCliProject.d.ts +0 -32
  133. package/dist-types/entry-points/SdCliProject.d.ts.map +0 -1
  134. package/dist-types/packages/SdCliClientPackage.d.ts +0 -17
  135. package/dist-types/packages/SdCliClientPackage.d.ts.map +0 -1
  136. package/dist-types/packages/SdCliLibraryPackage.d.ts +0 -20
  137. package/dist-types/packages/SdCliLibraryPackage.d.ts.map +0 -1
  138. package/dist-types/packages/SdCliPackageBase.d.ts +0 -11
  139. package/dist-types/packages/SdCliPackageBase.d.ts.map +0 -1
  140. package/dist-types/packages/SdCliServerPackage.d.ts +0 -16
  141. package/dist-types/packages/SdCliServerPackage.d.ts.map +0 -1
  142. package/dist-types/packages/SdCliUnknownPackage.d.ts +0 -9
  143. package/dist-types/packages/SdCliUnknownPackage.d.ts.map +0 -1
  144. package/dist-types/utils/SdCliFileCrypto.d.ts +0 -8
  145. package/dist-types/utils/SdCliFileCrypto.d.ts.map +0 -1
  146. package/dist-types/utils/SdProjectConfigUtil.d.ts +0 -7
  147. package/dist-types/utils/SdProjectConfigUtil.d.ts.map +0 -1
  148. package/dist-types/utils/SdTsDiagnosticUtil.d.ts +0 -6
  149. package/dist-types/utils/SdTsDiagnosticUtil.d.ts.map +0 -1
  150. package/dist-types/utils/SdWebpackUtil.d.ts +0 -7
  151. package/dist-types/utils/SdWebpackUtil.d.ts.map +0 -1
  152. package/dist-types/workers/client-ng-gen-worker.d.ts +0 -2
  153. package/dist-types/workers/client-ng-gen-worker.d.ts.map +0 -1
  154. package/dist-types/workers/lib-build-worker.d.ts +0 -2
  155. package/dist-types/workers/lib-build-worker.d.ts.map +0 -1
  156. package/schema/schema.json +0 -447
  157. package/sd-tsconfig.node.json +0 -18
  158. package/src/build-tools/SdCliCordova.ts +0 -242
  159. package/src/build-tools/SdCliIndexFileGenerator.ts +0 -61
  160. package/src/build-tools/SdCliNgModuleFilesGenerator.ts +0 -894
  161. package/src/build-tools/metadata/SdAotMetadataReader.ts +0 -374
  162. package/src/build-tools/metadata/SdIvyMetadataReader.ts +0 -183
  163. package/src/build-tools/metadata/SdMetadataError.ts +0 -7
  164. package/src/build-tools/metadata/SdMyMetadataReader.ts +0 -407
  165. package/src/builders/SdCliJavascriptLinter.ts +0 -81
  166. package/src/builders/SdCliNgClientBuilder.ts +0 -793
  167. package/src/builders/SdCliNgLibraryBuilder.ts +0 -301
  168. package/src/builders/SdCliPublisher.ts +0 -144
  169. package/src/builders/SdCliServerBuilder.ts +0 -555
  170. package/src/builders/SdCliTypescriptBuilder.ts +0 -552
  171. package/src/entry-points/SdCliLocalUpdater.ts +0 -114
  172. package/src/entry-points/SdCliPrepare.ts +0 -104
  173. package/src/entry-points/SdCliProject.ts +0 -405
  174. package/src/packages/SdCliClientPackage.ts +0 -111
  175. package/src/packages/SdCliLibraryPackage.ts +0 -118
  176. package/src/packages/SdCliPackageBase.ts +0 -34
  177. package/src/packages/SdCliServerPackage.ts +0 -85
  178. package/src/packages/SdCliUnknownPackage.ts +0 -14
  179. package/src/utils/SdCliFileCrypto.ts +0 -87
  180. package/src/utils/SdCliUtils.ts +0 -56
  181. package/src/utils/SdProjectConfigUtil.ts +0 -145
  182. package/src/utils/SdTsDiagnosticUtil.ts +0 -46
  183. package/src/utils/SdWebpackUtil.ts +0 -71
  184. package/src/workers/client-ng-gen-worker.ts +0 -63
  185. package/src/workers/lib-build-worker.ts +0 -97
@@ -1,555 +0,0 @@
1
- import { EventEmitter } from "events";
2
- import { INpmConfig, ISdPackageBuildResult, ISdServerPackageConfig, ITsconfig } from "../commons";
3
- import * as ts from "typescript";
4
- import { FsUtil, Logger, PathUtil, SdFsWatcher } from "@simplysm/sd-core-node";
5
- import { ObjectUtil, StringUtil, Wait } from "@simplysm/sd-core-common";
6
- import * as webpack from "webpack";
7
- import * as path from "path";
8
- import { JavaScriptOptimizerPlugin } from "@angular-devkit/build-angular/src/webpack/plugins/javascript-optimizer-plugin";
9
- import { DedupeModuleResolvePlugin } from "@angular-devkit/build-angular/src/webpack/plugins";
10
- import { LicenseWebpackPlugin } from "license-webpack-plugin";
11
- import { SdWebpackUtil } from "../utils/SdWebpackUtil";
12
- import { ErrorInfo } from "ts-loader/dist/interfaces";
13
- import { LintResult } from "eslint-webpack-plugin/declarations/options";
14
- import * as os from "os";
15
- import { SdServiceServer } from "@simplysm/sd-service-node";
16
- import decache from "decache";
17
- import * as CopyWebpackPlugin from "copy-webpack-plugin";
18
-
19
- // eslint-disable-next-line @typescript-eslint/naming-convention
20
- const ESLintWebpackPlugin = require("eslint-webpack-plugin");
21
-
22
- export class SdCliServerBuilder extends EventEmitter {
23
- public parsedTsconfig: ts.ParsedCommandLine;
24
- public npmConfigCache = new Map<string, INpmConfig>();
25
- private _server?: SdServiceServer;
26
-
27
- protected readonly _logger: Logger;
28
-
29
- public constructor(public rootPath: string,
30
- public tsconfigFilePath: string,
31
- public projectRootPath: string,
32
- public config: ISdServerPackageConfig,
33
- public skipProcesses: "lint"[]) {
34
- super();
35
-
36
- const tsconfig: ITsconfig = FsUtil.readJson(this.tsconfigFilePath);
37
- this.parsedTsconfig = ts.parseJsonConfigFileContent(tsconfig, ts.sys, this.rootPath);
38
- const npmConfig = FsUtil.readJson(path.resolve(this.rootPath, "package.json"));
39
- this.npmConfigCache.set(this.rootPath, npmConfig);
40
-
41
- this._logger = Logger.get(["simplysm", "sd-cli", this.constructor.name, npmConfig.name]);
42
- }
43
-
44
- public on(event: "change", listener: () => void): this;
45
- public on(event: "complete", listener: (results: ISdPackageBuildResult[], server?: SdServiceServer) => void): this;
46
- public on(event: string | symbol, listener: (...args: any[]) => void): this {
47
- return super.on(event, listener);
48
- }
49
-
50
- public async buildAsync(): Promise<void> {
51
- this.emit("change");
52
-
53
- await FsUtil.removeAsync(this.parsedTsconfig.options.outDir!);
54
-
55
- const externalModuleNames = this._findExternalModules(false).map((item) => item.name);
56
-
57
- // WEBPACK 빌드
58
- this._logger.debug("Webpack 빌드 수행");
59
- const webpackConfig = this._getWebpackConfig(false, externalModuleNames);
60
- const compiler = webpack(webpackConfig);
61
- const buildResults = await new Promise<ISdPackageBuildResult[]>((resolve, reject) => {
62
- compiler.run((err, stat) => {
63
- if (err != null) {
64
- reject(err);
65
- return;
66
- }
67
-
68
- // 결과 리턴
69
-
70
- const results = SdWebpackUtil.getWebpackResults(stat!);
71
- resolve(results);
72
- });
73
- });
74
- this._logger.debug("Webpack 빌드 결과", buildResults);
75
-
76
- // .config.json 파일 쓰기
77
-
78
- const targetPath = path.resolve(this.parsedTsconfig.options.outDir!, ".config.json");
79
- await FsUtil.writeFileAsync(targetPath, JSON.stringify(this.config.configs ?? {}, undefined, 2));
80
-
81
- // pm2.json 파일 쓰기
82
- if (this.config.pm2 !== undefined && this.config.pm2 !== false) {
83
- const npmConfig = this._getNpmConfig(this.rootPath)!;
84
- const pm2DistPath = path.resolve(this.parsedTsconfig.options.outDir!, "pm2.json");
85
- await FsUtil.writeFileAsync(pm2DistPath, JSON.stringify(ObjectUtil.merge(
86
- {
87
- "name": npmConfig.name.replace(/@/g, "").replace(/\//g, "-"),
88
- "script": path.basename(path.resolve(this.parsedTsconfig.options.outDir!, "main.js")),
89
- "watch": true,
90
- "watch_delay": 2000,
91
- "ignore_watch": [
92
- "node_modules",
93
- "www"
94
- ].distinct(),
95
- "interpreter": "node@" + process.versions.node,
96
- "env": {
97
- NODE_ENV: "production",
98
- VERSION: npmConfig.version,
99
- TZ: "Asia/Seoul",
100
- ...this.config.env ? this.config.env : {}
101
- }
102
- },
103
- (typeof this.config.pm2 !== "boolean") ? this.config.pm2 : {},
104
- {
105
- arrayProcess: "concat"
106
- }
107
- ), undefined, 2));
108
- }
109
-
110
- // iis 파일 쓰기
111
- if (this.config.iis !== undefined && this.config.iis !== false) {
112
- const iisDistPath = path.resolve(this.parsedTsconfig.options.outDir!, "web.config");
113
- const serverExeFilePath = (this.config.iis !== true && "serverExeFilePath" in this.config.iis)
114
- ? (this.config.iis.serverExeFilePath ?? "C:\\Program Files\\nodejs\\node.exe")
115
- : "C:\\Program Files\\nodejs\\node.exe";
116
- await FsUtil.writeFileAsync(iisDistPath, `
117
- <configuration>
118
- <system.webServer>
119
- <webSocket enabled="false" />
120
- <handlers>
121
- <add name="iisnode" path="main.js" verb="*" modules="iisnode" />
122
- </handlers>
123
- <iisnode nodeProcessCommandLine="${serverExeFilePath}"
124
- watchedFiles="web.config;*.js"
125
- loggingEnabled="true"
126
- devErrorsEnabled="true" />
127
- <rewrite>
128
- <rules>
129
- <rule name="main">
130
- <action type="Rewrite" url="main.js" />
131
- </rule>
132
- </rules>
133
- </rewrite>
134
- <httpErrors errorMode="Detailed" />
135
- </system.webServer>
136
- </configuration>
137
-
138
- `.trim());
139
- }
140
-
141
- // 배포용 package.json 파일 생성
142
-
143
- const distNpmConfig = ObjectUtil.clone(this._getNpmConfig(this.rootPath))!;
144
- distNpmConfig.dependencies = {};
145
- for (const externalModuleName of externalModuleNames) {
146
- distNpmConfig.dependencies[externalModuleName] = "*";
147
- }
148
- delete distNpmConfig.optionalDependencies;
149
- delete distNpmConfig.devDependencies;
150
- delete distNpmConfig.peerDependencies;
151
-
152
- if (this.config.pm2 !== undefined) {
153
- distNpmConfig.scripts = { "start": "pm2 start pm2.json" };
154
- }
155
-
156
- await FsUtil.writeFileAsync(path.resolve(this.parsedTsconfig.options.outDir!, "package.json"), JSON.stringify(distNpmConfig, undefined, 2));
157
-
158
- this.emit("complete", buildResults);
159
- }
160
-
161
- public async watchAsync(): Promise<void> {
162
- await FsUtil.removeAsync(this.parsedTsconfig.options.outDir!);
163
-
164
- const externalModules = this._findExternalModules(true);
165
- const externalModuleNames = externalModules.map((item) => item.name);
166
- const externalModulePaths = externalModules.map((item) => item.path);
167
-
168
- // 빌드
169
- const webpackConfig = this._getWebpackConfig(true, externalModuleNames);
170
- const compiler = webpack(webpackConfig);
171
- await new Promise<void>((resolve, reject) => {
172
- compiler.hooks.watchRun.tapAsync(this.constructor.name, async (args, callback) => {
173
- this.emit("change");
174
- callback();
175
-
176
- this._logger.debug("Webpack 빌드 수행");
177
-
178
- await this._stopServerAsync();
179
- });
180
-
181
- compiler.watch({ poll: undefined }, async (err, stat) => {
182
- if (err != null) {
183
- reject(err);
184
- return;
185
- }
186
-
187
- // .config.json 파일 쓰기
188
-
189
- const configDistPath = path.resolve(this.parsedTsconfig.options.outDir!, ".config.json");
190
- await FsUtil.writeFileAsync(configDistPath, JSON.stringify(this.config.configs ?? {}, undefined, 2));
191
-
192
- // 결과 변환
193
-
194
- const results = SdWebpackUtil.getWebpackResults(stat!);
195
-
196
- // 서버 시작
197
- try {
198
- await this._startServerAsync();
199
- }
200
- catch (error) {
201
- if (error instanceof Error) {
202
- results.push({
203
- filePath: undefined,
204
- severity: "error",
205
- message: error.message
206
- });
207
- }
208
- else {
209
- throw error;
210
- }
211
- }
212
-
213
- // 결과 리턴
214
-
215
- this.emit("complete", results, this._server);
216
- this._logger.debug("Webpack 빌드 수행 결과", results);
217
- resolve();
218
- });
219
- });
220
-
221
- // external 변경에 따른 서버 재시작을 위한 WATCH 구성
222
-
223
- const getWatchPathsAsync = async (): Promise<string[]> => {
224
- const result: string[] = [];
225
- for (const modulePath of externalModulePaths) {
226
- const npmConfig = this._getNpmConfig(modulePath);
227
- if (!npmConfig) continue;
228
- const distPath = path.resolve(modulePath, path.dirname(npmConfig.es2020 ?? npmConfig.module ?? npmConfig.main ?? "dist"));
229
- const watchPaths = (await FsUtil.globAsync(path.resolve(distPath, "**")))
230
- .filter((item) => (
231
- item.includes("@simplysm")
232
- && FsUtil.exists(item)
233
- && FsUtil.isDirectory(item)
234
- ));
235
-
236
- result.push(...watchPaths);
237
- }
238
-
239
- return result;
240
- };
241
-
242
- const watchPaths = await getWatchPathsAsync();
243
- const watcher = new SdFsWatcher();
244
- watcher
245
- .onChange(async (changeInfos) => {
246
- const dirtyFilePaths = changeInfos
247
- .map((changeInfo) => changeInfo.filePath)
248
- .filter((item) => path.basename(item).includes("."))
249
- .distinct();
250
-
251
- if (dirtyFilePaths.length === 0) return;
252
-
253
- this.emit("change");
254
- this._logger.debug("서버 재시작");
255
-
256
- const watchPaths2 = await getWatchPathsAsync();
257
- watcher.replaceWatchPaths(watchPaths2);
258
-
259
- await this._stopServerAsync();
260
-
261
- const results: ISdPackageBuildResult[] = [];
262
-
263
- try {
264
- await this._startServerAsync();
265
- }
266
- catch (error) {
267
- if (error instanceof Error) {
268
- results.push({
269
- filePath: undefined,
270
- severity: "error",
271
- message: error.message
272
- });
273
- }
274
- else {
275
- throw error;
276
- }
277
- }
278
-
279
- this.emit("complete", results, this._server);
280
- this._logger.debug("서버 재시작 결과", results);
281
- })
282
- .watch(watchPaths);
283
- }
284
-
285
- private async _stopServerAsync(): Promise<void> {
286
- if (this._server) {
287
- await this._server.closeAsync();
288
- delete this._server;
289
- }
290
- const mainFilePath = path.resolve(this.parsedTsconfig.options.outDir!, "main.js");
291
- decache(mainFilePath);
292
- }
293
-
294
- private async _startServerAsync(): Promise<void> {
295
- await Wait.true(() => this._server === undefined);
296
-
297
-
298
- const mainFilePath = path.resolve(this.parsedTsconfig.options.outDir!, "main.js");
299
-
300
- // const prevLoggerConfigs = ObjectUtil.clone(Logger.configs);
301
- this._server = require(mainFilePath) as SdServiceServer | undefined;
302
- // Logger.configs = prevLoggerConfigs;
303
-
304
- if (!this._server) {
305
- throw new Error(`${mainFilePath}(0, 0): 'SdServiceServer'를 'export'해야 합니다.`);
306
- }
307
-
308
-
309
- await new Promise<void>((resolve) => {
310
- this._server!.on("ready", () => {
311
- resolve();
312
- });
313
- });
314
- }
315
-
316
- private _getWebpackConfig(watch: boolean, externalModuleNames: string[]): webpack.Configuration {
317
- return {
318
- mode: watch ? "development" : "production",
319
- devtool: false,
320
- target: ["node", "es2020"],
321
- profile: false,
322
- resolve: {
323
- roots: [this.rootPath],
324
- extensions: [".ts", ".tsx", ".js"],
325
- symlinks: true,
326
- // modules: [this.projectRootPath, "node_modules"],
327
- mainFields: ["es2020", "module", "main"]
328
- },
329
- /*resolveLoader: {
330
- symlinks: true,
331
- modules: [
332
- "node_modules",
333
- ...this._findAllNodeModules(__dirname, this.projectRootPath)
334
- ]
335
- },*/
336
- context: this.projectRootPath,
337
- entry: {
338
- main: [
339
- path.resolve(this.rootPath, "src/main.ts")
340
- ]
341
- },
342
- output: {
343
- clean: true,
344
- path: this.parsedTsconfig.options.outDir,
345
- // filename: watch ? "[name].js" : `[name].[chunkhash:20].js`,
346
- // chunkFilename: watch ? "[name].js" : "[name].[chunkhash:20].js",
347
- filename: "[name].js",
348
- chunkFilename: "[name].js",
349
- assetModuleFilename: "resources/[name][ext][query]",
350
- libraryTarget: watch ? "umd" : "commonjs"
351
- },
352
- performance: { hints: false },
353
- module: {
354
- strictExportPresence: true,
355
- rules: [
356
- ...watch ? [
357
- {
358
- test: /\.m?js$/,
359
- enforce: "pre",
360
- loader: require.resolve("source-map-loader"),
361
- options: {
362
- filterSourceMappingUrl: (mapUri: string, resourcePath: string) => {
363
- return !resourcePath.includes("node_modules") || (/@simplysm[\\/]sd/).test(resourcePath);
364
- }
365
- }
366
- }
367
- ] as any : [],
368
- {
369
- test: /\.ts$/,
370
- exclude: /node_modules/,
371
- loader: require.resolve("ts-loader"),
372
- options: {
373
- configFile: this.tsconfigFilePath,
374
- errorFormatter: (msg: ErrorInfo, colors: boolean) => {
375
- return `${msg.file}(${msg.line}, ${msg.character}): ${msg.code}: ${msg.severity} ${msg.content}`;
376
- }
377
- }
378
- },
379
- {
380
- test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico|otf|xlsx?|pptx?|docx?|zip|pfx|pkl)$/,
381
- type: "asset/resource"
382
- }
383
- ]
384
- },
385
- ...watch ? {
386
- cache: { type: "memory", maxGenerations: 1 },
387
- snapshot: {
388
- immutablePaths: this._findAllInternalModuleCachePaths(),
389
- managedPaths: this._findAllInternalModuleCachePaths()
390
- }
391
- } : {
392
- cache: false
393
- },
394
- optimization: {
395
- minimizer: watch ? [] : [
396
- new JavaScriptOptimizerPlugin({
397
- sourcemap: false,
398
- target: this.parsedTsconfig.options.target,
399
- keepNames: true,
400
- removeLicenses: true,
401
- advanced: true
402
- }) as any
403
- ],
404
- moduleIds: "deterministic",
405
- chunkIds: watch ? "named" : "deterministic",
406
- emitOnErrors: watch
407
- },
408
- plugins: [
409
- new DedupeModuleResolvePlugin({ verbose: false }) as any,
410
- ...watch ? [] : [
411
- new LicenseWebpackPlugin({
412
- stats: { warnings: false, errors: false },
413
- perChunkOutput: false,
414
- outputFilename: "3rdpartylicenses.txt",
415
- skipChildCompilers: true
416
- })
417
- ],
418
- new CopyWebpackPlugin({
419
- patterns: ["assets/"].map((item) => ({
420
- context: this.rootPath,
421
- to: item,
422
- from: `src/${item}`,
423
- noErrorOnMissing: true,
424
- force: true,
425
- globOptions: {
426
- dot: true,
427
- followSymbolicLinks: false,
428
- ignore: [
429
- ".gitkeep",
430
- "**/.DS_Store",
431
- "**/Thumbs.db"
432
- ].map((i) => PathUtil.posix(this.rootPath, i))
433
- },
434
- priority: 0
435
- }))
436
- }),
437
- new webpack.EnvironmentPlugin({
438
- SD_VERSION: this._getNpmConfig(this.rootPath)!.version,
439
- ...this.config.env
440
- }),
441
- ...!this.skipProcesses.includes("lint") ? [
442
- new ESLintWebpackPlugin({
443
- context: this.rootPath,
444
- eslintPath: path.resolve(this.projectRootPath, "node_modules", "eslint"),
445
- extensions: ["js", "ts"],
446
- exclude: ["node_modules"],
447
- fix: false,
448
- threads: false,
449
- formatter: (results: LintResult[]) => {
450
- const resultMessages: string[] = [];
451
- for (const result of results) {
452
- for (const msg of result.messages) {
453
- resultMessages.push(`${result.filePath}(${msg.line}, ${msg.column}): ${msg.ruleId ?? ""}: ${msg.severity === 1 ? "warning" : msg.severity === 2 ? "error" : ""} ${msg.message}`);
454
- }
455
- }
456
- return resultMessages.join(os.EOL);
457
- }
458
- })
459
- ] : [],
460
- new webpack.ProgressPlugin({
461
- handler: (per: number, msg: string, ...args: string[]) => {
462
- const phaseText = msg ? ` - phase: ${msg}` : "";
463
- const argsText = args.length > 0 ? ` - args: [${args.join(", ")}]` : "";
464
- this._logger.debug(`Webpack 빌드 수행중...(${Math.round(per * 100)}%)${phaseText}${argsText}`);
465
- }
466
- })
467
- ],
468
- node: false,
469
- externals: externalModuleNames,
470
- stats: "errors-warnings"
471
- };
472
- }
473
-
474
- private _findAllInternalModuleCachePaths(): string[] {
475
- return this._findAllNodeModules(this.rootPath, this.projectRootPath)
476
- .mapMany((item) => (
477
- FsUtil.readdir(item)
478
- .filter((item1) => item1 !== "@simplysm")
479
- .map((item1) => path.resolve(item, item1))
480
- ));
481
- }
482
-
483
- private _findAllNodeModules(from: string, root: string): string[] {
484
- const nodeModules: string[] = [];
485
-
486
- let current = from;
487
- while (current) {
488
- const potential = path.join(current, "node_modules");
489
- if (FsUtil.exists(potential) && FsUtil.isDirectory(potential)) {
490
- nodeModules.push(potential);
491
- }
492
-
493
- if (current === root) break;
494
-
495
- const next = path.dirname(current);
496
- if (next === current) break;
497
- current = next;
498
- }
499
-
500
- return nodeModules;
501
- }
502
-
503
- private _findModulePath(moduleName: string, currentPath: string): string | undefined {
504
- const nodeModulesPaths = this._findAllNodeModules(currentPath, this.projectRootPath);
505
-
506
- for (const nodeModulePath of nodeModulesPaths) {
507
- const potential = path.join(nodeModulePath, moduleName);
508
- if (FsUtil.exists(potential)) {
509
- return potential;
510
- }
511
- }
512
-
513
- return undefined;
514
- }
515
-
516
- private _findExternalModules(all: boolean): { name: string; path: string }[] {
517
- const loadedModuleNames: string[] = [];
518
- const externalModules: { name: string; path: string }[] = [];
519
-
520
- const fn = (currPath: string): void => {
521
- const npmConfig = this._getNpmConfig(currPath);
522
- if (!npmConfig) return;
523
-
524
- for (const moduleName of Object.keys({
525
- ...npmConfig.dependencies,
526
- ...npmConfig.optionalDependencies
527
- })) {
528
- if (loadedModuleNames.includes(moduleName)) continue;
529
- loadedModuleNames.push(moduleName);
530
-
531
- const modulePath = this._findModulePath(moduleName, currPath);
532
- if (StringUtil.isNullOrEmpty(modulePath)) continue;
533
-
534
- if (all
535
- || this.config.externalDependencies?.includes(moduleName)
536
- || FsUtil.exists(path.resolve(modulePath, "binding.gyp"))) {
537
- externalModules.push({ path: modulePath, name: moduleName });
538
- }
539
-
540
- fn(modulePath);
541
- }
542
- };
543
-
544
- fn(this.rootPath);
545
-
546
- return externalModules.distinct();
547
- }
548
-
549
- private _getNpmConfig(rootPath: string): INpmConfig | undefined {
550
- if (!this.npmConfigCache.has(rootPath)) {
551
- this.npmConfigCache.set(rootPath, FsUtil.readJson(path.resolve(rootPath, "package.json")));
552
- }
553
- return this.npmConfigCache.get(rootPath);
554
- }
555
- }