@simplysm/sd-cli 10.0.37 → 10.0.39

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 (84) hide show
  1. package/dist/SdLinter.js.map +1 -1
  2. package/dist/SdTsIncrementalBuilder.d.ts +17 -4
  3. package/dist/SdTsIncrementalBuilder.js +18 -32
  4. package/dist/SdTsIncrementalBuilder.js.map +1 -1
  5. package/dist/build-cluster.js +98 -30
  6. package/dist/build-cluster.js.map +1 -1
  7. package/dist/builders/SdCliClientBuilder.d.ts +6 -2
  8. package/dist/builders/SdCliClientBuilder.js +107 -114
  9. package/dist/builders/SdCliClientBuilder.js.map +1 -1
  10. package/dist/builders/SdCliServerBuilder.d.ts +2 -1
  11. package/dist/builders/SdCliServerBuilder.js +38 -12
  12. package/dist/builders/SdCliServerBuilder.js.map +1 -1
  13. package/dist/builders/SdCliTsLibBuilder.d.ts +5 -2
  14. package/dist/builders/SdCliTsLibBuilder.js +64 -10
  15. package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
  16. package/dist/commons.d.ts +28 -2
  17. package/dist/entry/SdCliElectron.d.ts +7 -0
  18. package/dist/entry/SdCliElectron.js +42 -0
  19. package/dist/entry/SdCliElectron.js.map +1 -0
  20. package/dist/entry/SdCliLocalUpdate.d.ts +12 -0
  21. package/dist/entry/SdCliLocalUpdate.js +94 -0
  22. package/dist/entry/SdCliLocalUpdate.js.map +1 -0
  23. package/dist/entry/SdCliProject.d.ts +3 -3
  24. package/dist/entry/SdCliProject.js +87 -31
  25. package/dist/entry/SdCliProject.js.map +1 -1
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.js +2 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/sd-cli.d.ts +1 -1
  30. package/dist/sd-cli.js +74 -13
  31. package/dist/sd-cli.js.map +1 -1
  32. package/dist/utils/SdCliBuildResultUtil.js +1 -1
  33. package/dist/utils/SdCliBuildResultUtil.js.map +1 -1
  34. package/dist/utils/SdCliViteElectronMainPlugin.d.ts +6 -0
  35. package/dist/utils/SdCliViteElectronMainPlugin.js +81 -0
  36. package/dist/utils/SdCliViteElectronMainPlugin.js.map +1 -0
  37. package/dist/utils/SdCliViteExternalPlugin.d.ts +7 -0
  38. package/dist/utils/SdCliViteExternalPlugin.js +98 -0
  39. package/dist/utils/SdCliViteExternalPlugin.js.map +1 -0
  40. package/dist/utils/SdCliViteLoggerPlugin.d.ts +6 -0
  41. package/dist/utils/SdCliViteLoggerPlugin.js +24 -0
  42. package/dist/utils/SdCliViteLoggerPlugin.js.map +1 -0
  43. package/dist/utils/SdCliViteNodeGlobalPlugin.d.ts +2 -0
  44. package/dist/utils/SdCliViteNodeGlobalPlugin.js +29 -0
  45. package/dist/utils/SdCliViteNodeGlobalPlugin.js.map +1 -0
  46. package/dist/utils/SdCliViteReactSwcPlugin.d.ts +2 -0
  47. package/dist/utils/SdCliViteReactSwcPlugin.js +141 -0
  48. package/dist/utils/SdCliViteReactSwcPlugin.js.map +1 -0
  49. package/dist/utils/SdCliViteWatchWithResolutionsPlugin.d.ts +2 -0
  50. package/dist/utils/SdCliViteWatchWithResolutionsPlugin.js +26 -0
  51. package/dist/utils/SdCliViteWatchWithResolutionsPlugin.js.map +1 -0
  52. package/dist/utils/getElectronReactExternals.d.ts +1 -0
  53. package/dist/utils/getElectronReactExternals.js +17 -0
  54. package/dist/utils/getElectronReactExternals.js.map +1 -0
  55. package/dist/utils/sdCliTsDefineTransformer.d.ts +4 -0
  56. package/dist/utils/sdCliTsDefineTransformer.js +26 -0
  57. package/dist/utils/sdCliTsDefineTransformer.js.map +1 -0
  58. package/package.json +25 -11
  59. package/src/SdLinter.ts +2 -2
  60. package/src/SdTsIncrementalBuilder.ts +116 -105
  61. package/src/build-cluster.ts +173 -111
  62. package/src/builders/SdCliClientBuilder.ts +226 -221
  63. package/src/builders/SdCliServerBuilder.ts +311 -275
  64. package/src/builders/SdCliTsLibBuilder.ts +160 -89
  65. package/src/commons.ts +66 -34
  66. package/src/entry/SdCliElectron.ts +55 -0
  67. package/src/entry/SdCliLocalUpdate.ts +125 -0
  68. package/src/entry/SdCliProject.ts +452 -395
  69. package/src/index.ts +1 -0
  70. package/src/sd-cli.ts +185 -122
  71. package/src/utils/SdCliBuildResultUtil.ts +1 -2
  72. package/src/utils/SdCliViteElectronMainPlugin.ts +86 -0
  73. package/src/utils/SdCliViteExternalPlugin.ts +112 -0
  74. package/src/utils/SdCliViteLoggerPlugin.ts +29 -0
  75. package/src/utils/SdCliViteNodeGlobalPlugin.ts +31 -0
  76. package/src/utils/SdCliViteReactSwcPlugin.ts +154 -0
  77. package/src/utils/SdCliViteWatchWithResolutionsPlugin.ts +29 -0
  78. package/src/utils/getElectronReactExternals.ts +19 -0
  79. package/src/utils/sdCliTsDefineTransformer.ts +31 -0
  80. package/.eslintrc.cjs +0 -18
  81. package/dist/utils/SdCliConfigUtil.d.ts +0 -7
  82. package/dist/utils/SdCliConfigUtil.js +0 -69
  83. package/dist/utils/SdCliConfigUtil.js.map +0 -1
  84. package/src/utils/SdCliConfigUtil.ts +0 -94
@@ -1,467 +1,524 @@
1
1
  import path from "path";
2
- import { FsUtil, Logger, SdProcess } from "@simplysm/sd-core-node";
3
- import { SdCliConfigUtil } from "../utils/SdCliConfigUtil";
2
+ import {FsUtil, Logger, SdProcess} from "@simplysm/sd-core-node";
4
3
  import {
5
- INpmConfig,
6
- ISdCliBuildClusterReqMessage,
7
- ISdCliBuildClusterResMessage,
8
- ISdCliPackageBuildResult,
9
- TSdCliPackageConfig
4
+ INpmConfig,
5
+ ISdCliBuildClusterReqMessage,
6
+ ISdCliBuildClusterResMessage,
7
+ ISdCliConfig,
8
+ ISdCliPackageBuildResult,
9
+ TSdCliPackageConfig
10
10
  } from "../commons";
11
11
  import cp from "child_process";
12
- import { fileURLToPath } from "url";
13
- import { SdCliBuildResultUtil } from "../utils/SdCliBuildResultUtil";
12
+ import {fileURLToPath, pathToFileURL} from "url";
13
+ import {SdCliBuildResultUtil} from "../utils/SdCliBuildResultUtil";
14
14
  import semver from "semver";
15
- import { NotImplementError, Wait } from "@simplysm/sd-core-common";
15
+ import {NotImplementError, Wait} from "@simplysm/sd-core-common";
16
16
 
17
17
  export class SdCliProject {
18
- public static async watchAsync(opt: {
19
- rootPath: string;
20
- confFileRelPath: string;
21
- optNames: string[];
22
- pkgNames: string[];
23
- }): Promise<void> {
24
- const logger = Logger.get(["simplysm", "sd-cli", "SdCliProject", "watchAsync"]);
25
-
26
- logger.debug("프로젝트 설정 가져오기...");
27
- const projConf = await SdCliConfigUtil.loadConfigAsync(path.resolve(opt.rootPath, opt.confFileRelPath), false, opt.optNames);
28
-
29
- logger.debug("프로젝트 package.json 가져오기...");
30
- const projNpmConf = FsUtil.readJson(path.resolve(opt.rootPath, "package.json"));
31
-
32
- logger.debug("패키지 목록 구성...");
33
- const allPkgPaths = await projNpmConf.workspaces?.mapManyAsync(async (item) => await FsUtil.globAsync(item));
34
- let pkgPaths = allPkgPaths.filter((pkgPath) => path.basename(pkgPath) in projConf.packages);
35
- if (opt.pkgNames.length !== 0) {
36
- pkgPaths = pkgPaths.filter((pkgPath) => opt.pkgNames.includes(path.basename(pkgPath)));
37
- }
38
-
39
- logger.debug("빌드 프로세스 준비...");
40
- const cluster = await this._prepareClusterAsync();
41
-
42
- logger.debug("빌드 프로세스 이벤트 준비...");
43
- const resultCache = new Map<string, ISdCliPackageBuildResult[]>();
44
- let busyCount = 0;
45
- const serverInfoMap = new Map<string, {
46
- // server
47
- pkgPath?: string; // persist
48
- worker?: cp.ChildProcess; // persist
49
- port?: number;
50
- hasChanges: boolean;
51
-
52
- //client
53
- pathProxy: Record<string, number | undefined>; // persist
54
- changeFilePaths: string[];
55
- }>();
56
- cluster.on("message", (message: ISdCliBuildClusterResMessage) => {
57
- if (message.type === "change") {
58
- if (busyCount === 0) {
59
- logger.log("빌드를 시작합니다...");
18
+ public static async watchAsync(opt: {
19
+ confFileRelPath: string;
20
+ optNames: string[];
21
+ pkgNames: string[];
22
+ withLint: boolean;
23
+ }): Promise<void> {
24
+ const logger = Logger.get(["simplysm", "sd-cli", "SdCliProject", "watchAsync"]);
25
+
26
+ logger.debug("프로젝트 설정 가져오기...");
27
+ const projConf = (await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)).default(true, opt.optNames) as ISdCliConfig;
28
+
29
+ logger.debug("프로젝트 package.json 가져오기...");
30
+ const projNpmConf = (await FsUtil.readJsonAsync(path.resolve(process.cwd(), "package.json"))) as INpmConfig;
31
+
32
+ logger.debug("패키지 목록 구성...");
33
+ if (!projNpmConf.workspaces) {
34
+ throw new Error("프로젝트 package.json에 workspaces가 설정되어있지 않습니다.");
60
35
  }
61
- busyCount++;
62
- }
63
- else if (message.type === "complete") {
64
- for (const affectedFilePath of message.result!.affectedFilePaths) {
65
- resultCache.delete(affectedFilePath);
36
+ const allPkgPaths = await projNpmConf.workspaces.mapManyAsync(async (item) => await FsUtil.globAsync(item));
37
+ let pkgPaths = allPkgPaths.filter((pkgPath) => path.basename(pkgPath) in projConf.packages);
38
+ if (opt.pkgNames.length !== 0) {
39
+ pkgPaths = pkgPaths.filter((pkgPath) => opt.pkgNames.includes(path.basename(pkgPath)));
66
40
  }
67
41
 
68
- for (const buildResult of message.result!.buildResults) {
69
- const cacheItem = resultCache.getOrCreate(buildResult.filePath ?? "none", []);
70
- cacheItem.push(buildResult);
42
+ logger.debug("패키지 존재 확인...");
43
+ const notExistsPkgs = Object.keys(projConf.packages).filter((pkgConfKey) => allPkgPaths.every((pkgPath) => path.basename(pkgPath) !== pkgConfKey));
44
+ if (notExistsPkgs.length > 0) {
45
+ throw new Error("패키지를 찾을 수 없습니다. (" + notExistsPkgs.join(", ") + ")");
71
46
  }
72
47
 
73
- if (message.req.pkgConf.type === "server") {
74
- const pkgName = path.basename(message.req.pkgPath);
75
- const serverInfo = serverInfoMap.getOrCreate(pkgName, {
76
- hasChanges: false,
77
- pathProxy: {},
78
- changeFilePaths: []
79
- });
80
- serverInfo.pkgPath = message.req.pkgPath;
81
- serverInfo.hasChanges = true;
82
- }
48
+ logger.debug("빌드 프로세스 준비...");
49
+ const cluster = await this._prepareClusterAsync();
50
+
51
+ logger.debug("빌드 프로세스 이벤트 준비...");
52
+ const resultCache = new Map<string, ISdCliPackageBuildResult[]>();
53
+ let busyCount = 0;
54
+ const serverInfoMap = new Map<string, {
55
+ // server
56
+ pkgPath?: string; // persist
57
+ worker?: cp.ChildProcess; // persist
58
+ port?: number;
59
+ hasChanges: boolean;
60
+
61
+ //client
62
+ pathProxy: Record<string, number | undefined>; // persist
63
+ changeFilePaths: string[];
64
+ }>();
65
+ cluster.on("message", (message: ISdCliBuildClusterResMessage) => {
66
+ if (message.type === "change") {
67
+ if (busyCount === 0) {
68
+ logger.log("빌드를 시작합니다...");
69
+ }
70
+ busyCount++;
71
+ } else if (message.type === "complete") {
72
+ for (const affectedFilePath of message.result!.affectedFilePaths) {
73
+ resultCache.delete(affectedFilePath);
74
+ }
83
75
 
84
- if (message.req.pkgConf.type === "client" && message.req.pkgConf.server !== undefined) {
85
- const pkgName = path.basename(message.req.pkgPath);
86
- const serverInfo = serverInfoMap.getOrCreate(message.req.pkgConf.server, {
87
- hasChanges: false,
88
- pathProxy: {},
89
- changeFilePaths: []
90
- });
91
- serverInfo.pathProxy[pkgName] = message.result!.port;
92
- serverInfo.changeFilePaths.push(...message.result!.affectedFilePaths);
93
- }
76
+ for (const buildResult of message.result!.buildResults) {
77
+ const cacheItem = resultCache.getOrCreate(buildResult.filePath ?? "none", []);
78
+ cacheItem.push(buildResult);
79
+ }
94
80
 
95
- setTimeout(async () => {
96
- busyCount--;
97
- if (busyCount === 0) {
98
- for (const serverPkgName of serverInfoMap.keys()) {
99
- const serverInfo = serverInfoMap.get(serverPkgName)!;
100
- if (serverInfo.pkgPath !== undefined && serverInfo.hasChanges) {
101
- logger.debug("서버 재시작...");
102
- try {
103
- const restartServerResult = await this._restartServerAsync(serverInfo.pkgPath, serverInfo.worker);
104
- serverInfo.worker = restartServerResult.worker;
105
- serverInfo.port = restartServerResult.port;
106
- serverInfo.hasChanges = false;
81
+ if (message.req.pkgConf.type === "server") {
82
+ const pkgName = path.basename(message.req.pkgPath);
83
+ const serverInfo = serverInfoMap.getOrCreate(pkgName, {
84
+ hasChanges: false,
85
+ pathProxy: {},
86
+ changeFilePaths: []
87
+ });
88
+ serverInfo.pkgPath = message.req.pkgPath;
89
+ serverInfo.hasChanges = true;
107
90
  }
108
- catch (err) {
109
- logger.error(err);
91
+
92
+ if (message.req.pkgConf.type === "client") {
93
+ const pkgName = path.basename(message.req.pkgPath);
94
+
95
+ if (message.req.pkgConf.server !== undefined) {
96
+ const serverInfo = serverInfoMap.getOrCreate(message.req.pkgConf.server, {
97
+ hasChanges: false,
98
+ pathProxy: {},
99
+ changeFilePaths: []
100
+ });
101
+ serverInfo.pathProxy[pkgName] = message.result!.port;
102
+ serverInfo.changeFilePaths.push(...message.result!.affectedFilePaths);
103
+ } else {
104
+ const serverInfo = serverInfoMap.getOrCreate(pkgName, {
105
+ hasChanges: false,
106
+ pathProxy: {},
107
+ changeFilePaths: []
108
+ });
109
+ serverInfo.port = message.result!.port;
110
+ serverInfo.changeFilePaths.push(...message.result!.affectedFilePaths);
111
+ }
110
112
  }
111
- }
112
113
 
113
- if (serverInfo.worker) {
114
- logger.debug("클라이언트 설정...");
115
- serverInfo.worker.send({
116
- type: "setPathProxy",
117
- pathProxy: serverInfo.pathProxy
118
- });
119
- }
114
+ setTimeout(async () => {
115
+ busyCount--;
116
+ if (busyCount === 0) {
117
+ for (const serverPkgName of serverInfoMap.keys()) {
118
+ const serverInfo = serverInfoMap.get(serverPkgName)!;
119
+ if (serverInfo.pkgPath !== undefined && serverInfo.hasChanges) {
120
+ logger.debug("서버 재시작...");
121
+ try {
122
+ const restartServerResult = await this._restartServerAsync(serverInfo.pkgPath, serverInfo.worker);
123
+ serverInfo.worker = restartServerResult.worker;
124
+ serverInfo.port = restartServerResult.port;
125
+ serverInfo.hasChanges = false;
126
+ } catch (err) {
127
+ logger.error(err);
128
+ }
129
+ }
130
+
131
+ if (serverInfo.worker) {
132
+ logger.debug("클라이언트 설정...");
133
+ serverInfo.worker.send({
134
+ type: "setPathProxy",
135
+ pathProxy: serverInfo.pathProxy
136
+ });
137
+ }
138
+ }
139
+
140
+ const clientPaths: string[] = [];
141
+ for (const serverInfo of serverInfoMap.values()) {
142
+ if (Object.keys(serverInfo.pathProxy).length > 0) {
143
+ for (const proxyPath of Object.keys(serverInfo.pathProxy)) {
144
+ clientPaths.push(`http://localhost:${serverInfo.port}/${proxyPath}/`);
145
+ }
146
+ } else {
147
+ clientPaths.push(`http://localhost:${serverInfo.port}/`);
148
+ }
149
+ }
150
+ if (clientPaths.length > 0) {
151
+ logger.info("클라이언트 개발 서버 접속 주소\n" + clientPaths.join("\n"));
152
+ }
153
+
154
+ const buildResults = Array.from(resultCache.values()).mapMany();
155
+ this._logging(buildResults, logger);
156
+ }
157
+ }, 300);
120
158
  }
159
+ });
121
160
 
122
- const clientPaths: string[] = [];
123
- for (const serverInfo of serverInfoMap.values()) {
124
- for (const proxyPath of Object.keys(serverInfo.pathProxy)) {
125
- clientPaths.push(`http://localhost:${serverInfo.port}/${proxyPath}/`);
126
- }
127
- }
128
- if (clientPaths.length > 0) {
129
- logger.info("클라이언트 개발 서버 접속 주소\n" + clientPaths.join("\n"));
161
+ logger.debug("빌드 프로세스 명령 전송...");
162
+ busyCount++;
163
+ logger.log("빌드를 시작합니다...");
164
+
165
+ await pkgPaths.parallelAsync(async (pkgPath) => {
166
+ const pkgConf = projConf.packages[path.basename(pkgPath)]!;
167
+ if (pkgConf.type === "client") {
168
+ const builderKeys = Object.keys(pkgConf.builder ?? {web: {}});
169
+ await builderKeys.parallelAsync(async (builderKey) => {
170
+ await this._runCommandAsync(cluster, "watch", pkgPath, projConf.packages[path.basename(pkgPath)]!, opt.withLint, builderKey);
171
+ });
172
+ } else {
173
+ await this._runCommandAsync(cluster, "watch", pkgPath, projConf.packages[path.basename(pkgPath)]!, opt.withLint);
130
174
  }
175
+ });
131
176
 
177
+ busyCount--;
178
+ if (busyCount === 0) {
132
179
  const buildResults = Array.from(resultCache.values()).mapMany();
133
180
  this._logging(buildResults, logger);
134
- }
135
- }, 300);
136
- }
137
- });
138
-
139
- logger.debug("빌드 프로세스 명령 전송...");
140
- busyCount++;
141
- logger.log("빌드를 시작합니다...");
142
-
143
- await pkgPaths.parallelAsync(async (pkgPath) => {
144
- await this._runCommandAsync(cluster, "watch", pkgPath, projConf.packages[path.basename(pkgPath)]!);
145
- });
146
-
147
- busyCount--;
148
- if (busyCount === 0) {
149
- const buildResults = Array.from(resultCache.values()).mapMany();
150
- this._logging(buildResults, logger);
151
- }
152
- }
153
-
154
- public static async buildAsync(opt: {
155
- rootPath: string;
156
- confFileRelPath: string;
157
- optNames: string[];
158
- pkgNames: string[];
159
- }): Promise<void> {
160
- const logger = Logger.get(["simplysm", "sd-cli", "SdCliProject", "buildAsync"]);
161
-
162
- logger.debug("프로젝트 설정 가져오기...");
163
- const projConf = await SdCliConfigUtil.loadConfigAsync(path.resolve(opt.rootPath, opt.confFileRelPath), false, opt.optNames);
164
-
165
- logger.debug("프로젝트 package.json 가져오기...");
166
- const projNpmConf = FsUtil.readJson(path.resolve(opt.rootPath, "package.json"));
167
-
168
- logger.debug("패키지 목록 구성...");
169
- const allPkgPaths = await projNpmConf.workspaces?.mapManyAsync(async (item) => await FsUtil.globAsync(item));
170
- let pkgPaths = allPkgPaths.filter((pkgPath) => path.basename(pkgPath) in projConf.packages);
171
- if (opt.pkgNames.length !== 0) {
172
- pkgPaths = pkgPaths.filter((pkgPath) => opt.pkgNames.includes(path.basename(pkgPath)));
181
+ }
173
182
  }
174
183
 
175
- logger.debug("프로젝트 패키지 버전 설정...");
176
- await this._upgradeVersionAsync(opt.rootPath, projNpmConf, allPkgPaths);
184
+ public static async buildAsync(opt: {
185
+ confFileRelPath: string;
186
+ optNames: string[];
187
+ pkgNames: string[];
188
+ withLint: boolean;
189
+ }): Promise<void> {
190
+ const logger = Logger.get(["simplysm", "sd-cli", "SdCliProject", "buildAsync"]);
177
191
 
178
- logger.debug("빌드 프로세스 준비...");
179
- const cluster = await this._prepareClusterAsync();
192
+ logger.debug("프로젝트 설정 가져오기...");
193
+ const projConf = (await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)).default(false, opt.optNames) as ISdCliConfig;
180
194
 
181
- logger.debug("빌드 프로세스 명령 전달...");
182
- const results = (
183
- await pkgPaths.parallelAsync(async (pkgPath) => {
184
- return await this._runCommandAsync(cluster, "build", pkgPath, projConf.packages[path.basename(pkgPath)]!);
185
- })
186
- ).mapMany();
195
+ logger.debug("프로젝트 package.json 가져오기...");
196
+ const projNpmConf = (await FsUtil.readJsonAsync(path.resolve(process.cwd(), "package.json"))) as INpmConfig;
187
197
 
188
- logger.debug("빌드 프로세스 닫기...");
189
- this._closeCluster(cluster);
198
+ logger.debug("패키지 목록 구성...");
199
+ if (!projNpmConf.workspaces) {
200
+ throw new Error("프로젝트 package.json에 workspaces가 설정되어있지 않습니다.");
201
+ }
202
+ const allPkgPaths = await projNpmConf.workspaces.mapManyAsync(async (item) => await FsUtil.globAsync(item));
203
+ let pkgPaths = allPkgPaths.filter((pkgPath) => path.basename(pkgPath) in projConf.packages);
204
+ if (opt.pkgNames.length !== 0) {
205
+ pkgPaths = pkgPaths.filter((pkgPath) => opt.pkgNames.includes(path.basename(pkgPath)));
206
+ }
190
207
 
191
- this._logging(results, logger);
192
- }
208
+ logger.debug("프로젝트 및 패키지 버전 설정...");
209
+ await this._upgradeVersionAsync(projNpmConf, allPkgPaths);
210
+
211
+ logger.debug("빌드 프로세스 준비...");
212
+ const cluster = await this._prepareClusterAsync();
213
+
214
+ logger.debug("빌드 프로세스 명령 전달...");
215
+ const results = (
216
+ await pkgPaths.parallelAsync(async (pkgPath) => {
217
+ const pkgConf = projConf.packages[path.basename(pkgPath)]!;
218
+ if (pkgConf.type === "client") {
219
+ const builderKeys = Object.keys(pkgConf.builder ?? {web: {}});
220
+ return (await builderKeys.parallelAsync(async (builderKey) => {
221
+ return await this._runCommandAsync(cluster, "build", pkgPath, projConf.packages[path.basename(pkgPath)]!, opt.withLint, builderKey);
222
+ })).mapMany();
223
+ } else {
224
+ return await this._runCommandAsync(cluster, "build", pkgPath, projConf.packages[path.basename(pkgPath)]!, opt.withLint);
225
+ }
226
+ })
227
+ ).mapMany();
193
228
 
194
- public static async publishAsync(opt: {
195
- rootPath: string;
196
- noBuild: boolean;
197
- confFileRelPath: string;
198
- optNames: string[];
199
- pkgNames: string[];
200
- }): Promise<void> {
201
- const logger = Logger.get(["simplysm", "sd-cli", "SdCliProject", "publishAsync"]);
229
+ logger.debug("빌드 프로세스 닫기...");
230
+ this._closeCluster(cluster);
202
231
 
203
- logger.debug("프로젝트 설정 가져오기...");
204
- const projConf = await SdCliConfigUtil.loadConfigAsync(path.resolve(opt.rootPath, opt.confFileRelPath), false, opt.optNames);
232
+ this._logging(results, logger);
233
+ }
205
234
 
206
- logger.debug("프로젝트 package.json 가져오기...");
207
- const projNpmConf = FsUtil.readJson(path.resolve(opt.rootPath, "package.json"));
235
+ public static async publishAsync(opt: {
236
+ noBuild: boolean;
237
+ confFileRelPath: string;
238
+ optNames: string[];
239
+ pkgNames: string[];
240
+ withLint: boolean;
241
+ }): Promise<void> {
242
+ const logger = Logger.get(["simplysm", "sd-cli", "SdCliProject", "publishAsync"]);
208
243
 
209
- if (opt.noBuild) {
210
- logger.warn("빌드하지 않고, 배포하는것은 상당히 위험합니다.");
211
- await this._waitSecMessageAsync("프로세스를 중지하려면, 'CTRL+C'를 누르세요.", 5);
212
- }
244
+ logger.debug("프로젝트 설정 가져오기...");
245
+ const projConf = (await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)).default(false, opt.optNames) as ISdCliConfig;
213
246
 
214
- // GIT 사용중일 경우, 커밋되지 않은 수정사항이 있는지 확인
215
- if (FsUtil.exists(path.resolve(process.cwd(), ".git"))) {
216
- logger.debug("GIT 커밋여부 확인...");
217
- const gitStatusResult = await SdProcess.spawnAsync("git status");
218
- if (gitStatusResult.includes("Changes") || gitStatusResult.includes("Untracked")) {
219
- throw new Error("커밋되지 않은 정보가 있습니다.\n" + gitStatusResult);
220
- }
221
- }
247
+ logger.debug("프로젝트 package.json 가져오기...");
248
+ const projNpmConf = (await FsUtil.readJsonAsync(path.resolve(process.cwd(), "package.json"))) as INpmConfig;
222
249
 
223
- logger.debug("패키지 목록 구성...");
224
- const allPkgPaths = await projNpmConf.workspaces?.mapManyAsync(async (item) => await FsUtil.globAsync(item));
225
- let pkgPaths = allPkgPaths.filter((pkgPath) => path.basename(pkgPath) in projConf.packages);
226
- if (opt.pkgNames.length !== 0) {
227
- pkgPaths = pkgPaths.filter((pkgPath) => opt.pkgNames.includes(path.basename(pkgPath)));
228
- }
250
+ if (opt.noBuild) {
251
+ logger.warn("빌드하지 않고, 배포하는것은 상당히 위험합니다.");
252
+ await this._waitSecMessageAsync("프로세스를 중지하려면, 'CTRL+C'를 누르세요.", 5);
253
+ }
229
254
 
230
- logger.debug("프로젝트 패키지 버전 설정...");
231
- await this._upgradeVersionAsync(opt.rootPath, projNpmConf, allPkgPaths);
255
+ // GIT 사용중일 경우, 커밋되지 않은 수정사항이 있는지 확인
256
+ if (FsUtil.exists(path.resolve(process.cwd(), ".git"))) {
257
+ logger.debug("GIT 커밋여부 확인...");
258
+ const gitStatusResult = await SdProcess.spawnAsync("git status");
259
+ if (gitStatusResult.includes("Changes") || gitStatusResult.includes("Untracked")) {
260
+ throw new Error("커밋되지 않은 정보가 있습니다.\n" + gitStatusResult);
261
+ }
262
+ }
232
263
 
233
- // 빌드
234
- if (!opt.noBuild) {
235
- logger.debug("빌드 프로세스 준비...");
236
- const cluster = await this._prepareClusterAsync();
264
+ logger.debug("패키지 목록 구성...");
265
+ if (!projNpmConf.workspaces) {
266
+ throw new Error("프로젝트 package.json에 workspaces가 설정되어있지 않습니다.");
267
+ }
268
+ const allPkgPaths = await projNpmConf.workspaces.mapManyAsync(async (item) => await FsUtil.globAsync(item));
269
+ let pkgPaths = allPkgPaths.filter((pkgPath) => path.basename(pkgPath) in projConf.packages);
270
+ if (opt.pkgNames.length !== 0) {
271
+ pkgPaths = pkgPaths.filter((pkgPath) => opt.pkgNames.includes(path.basename(pkgPath)));
272
+ }
237
273
 
238
- logger.debug("빌드 프로세스 명령 전달...");
239
- const results = (
240
- await pkgPaths.parallelAsync(async (pkgPath) => {
241
- return await this._runCommandAsync(cluster, "build", pkgPath, projConf.packages[path.basename(pkgPath)]!);
242
- })
243
- ).mapMany();
274
+ logger.debug("프로젝트 패키지 버전 설정...");
275
+ await this._upgradeVersionAsync(projNpmConf, allPkgPaths);
244
276
 
245
- logger.debug("빌드 프로세스 닫기...");
246
- this._closeCluster(cluster);
277
+ // 빌드
278
+ if (!opt.noBuild) {
279
+ logger.debug("빌드 프로세스 준비...");
280
+ const cluster = await this._prepareClusterAsync();
247
281
 
248
- this._logging(results, logger);
249
- }
282
+ logger.debug("빌드 프로세스 명령 전달...");
283
+ const results = (
284
+ await pkgPaths.parallelAsync(async (pkgPath) => {
285
+ return await this._runCommandAsync(cluster, "build", pkgPath, projConf.packages[path.basename(pkgPath)]!, opt.withLint);
286
+ })
287
+ ).mapMany();
250
288
 
251
- // GIT 사용중일경우, 새 버전 커밋 및 TAG 생성
252
- if (FsUtil.exists(path.resolve(process.cwd(), ".git"))) {
253
- logger.debug("새 버전 커밋 및 TAG 생성...");
254
- await SdProcess.spawnAsync("git add .");
255
- await SdProcess.spawnAsync(`git commit -m "v${projNpmConf.version}"`);
256
- await SdProcess.spawnAsync(`git tag -a "v${projNpmConf.version}" -m "v${projNpmConf.version}"`);
289
+ logger.debug("빌드 프로세스 닫기...");
290
+ this._closeCluster(cluster);
257
291
 
258
- logger.debug("새 버전 푸쉬...");
259
- await SdProcess.spawnAsync("git push");
260
- await SdProcess.spawnAsync("git push --tags");
261
- }
292
+ this._logging(results, logger);
293
+ }
262
294
 
263
- logger.debug("배포 시작...");
264
- await pkgPaths.parallelAsync(async (pkgPath) => {
265
- const pkgName = path.basename(pkgPath);
266
- const pkgConf = projConf.packages[pkgName];
267
- if (pkgConf?.publish == null) return;
295
+ // GIT 사용중일경우, 새 버전 커밋 및 TAG 생성
296
+ if (FsUtil.exists(path.resolve(process.cwd(), ".git"))) {
297
+ logger.debug("새 버전 커밋 및 TAG 생성...");
298
+ await SdProcess.spawnAsync("git add .");
299
+ await SdProcess.spawnAsync(`git commit -m "v${projNpmConf.version}"`);
300
+ await SdProcess.spawnAsync(`git tag -a "v${projNpmConf.version}" -m "v${projNpmConf.version}"`);
268
301
 
269
- logger.debug(`[${pkgName}] 배포 시작...`);
270
- await this._publishPkgAsync(pkgPath, pkgConf.publish);
271
- logger.debug(`[${pkgName}] 배포 완료`);
272
- });
302
+ logger.debug("새 버전 푸쉬...");
303
+ await SdProcess.spawnAsync("git push");
304
+ await SdProcess.spawnAsync("git push --tags");
305
+ }
273
306
 
274
- logger.info(`모든 배포가 완료되었습니다. (v${projNpmConf.version})`);
275
- }
307
+ logger.debug("배포 시작...");
308
+ await pkgPaths.parallelAsync(async (pkgPath) => {
309
+ const pkgName = path.basename(pkgPath);
310
+ const pkgConf = projConf.packages[pkgName];
311
+ if (pkgConf?.publish == null) return;
276
312
 
277
- private static async _publishPkgAsync(pkgPath: string, pkgPubConf: TSdCliPackageConfig["publish"]): Promise<void> {
278
- if (pkgPubConf === "npm") {
279
- await SdProcess.spawnAsync("yarn npm publish --access public", { cwd: pkgPath });
280
- }
281
- else {
282
- throw new NotImplementError();
283
- }
284
- }
313
+ logger.debug(`[${pkgName}] 배포 시작...`);
314
+ await this._publishPkgAsync(pkgPath, pkgConf.publish);
315
+ logger.debug(`[${pkgName}] 배포 완료`);
316
+ });
285
317
 
286
- private static async _waitSecMessageAsync(msg: string, sec: number): Promise<void> {
287
- for (let i = sec; i > 0; i--) {
288
- if (i !== sec) {
289
- process.stdout.cursorTo(0);
290
- }
291
- process.stdout.write(`${msg} ${i}`);
292
- await Wait.time(1000);
318
+ logger.info(`모든 배포가 완료되었습니다. (v${projNpmConf.version})`);
293
319
  }
294
320
 
295
- process.stdout.cursorTo(0);
296
- process.stdout.clearLine(0);
297
- }
298
-
299
- private static async _upgradeVersionAsync(projPath: string, projNpmConf: INpmConfig, allPkgPaths: string[]): Promise<void> {
300
- // 작업공간 package.json 버전 설정
301
- const newVersion = semver.inc(projNpmConf.version, "patch")!;
302
- projNpmConf.version = newVersion;
303
-
304
- const pkgNames = await allPkgPaths.mapAsync(async (pkgPath) => {
305
- const pkgNpmConf = await FsUtil.readJsonAsync(path.resolve(pkgPath, "package.json"));
306
- return pkgNpmConf.name;
307
- });
308
-
309
- const updateDepVersion = (deps: Record<string, string> | undefined): void => {
310
- if (!deps) return;
311
- for (const depName of Object.keys(deps)) {
312
- if (pkgNames.includes(depName)) {
313
- deps[depName] = newVersion;
321
+ private static async _publishPkgAsync(pkgPath: string, pkgPubConf: TSdCliPackageConfig["publish"]): Promise<void> {
322
+ if (pkgPubConf === "npm") {
323
+ await SdProcess.spawnAsync("yarn npm publish --access public", {cwd: pkgPath});
324
+ } else {
325
+ throw new NotImplementError();
314
326
  }
315
- }
316
- };
317
- updateDepVersion(projNpmConf.dependencies);
318
- updateDepVersion(projNpmConf.optionalDependencies);
319
- updateDepVersion(projNpmConf.devDependencies);
320
- updateDepVersion(projNpmConf.peerDependencies);
321
-
322
- const projNpmConfFilePath = path.resolve(projPath, "package.json");
323
- await FsUtil.writeJsonAsync(projNpmConfFilePath, projNpmConf, { space: 2 });
324
-
325
- // 각 패키지 package.json 버전 설정
326
- await allPkgPaths.parallelAsync(async (pkgPath) => {
327
- const pkgNpmConfFilePath = path.resolve(pkgPath, "package.json");
328
- const pkgNpmConf = await FsUtil.readJsonAsync(pkgNpmConfFilePath);
329
- pkgNpmConf.version = newVersion;
330
-
331
- updateDepVersion(pkgNpmConf.dependencies);
332
- updateDepVersion(pkgNpmConf.optionalDependencies);
333
- updateDepVersion(pkgNpmConf.devDependencies);
334
- updateDepVersion(pkgNpmConf.peerDependencies);
335
-
336
- await FsUtil.writeJsonAsync(pkgNpmConfFilePath, pkgNpmConf, { space: 2 });
337
- });
338
- }
339
-
340
- private static _logging(buildResults: ISdCliPackageBuildResult[], logger: Logger): void {
341
- const messages = buildResults.filter((item) => item.severity === "message");
342
- const suggestions = buildResults.filter((item) => item.severity === "suggestion");
343
- const warnings = buildResults.filter((item) => item.severity === "warning");
344
- const errors = buildResults.filter((item) => item.severity === "error");
345
-
346
- if (messages.length > 0) {
347
- logger.log("\n" + messages.map((item) => SdCliBuildResultUtil.getMessage(item)).join("\n"));
348
- }
349
- if (suggestions.length > 0) {
350
- logger.info("\n" + suggestions.map((item) => SdCliBuildResultUtil.getMessage(item)).join("\n"));
351
327
  }
352
- if (warnings.length > 0) {
353
- logger.warn("\n" + warnings.map((item) => SdCliBuildResultUtil.getMessage(item)).join("\n"));
354
- }
355
- if (errors.length > 0) {
356
- logger.error("\n" + errors.map((item) => SdCliBuildResultUtil.getMessage(item)).join("\n"));
357
- }
358
-
359
- logger.info("모든 빌드가 완료되었습니다.");
360
- }
361
-
362
- private static async _prepareClusterAsync(): Promise<cp.ChildProcess> {
363
- const logger = Logger.get(["simplysm", "sd-cli", "SdCliProject", "_runBuildClusterAsync"]);
364
328
 
365
- return await new Promise<cp.ChildProcess>(async (resolve, reject) => {
366
- const cluster = cp.fork(
367
- fileURLToPath(await import.meta.resolve!("../build-cluster")),
368
- [],
369
- {
370
- stdio: ["pipe", "pipe", "pipe", "ipc"],
371
- env: process.env
329
+ private static async _waitSecMessageAsync(msg: string, sec: number): Promise<void> {
330
+ for (let i = sec; i > 0; i--) {
331
+ if (i !== sec) {
332
+ process.stdout.cursorTo(0);
333
+ }
334
+ process.stdout.write(`${msg} ${i}`);
335
+ await Wait.time(1000);
372
336
  }
373
- );
374
337
 
375
- cluster.stdout!.pipe(process.stdout);
376
- cluster.stderr!.pipe(process.stderr);
338
+ process.stdout.cursorTo(0);
339
+ process.stdout.clearLine(0);
340
+ }
377
341
 
378
- cluster.on("exit", (code) => {
379
- if (code != null && code !== 0) {
380
- const err = new Error(`오류와 함께 닫힘 (${code})`);
381
- logger.error(err);
382
- reject(err);
383
- return;
384
- }
385
- });
342
+ private static async _upgradeVersionAsync(projNpmConf: INpmConfig, allPkgPaths: string[]): Promise<void> {
343
+ // 작업공간 package.json 버전 설정
344
+ const newVersion = semver.inc(projNpmConf.version, "patch")!;
345
+ projNpmConf.version = newVersion;
346
+
347
+ const pkgNames = await allPkgPaths.mapAsync(async (pkgPath) => {
348
+ const pkgNpmConf = await FsUtil.readJsonAsync(path.resolve(pkgPath, "package.json"));
349
+ return pkgNpmConf.name;
350
+ });
351
+
352
+ const updateDepVersion = (deps: Record<string, string> | undefined): void => {
353
+ if (!deps) return;
354
+ for (const depName of Object.keys(deps)) {
355
+ if (pkgNames.includes(depName)) {
356
+ deps[depName] = newVersion;
357
+ }
358
+ }
359
+ };
360
+ updateDepVersion(projNpmConf.dependencies);
361
+ updateDepVersion(projNpmConf.optionalDependencies);
362
+ updateDepVersion(projNpmConf.devDependencies);
363
+ updateDepVersion(projNpmConf.peerDependencies);
364
+
365
+ const projNpmConfFilePath = path.resolve(process.cwd(), "package.json");
366
+ await FsUtil.writeJsonAsync(projNpmConfFilePath, projNpmConf, {space: 2});
367
+
368
+ // 각 패키지 package.json 버전 설정
369
+ await allPkgPaths.parallelAsync(async (pkgPath) => {
370
+ const pkgNpmConfFilePath = path.resolve(pkgPath, "package.json");
371
+ const pkgNpmConf = await FsUtil.readJsonAsync(pkgNpmConfFilePath);
372
+ pkgNpmConf.version = newVersion;
373
+
374
+ updateDepVersion(pkgNpmConf.dependencies);
375
+ updateDepVersion(pkgNpmConf.optionalDependencies);
376
+ updateDepVersion(pkgNpmConf.devDependencies);
377
+ updateDepVersion(pkgNpmConf.peerDependencies);
378
+
379
+ await FsUtil.writeJsonAsync(pkgNpmConfFilePath, pkgNpmConf, {space: 2});
380
+ });
381
+ }
386
382
 
387
- cluster.on("error", (err) => {
388
- logger.error(err);
389
- reject(err);
390
- });
383
+ private static _logging(buildResults: ISdCliPackageBuildResult[], logger: Logger): void {
384
+ const messages = buildResults.filter((item) => item.severity === "message");
385
+ const suggestions = buildResults.filter((item) => item.severity === "suggestion");
386
+ const warnings = buildResults.filter((item) => item.severity === "warning");
387
+ const errors = buildResults.filter((item) => item.severity === "error");
391
388
 
392
- cluster.on("message", (message) => {
393
- if (message === "ready") {
394
- logger.debug("빌드 클러스터 프로세스가 준비되었습니다.");
395
- resolve(cluster);
389
+ if (messages.length > 0) {
390
+ logger.log("\n" + messages.map((item) => SdCliBuildResultUtil.getMessage(item)).join("\n"));
396
391
  }
397
- });
398
- });
399
- }
400
-
401
- private static async _runCommandAsync(cluster: cp.ChildProcess, cmd: "watch", pkgPath: string, pkgConf: TSdCliPackageConfig): Promise<void>;
402
- private static async _runCommandAsync(cluster: cp.ChildProcess, cmd: "build", pkgPath: string, pkgConf: TSdCliPackageConfig): Promise<ISdCliPackageBuildResult[]>;
403
- private static async _runCommandAsync(cluster: cp.ChildProcess, cmd: "watch" | "build", pkgPath: string, pkgConf: TSdCliPackageConfig): Promise<ISdCliPackageBuildResult[] | void> {
404
- return await new Promise<ISdCliPackageBuildResult[] | void>((resolve) => {
405
- const cb = (message: ISdCliBuildClusterResMessage): void => {
406
- if (cmd === "watch" && message.type === "ready" && message.req.cmd === cmd && message.req.pkgPath === pkgPath) {
407
- cluster.off("message", cb);
408
- resolve();
392
+ if (suggestions.length > 0) {
393
+ logger.info("\n" + suggestions.map((item) => SdCliBuildResultUtil.getMessage(item)).join("\n"));
409
394
  }
410
- else if (cmd === "build" && message.type === "complete" && message.req.cmd === cmd && message.req.pkgPath === pkgPath) {
411
- cluster.off("message", cb);
412
- resolve(message.result?.buildResults);
395
+ if (warnings.length > 0) {
396
+ logger.warn("\n" + warnings.map((item) => SdCliBuildResultUtil.getMessage(item)).join("\n"));
397
+ }
398
+ if (errors.length > 0) {
399
+ logger.error("\n" + errors.map((item) => SdCliBuildResultUtil.getMessage(item)).join("\n"));
413
400
  }
414
- };
415
- cluster.on("message", cb);
416
401
 
417
- cluster.send({ cmd, pkgPath, pkgConf } as ISdCliBuildClusterReqMessage);
418
- });
419
- }
402
+ logger.info("모든 빌드가 완료되었습니다.");
403
+ }
420
404
 
421
- private static _closeCluster(cluster: cp.ChildProcess): void {
422
- cluster.kill("SIGKILL");
423
- }
405
+ private static async _prepareClusterAsync(): Promise<cp.ChildProcess> {
406
+ const logger = Logger.get(["simplysm", "sd-cli", "SdCliProject", "_runBuildClusterAsync"]);
424
407
 
425
- private static async _restartServerAsync(pkgPath: string, prevServerProcess?: cp.ChildProcess): Promise<{ worker: cp.ChildProcess, port: number }> {
426
- const logger = Logger.get(["simplysm", "sd-cli", "SdCliProject", "_restartServerAsync"]);
408
+ return await new Promise<cp.ChildProcess>(async (resolve, reject) => {
409
+ const cluster = cp.fork(
410
+ fileURLToPath(await import.meta.resolve!("../build-cluster")),
411
+ [],
412
+ {
413
+ stdio: ["pipe", "pipe", "pipe", "ipc"],
414
+ env: process.env
415
+ }
416
+ );
417
+
418
+ cluster.stdout!.pipe(process.stdout);
419
+ cluster.stderr!.pipe(process.stderr);
420
+
421
+ cluster.on("exit", (code) => {
422
+ if (code != null && code !== 0) {
423
+ const err = new Error(`오류와 함께 닫힘 (${code})`);
424
+ logger.error(err);
425
+ reject(err);
426
+ return;
427
+ }
428
+ });
429
+
430
+ cluster.on("error", (err) => {
431
+ logger.error(err);
432
+ reject(err);
433
+ });
427
434
 
428
- if (prevServerProcess) {
429
- prevServerProcess.kill("SIGKILL");
435
+ cluster.on("message", (message) => {
436
+ if (message === "ready") {
437
+ logger.debug("빌드 클러스터 프로세스가 준비되었습니다.");
438
+ resolve(cluster);
439
+ }
440
+ });
441
+ });
430
442
  }
431
443
 
432
- return await new Promise<{ worker: cp.ChildProcess, port: number }>(async (resolve, reject) => {
433
- const worker = cp.fork(
434
- fileURLToPath(await import.meta.resolve!("../server-worker")),
435
- [pkgPath],
436
- {
437
- stdio: ["pipe", "pipe", "pipe", "ipc"],
438
- env: process.env
439
- }
440
- );
444
+ private static async _runCommandAsync(cluster: cp.ChildProcess, cmd: "watch", pkgPath: string, pkgConf: TSdCliPackageConfig, withLint: boolean, builderKey?: string): Promise<void>;
445
+ private static async _runCommandAsync(cluster: cp.ChildProcess, cmd: "build", pkgPath: string, pkgConf: TSdCliPackageConfig, withLint: boolean, builderKey?: string): Promise<ISdCliPackageBuildResult[]>;
446
+ private static async _runCommandAsync(cluster: cp.ChildProcess, cmd: "watch" | "build", pkgPath: string, pkgConf: TSdCliPackageConfig, withLint: boolean, builderKey?: string): Promise<ISdCliPackageBuildResult[] | void> {
447
+ return await new Promise<ISdCliPackageBuildResult[] | void>((resolve) => {
448
+ const cb = (message: ISdCliBuildClusterResMessage): void => {
449
+ if (cmd === "watch" && message.type === "ready" && message.req.cmd === cmd && message.req.pkgPath === pkgPath) {
450
+ cluster.off("message", cb);
451
+ resolve();
452
+ } else if (cmd === "build" && message.type === "complete" && message.req.cmd === cmd && message.req.pkgPath === pkgPath) {
453
+ cluster.off("message", cb);
454
+ resolve(message.result?.buildResults);
455
+ }
456
+ };
457
+ cluster.on("message", cb);
458
+
459
+ cluster.send({
460
+ cmd,
461
+ pkgPath,
462
+ pkgConf,
463
+ builderKey,
464
+ withLint
465
+ } as ISdCliBuildClusterReqMessage);
466
+ });
467
+ }
441
468
 
442
- worker.stdout!.pipe(process.stdout);
443
- worker.stderr!.pipe(process.stderr);
469
+ private static _closeCluster(cluster: cp.ChildProcess): void {
470
+ cluster.kill("SIGKILL");
471
+ }
472
+
473
+ private static async _restartServerAsync(pkgPath: string, prevServerProcess?: cp.ChildProcess): Promise<{
474
+ worker: cp.ChildProcess,
475
+ port: number
476
+ }> {
477
+ const logger = Logger.get(["simplysm", "sd-cli", "SdCliProject", "_restartServerAsync"]);
444
478
 
445
- worker.on("exit", (code) => {
446
- if (code != null && code !== 0) {
447
- const err = new Error(`오류와 함께 닫힘 (${code})`);
448
- logger.error(err);
449
- reject(err);
450
- return;
479
+ if (prevServerProcess) {
480
+ prevServerProcess.kill("SIGKILL");
451
481
  }
452
- });
453
482
 
454
- worker.on("error", (err) => {
455
- logger.error(err);
456
- reject(err);
457
- });
483
+ return await new Promise<{
484
+ worker: cp.ChildProcess,
485
+ port: number
486
+ }>(async (resolve, reject) => {
487
+ const worker = cp.fork(
488
+ fileURLToPath(await import.meta.resolve!("../server-worker")),
489
+ [pkgPath],
490
+ {
491
+ stdio: ["pipe", "pipe", "pipe", "ipc"],
492
+ env: process.env
493
+ }
494
+ );
458
495
 
459
- worker.on("message", (message: any) => {
460
- if ("port" in message) {
461
- logger.debug("서버가 시작되었습니다.");
462
- resolve({ worker, port: message.port });
463
- }
464
- });
465
- });
466
- }
496
+ worker.stdout!.pipe(process.stdout);
497
+ worker.stderr!.pipe(process.stderr);
498
+
499
+ worker.on("exit", (code) => {
500
+ if (code != null && code !== 0) {
501
+ const err = new Error(`오류와 함께 닫힘 (${code})`);
502
+ logger.error(err);
503
+ reject(err);
504
+ return;
505
+ }
506
+ });
507
+
508
+ worker.on("error", (err) => {
509
+ logger.error(err);
510
+ reject(err);
511
+ });
512
+
513
+ worker.on("message", (message: any) => {
514
+ if ("port" in message) {
515
+ logger.debug("서버가 시작되었습니다.");
516
+ resolve({
517
+ worker,
518
+ port: message.port
519
+ });
520
+ }
521
+ });
522
+ });
523
+ }
467
524
  }