@simplysm/sd-cli 12.5.21 → 12.5.22

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 (195) hide show
  1. package/dist/{build-tools → entry}/SdCliCordova.d.ts +5 -6
  2. package/dist/{build-tools → entry}/SdCliCordova.js +117 -99
  3. package/dist/entry/SdCliCordova.js.map +1 -0
  4. package/dist/entry/SdCliElectron.d.ts +2 -2
  5. package/dist/entry/SdCliElectron.js +50 -40
  6. package/dist/entry/SdCliElectron.js.map +1 -1
  7. package/dist/entry/SdCliLocalUpdate.d.ts +1 -2
  8. package/dist/entry/SdCliLocalUpdate.js +26 -27
  9. package/dist/entry/SdCliLocalUpdate.js.map +1 -1
  10. package/dist/entry/SdCliProject.d.ts +1 -5
  11. package/dist/entry/SdCliProject.js +62 -288
  12. package/dist/entry/SdCliProject.js.map +1 -1
  13. package/dist/index.d.ts +23 -20
  14. package/dist/index.js +23 -20
  15. package/dist/index.js.map +1 -1
  16. package/dist/pkg-builders/SdMultiBuildRunner.d.ts +21 -0
  17. package/dist/pkg-builders/SdMultiBuildRunner.js +174 -0
  18. package/dist/pkg-builders/SdMultiBuildRunner.js.map +1 -0
  19. package/dist/pkg-builders/client/SdCliNgRoutesFileGenerator.d.ts +4 -0
  20. package/dist/{build-tools → pkg-builders/client}/SdCliNgRoutesFileGenerator.js +7 -7
  21. package/dist/pkg-builders/client/SdCliNgRoutesFileGenerator.js.map +1 -0
  22. package/dist/pkg-builders/client/SdClientBuildRunner.d.ts +20 -0
  23. package/dist/pkg-builders/client/SdClientBuildRunner.js +135 -0
  24. package/dist/pkg-builders/client/SdClientBuildRunner.js.map +1 -0
  25. package/dist/pkg-builders/client/SdNgBundler.d.ts +29 -0
  26. package/dist/{build-tools → pkg-builders/client}/SdNgBundler.js +100 -95
  27. package/dist/pkg-builders/client/SdNgBundler.js.map +1 -0
  28. package/dist/{build-tools → pkg-builders/client}/SdNgBundlerContext.d.ts +1 -2
  29. package/dist/{build-tools → pkg-builders/client}/SdNgBundlerContext.js +19 -45
  30. package/dist/pkg-builders/client/SdNgBundlerContext.js.map +1 -0
  31. package/dist/pkg-builders/client/createSdNgPlugin.d.ts +10 -0
  32. package/dist/{bundle-plugins/sdNgPlugin.js → pkg-builders/client/createSdNgPlugin.js} +32 -33
  33. package/dist/pkg-builders/client/createSdNgPlugin.js.map +1 -0
  34. package/dist/pkg-builders/lib/SdCliIndexFileGenerator.d.ts +5 -0
  35. package/dist/{build-tools → pkg-builders/lib}/SdCliIndexFileGenerator.js +11 -11
  36. package/dist/pkg-builders/lib/SdCliIndexFileGenerator.js.map +1 -0
  37. package/dist/pkg-builders/lib/SdJsLibBuildRunner.d.ts +16 -0
  38. package/dist/pkg-builders/lib/SdJsLibBuildRunner.js +81 -0
  39. package/dist/pkg-builders/lib/SdJsLibBuildRunner.js.map +1 -0
  40. package/dist/pkg-builders/lib/SdTsLibBuildRunner.d.ts +13 -0
  41. package/dist/pkg-builders/lib/SdTsLibBuildRunner.js +89 -0
  42. package/dist/pkg-builders/lib/SdTsLibBuildRunner.js.map +1 -0
  43. package/dist/pkg-builders/lib/SdTsLibBuilder.d.ts +14 -0
  44. package/dist/pkg-builders/lib/SdTsLibBuilder.js +54 -0
  45. package/dist/pkg-builders/lib/SdTsLibBuilder.js.map +1 -0
  46. package/dist/pkg-builders/server/SdServerBuildRunner.d.ts +17 -0
  47. package/dist/{builders/SdCliServerBuilder.js → pkg-builders/server/SdServerBuildRunner.js} +48 -53
  48. package/dist/pkg-builders/server/SdServerBuildRunner.js.map +1 -0
  49. package/dist/pkg-builders/server/SdServerBundler.d.ts +19 -0
  50. package/dist/{build-tools → pkg-builders/server}/SdServerBundler.js +25 -30
  51. package/dist/pkg-builders/server/SdServerBundler.js.map +1 -0
  52. package/dist/pkg-builders/server/createSdServerPlugin.d.ts +10 -0
  53. package/dist/pkg-builders/server/createSdServerPlugin.js +53 -0
  54. package/dist/pkg-builders/server/createSdServerPlugin.js.map +1 -0
  55. package/dist/sd-cli.js +61 -54
  56. package/dist/sd-cli.js.map +1 -1
  57. package/dist/ts-builder/SdTsCompileWorker.d.ts +9 -0
  58. package/dist/ts-builder/SdTsCompileWorker.js +16 -0
  59. package/dist/ts-builder/SdTsCompileWorker.js.map +1 -0
  60. package/dist/ts-builder/SdTsCompiler.d.ts +7 -0
  61. package/dist/{build-tools → ts-builder}/SdTsCompiler.js +226 -212
  62. package/dist/ts-builder/SdTsCompiler.js.map +1 -0
  63. package/dist/types/build-plugin.type.d.ts +14 -0
  64. package/dist/types/build-plugin.type.js +2 -0
  65. package/dist/types/build-plugin.type.js.map +1 -0
  66. package/dist/types/build.type.d.ts +15 -0
  67. package/dist/types/build.type.js +2 -0
  68. package/dist/types/build.type.js.map +1 -0
  69. package/dist/types/common-configs.type.d.ts +22 -0
  70. package/dist/types/common-configs.type.js +2 -0
  71. package/dist/types/common-configs.type.js.map +1 -0
  72. package/dist/types/sd-configs.type.d.ts +99 -0
  73. package/dist/types/sd-configs.type.js +2 -0
  74. package/dist/types/sd-configs.type.js.map +1 -0
  75. package/dist/types/ts-compiler.type.d.ts +29 -0
  76. package/dist/types/ts-compiler.type.js +2 -0
  77. package/dist/types/ts-compiler.type.js.map +1 -0
  78. package/dist/types/workers.type.d.ts +49 -0
  79. package/dist/types/workers.type.js +2 -0
  80. package/dist/types/workers.type.js.map +1 -0
  81. package/dist/utils/SdCliConvertMessageUtil.d.ts +21 -0
  82. package/dist/utils/SdCliConvertMessageUtil.js +137 -0
  83. package/dist/utils/SdCliConvertMessageUtil.js.map +1 -0
  84. package/dist/workers/compile-worker.js +27 -0
  85. package/dist/workers/compile-worker.js.map +1 -0
  86. package/dist/workers/lint-worker.js +36 -0
  87. package/dist/workers/lint-worker.js.map +1 -0
  88. package/dist/workers/server-worker.d.ts +1 -0
  89. package/dist/workers/server-worker.js +49 -0
  90. package/dist/workers/server-worker.js.map +1 -0
  91. package/lib/dev-worker.cjs +5 -0
  92. package/package.json +7 -10
  93. package/src/entry/SdCliCordova.ts +363 -0
  94. package/src/entry/SdCliElectron.ts +96 -69
  95. package/src/entry/SdCliLocalUpdate.ts +43 -44
  96. package/src/entry/SdCliProject.ts +72 -417
  97. package/src/index.ts +23 -20
  98. package/src/pkg-builders/SdMultiBuildRunner.ts +250 -0
  99. package/src/{build-tools → pkg-builders/client}/SdCliNgRoutesFileGenerator.ts +7 -7
  100. package/src/pkg-builders/client/SdClientBuildRunner.ts +191 -0
  101. package/src/{build-tools → pkg-builders/client}/SdNgBundler.ts +125 -121
  102. package/src/pkg-builders/client/SdNgBundlerContext.ts +111 -0
  103. package/src/{bundle-plugins/sdNgPlugin.ts → pkg-builders/client/createSdNgPlugin.ts} +43 -46
  104. package/src/{build-tools → pkg-builders/lib}/SdCliIndexFileGenerator.ts +11 -11
  105. package/src/pkg-builders/lib/SdJsLibBuildRunner.ts +105 -0
  106. package/src/pkg-builders/lib/SdTsLibBuildRunner.ts +128 -0
  107. package/src/pkg-builders/lib/SdTsLibBuilder.ts +69 -0
  108. package/src/{builders/SdCliServerBuilder.ts → pkg-builders/server/SdServerBuildRunner.ts} +66 -78
  109. package/src/{build-tools → pkg-builders/server}/SdServerBundler.ts +40 -41
  110. package/src/pkg-builders/server/createSdServerPlugin.ts +77 -0
  111. package/src/sd-cli.ts +197 -211
  112. package/src/ts-builder/SdTsCompileWorker.ts +21 -0
  113. package/src/ts-builder/SdTsCompiler.ts +758 -0
  114. package/src/types/build-plugin.type.ts +16 -0
  115. package/src/types/build.type.ts +17 -0
  116. package/src/types/common-configs.type.ts +27 -0
  117. package/src/types/sd-configs.type.ts +114 -0
  118. package/src/types/ts-compiler.type.ts +29 -0
  119. package/src/types/workers.type.ts +27 -0
  120. package/src/utils/SdCliConvertMessageUtil.ts +177 -0
  121. package/src/workers/compile-worker.ts +31 -0
  122. package/src/workers/lint-worker.ts +44 -0
  123. package/src/workers/server-worker.ts +52 -0
  124. package/tsconfig.json +7 -1
  125. package/dist/build-cluster.js +0 -201
  126. package/dist/build-cluster.js.map +0 -1
  127. package/dist/build-tools/SdCliCordova.js.map +0 -1
  128. package/dist/build-tools/SdCliIndexFileGenerator.d.ts +0 -5
  129. package/dist/build-tools/SdCliIndexFileGenerator.js.map +0 -1
  130. package/dist/build-tools/SdCliNgRoutesFileGenerator.d.ts +0 -4
  131. package/dist/build-tools/SdCliNgRoutesFileGenerator.js.map +0 -1
  132. package/dist/build-tools/SdLinter.d.ts +0 -5
  133. package/dist/build-tools/SdLinter.js +0 -49
  134. package/dist/build-tools/SdLinter.js.map +0 -1
  135. package/dist/build-tools/SdNgBundler.d.ts +0 -29
  136. package/dist/build-tools/SdNgBundler.js.map +0 -1
  137. package/dist/build-tools/SdNgBundlerContext.js.map +0 -1
  138. package/dist/build-tools/SdReactBundler.d.ts +0 -25
  139. package/dist/build-tools/SdReactBundler.js +0 -295
  140. package/dist/build-tools/SdReactBundler.js.map +0 -1
  141. package/dist/build-tools/SdReactBundlerContext.d.ts +0 -14
  142. package/dist/build-tools/SdReactBundlerContext.js +0 -59
  143. package/dist/build-tools/SdReactBundlerContext.js.map +0 -1
  144. package/dist/build-tools/SdServerBundler.d.ts +0 -20
  145. package/dist/build-tools/SdServerBundler.js.map +0 -1
  146. package/dist/build-tools/SdTsCompiler.d.ts +0 -34
  147. package/dist/build-tools/SdTsCompiler.js.map +0 -1
  148. package/dist/build-tools/SdTsLibBundler.d.ts +0 -13
  149. package/dist/build-tools/SdTsLibBundler.js +0 -58
  150. package/dist/build-tools/SdTsLibBundler.js.map +0 -1
  151. package/dist/builders/SdCliClientBuilder.d.ts +0 -18
  152. package/dist/builders/SdCliClientBuilder.js +0 -172
  153. package/dist/builders/SdCliClientBuilder.js.map +0 -1
  154. package/dist/builders/SdCliJsLibLinter.d.ts +0 -13
  155. package/dist/builders/SdCliJsLibLinter.js +0 -60
  156. package/dist/builders/SdCliJsLibLinter.js.map +0 -1
  157. package/dist/builders/SdCliServerBuilder.d.ts +0 -15
  158. package/dist/builders/SdCliServerBuilder.js.map +0 -1
  159. package/dist/builders/SdCliTsLibBuilder.d.ts +0 -12
  160. package/dist/builders/SdCliTsLibBuilder.js +0 -90
  161. package/dist/builders/SdCliTsLibBuilder.js.map +0 -1
  162. package/dist/bundle-plugins/sdNgPlugin.d.ts +0 -16
  163. package/dist/bundle-plugins/sdNgPlugin.js.map +0 -1
  164. package/dist/bundle-plugins/sdReactPlugin.d.ts +0 -16
  165. package/dist/bundle-plugins/sdReactPlugin.js +0 -117
  166. package/dist/bundle-plugins/sdReactPlugin.js.map +0 -1
  167. package/dist/bundle-plugins/sdServerPlugin.d.ts +0 -16
  168. package/dist/bundle-plugins/sdServerPlugin.js +0 -63
  169. package/dist/bundle-plugins/sdServerPlugin.js.map +0 -1
  170. package/dist/commons.d.ts +0 -145
  171. package/dist/commons.js +0 -2
  172. package/dist/commons.js.map +0 -1
  173. package/dist/server-worker.js +0 -57
  174. package/dist/server-worker.js.map +0 -1
  175. package/dist/utils/SdCliBuildResultUtil.d.ts +0 -16
  176. package/dist/utils/SdCliBuildResultUtil.js +0 -54
  177. package/dist/utils/SdCliBuildResultUtil.js.map +0 -1
  178. package/src/build-cluster.ts +0 -212
  179. package/src/build-tools/SdCliCordova.ts +0 -340
  180. package/src/build-tools/SdLinter.ts +0 -65
  181. package/src/build-tools/SdNgBundlerContext.ts +0 -137
  182. package/src/build-tools/SdReactBundler.ts +0 -372
  183. package/src/build-tools/SdReactBundlerContext.ts +0 -71
  184. package/src/build-tools/SdTsCompiler.ts +0 -754
  185. package/src/build-tools/SdTsLibBundler.ts +0 -72
  186. package/src/builders/SdCliClientBuilder.ts +0 -233
  187. package/src/builders/SdCliJsLibLinter.ts +0 -72
  188. package/src/builders/SdCliTsLibBuilder.ts +0 -126
  189. package/src/bundle-plugins/sdReactPlugin.ts +0 -164
  190. package/src/bundle-plugins/sdServerPlugin.ts +0 -94
  191. package/src/commons.ts +0 -171
  192. package/src/server-worker.ts +0 -65
  193. package/src/utils/SdCliBuildResultUtil.ts +0 -63
  194. /package/dist/{build-cluster.d.ts → workers/compile-worker.d.ts} +0 -0
  195. /package/dist/{server-worker.d.ts → workers/lint-worker.d.ts} +0 -0
@@ -1,24 +1,19 @@
1
1
  import path from "path";
2
2
  import { FsUtil, Logger, PathUtil, SdProcess } from "@simplysm/sd-core-node";
3
- import {
4
- INpmConfig,
5
- ISdCliBuildClusterResMessage,
6
- ISdCliConfig,
7
- ISdCliPackageBuildResult,
8
- ISdCliServerPackageConfig,
9
- TSdCliPackageConfig,
10
- } from "../commons";
11
- import cp from "child_process";
12
- import { fileURLToPath, pathToFileURL } from "url";
13
- import { SdCliBuildResultUtil } from "../utils/SdCliBuildResultUtil";
3
+ import { pathToFileURL } from "url";
14
4
  import semver from "semver";
15
- import { JsonConvert, NeverEntryError, StringUtil, Wait } from "@simplysm/sd-core-common";
5
+ import { NeverEntryError, StringUtil, Wait } from "@simplysm/sd-core-common";
16
6
  import { SdStorage } from "@simplysm/sd-storage";
17
7
  import { SdCliLocalUpdate } from "./SdCliLocalUpdate";
18
8
  import xml2js from "xml2js";
9
+ import { SdMultiBuildRunner } from "../pkg-builders/SdMultiBuildRunner";
10
+ import { SdCliConvertMessageUtil } from "../utils/SdCliConvertMessageUtil";
11
+ import { ISdProjectConfig, TSdPackageConfig } from "../types/sd-configs.type";
12
+ import { INpmConfig } from "../types/common-configs.type";
13
+ import { ISdBuildMessage } from "../types/build.type";
19
14
 
20
15
  export class SdCliProject {
21
- public static async watchAsync(opt: {
16
+ static async watchAsync(opt: {
22
17
  confFileRelPath: string;
23
18
  optNames: string[];
24
19
  pkgNames: string[];
@@ -30,7 +25,7 @@ export class SdCliProject {
30
25
  const projConf = (await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)).default(
31
26
  true,
32
27
  opt.optNames,
33
- ) as ISdCliConfig;
28
+ ) as ISdProjectConfig;
34
29
 
35
30
  if (projConf.localUpdates) {
36
31
  logger.debug("로컬 라이브러리 업데이트 변경감지 시작...");
@@ -41,15 +36,16 @@ export class SdCliProject {
41
36
  }
42
37
 
43
38
  logger.debug("프로젝트 package.json 가져오기...");
44
- const projNpmConf = (await FsUtil.readJsonAsync(path.resolve(process.cwd(), "package.json"))) as INpmConfig;
39
+ const projNpmConf = FsUtil.readJson(path.resolve(process.cwd(), "package.json")) as INpmConfig;
45
40
 
46
41
  logger.debug("패키지 목록 구성...");
47
42
  if (!projNpmConf.workspaces) {
48
43
  throw new Error("프로젝트 package.json에 workspaces가 설정되어있지 않습니다.");
49
44
  }
50
- const allPkgPaths = (
51
- await projNpmConf.workspaces.mapManyAsync(async (item) => await FsUtil.globAsync(item))
52
- ).filter((item) => !item.includes("."));
45
+ const allPkgPaths = projNpmConf.workspaces
46
+ .mapMany((item) => FsUtil.glob(item))
47
+ .filter((item) => !item.includes("."))
48
+ .map((item) => PathUtil.norm(item));
53
49
  let pkgPaths = allPkgPaths.filter((pkgPath) => path.basename(pkgPath) in projConf.packages);
54
50
  if (opt.pkgNames.length !== 0) {
55
51
  pkgPaths = pkgPaths.filter((pkgPath) => opt.pkgNames.includes(path.basename(pkgPath)));
@@ -63,209 +59,41 @@ export class SdCliProject {
63
59
  throw new Error("패키지를 찾을 수 없습니다. (" + notExistsPkgs.join(", ") + ")");
64
60
  }
65
61
 
66
- logger.debug("빌드 프로세스 준비...");
67
- const cluster = await this._prepareClusterAsync();
68
-
69
- logger.debug("빌드 프로세스 이벤트 준비...");
70
- const resultCache = new Map<string, ISdCliPackageBuildResult[]>();
71
- let busyReqCntMap = new Map<string, number>();
72
- const serverInfoMap = new Map<
73
- string,
74
- {
75
- // server
76
- pkgOrOpt?: { path: string; conf: ISdCliServerPackageConfig } | { port: number }; // persist
77
- worker?: cp.ChildProcess; // persist
78
- port?: number;
79
- hasChanges: boolean;
80
- hasClientChanges: boolean;
81
-
82
- //client
83
- pathProxy: Record<string, string | number | undefined>; // persist
84
- // changeFilePaths: string[];
85
- }
86
- >();
87
- cluster.on("message", (message: ISdCliBuildClusterResMessage) => {
88
- if (message.type === "change") {
89
- if (Array.from(busyReqCntMap.values()).every((v) => v === 0)) {
90
- logger.log("빌드를 시작합니다...");
91
- }
92
- busyReqCntMap.set(
93
- message.req.cmd + "|" + message.req.pkgPath,
94
- (busyReqCntMap.get(message.req.cmd + "|" + message.req.pkgPath) ?? 0) + 1,
95
- );
96
- } else if (message.type === "complete") {
97
- resultCache.delete("none");
98
- for (const affectedFilePath of message.result!.affectedFilePaths) {
99
- if (PathUtil.isChildPath(affectedFilePath, message.req.pkgPath)) {
100
- resultCache.delete(affectedFilePath);
101
- }
102
- }
103
-
104
- for (const buildResult of message.result!.buildResults) {
105
- // if (buildResult.filePath == null || PathUtil.isChildPath(buildResult.filePath, message.req.pkgPath)) {
106
- const cacheItem = resultCache.getOrCreate(buildResult.filePath ?? "none", []);
107
- cacheItem.push(buildResult);
108
- // }
109
- }
110
-
111
- const pkgConf = message.req.projConf.packages[path.basename(message.req.pkgPath)]!;
112
-
113
- if (pkgConf.type === "server") {
114
- const pkgName = path.basename(message.req.pkgPath);
115
- const serverInfo = serverInfoMap.getOrCreate(pkgName, {
116
- hasChanges: true,
117
- hasClientChanges: false,
118
- pathProxy: {},
119
- // changeFilePaths: []
120
- });
121
-
122
- const serverPkgConf = projConf.packages[pkgName] as ISdCliServerPackageConfig;
123
- serverInfo.pkgOrOpt = {
124
- path: message.req.pkgPath,
125
- conf: serverPkgConf,
126
- };
127
-
128
- serverInfo.hasChanges = true;
129
- }
130
-
131
- if (pkgConf.type === "client") {
132
- const pkgName = path.basename(message.req.pkgPath);
133
-
134
- if (pkgConf.server !== undefined) {
135
- const serverInfo = serverInfoMap.getOrCreate(
136
- typeof pkgConf.server === "string" ? pkgConf.server : pkgConf.server.port.toString(),
137
- {
138
- hasChanges: true,
139
- hasClientChanges: false,
140
- pathProxy: {},
141
- // changeFilePaths: []
142
- },
143
- );
144
-
145
- if (typeof pkgConf.server !== "string") {
146
- serverInfo.pkgOrOpt = pkgConf.server;
147
- }
148
-
149
- serverInfo.pathProxy[pkgName] = path.resolve(message.req.pkgPath, "dist");
150
- serverInfo.pathProxy["node_modules"] = path.resolve(process.cwd(), "node_modules");
151
- // serverInfo.changeFilePaths.push(...message.result!.affectedFilePaths);
152
-
153
- serverInfo.hasClientChanges = true;
154
- // serverInfo.worker?.send({type: "broadcastReload"});
155
- } else {
156
- const serverInfo = serverInfoMap.getOrCreate(pkgName, {
157
- hasChanges: true,
158
- hasClientChanges: false,
159
- pathProxy: {},
160
- // changeFilePaths: []
161
- });
162
- // serverInfo.port = message.result!.port;
163
- // serverInfo.changeFilePaths.push(...message.result!.affectedFilePaths);
164
-
165
- serverInfo.hasClientChanges = true;
166
- // serverInfo.worker?.send({type: "broadcastReload"});
167
- }
168
- }
169
-
170
- setTimeout(async () => {
171
- busyReqCntMap.set(
172
- message.req.cmd + "|" + message.req.pkgPath,
173
- (busyReqCntMap.get(message.req.cmd + "|" + message.req.pkgPath) ?? 0) - 1,
174
- );
175
- logger.debug("남아있는 예약 빌드", busyReqCntMap);
176
- if (Array.from(busyReqCntMap.values()).every((v) => v === 0)) {
177
- for (const serverPkgNameOrPort of serverInfoMap.keys()) {
178
- const serverInfo = serverInfoMap.get(serverPkgNameOrPort)!;
179
- if (serverInfo.pkgOrOpt && serverInfo.hasChanges) {
180
- logger.debug("서버 재시작...");
181
- try {
182
- const restartServerResult = await this._restartServerAsync(serverInfo.pkgOrOpt, serverInfo.worker);
183
- serverInfo.worker = restartServerResult.worker;
184
- serverInfo.port = restartServerResult.port;
185
- serverInfo.hasChanges = false;
186
- } catch (err) {
187
- logger.error(err);
188
- }
189
- }
190
-
191
- if (serverInfo.worker) {
192
- logger.debug("클라이언트 설정...");
193
- serverInfo.worker.send({
194
- type: "setPathProxy",
195
- pathProxy: serverInfo.pathProxy,
196
- });
197
-
198
- if (serverInfo.hasClientChanges) {
199
- logger.debug("클라이언트 새로고침...");
200
- serverInfo.worker.send({ type: "broadcastReload" });
201
- }
202
- }
203
- }
204
-
205
- const clientPaths: string[] = [];
206
- for (const serverInfo of serverInfoMap.values()) {
207
- if (Object.keys(serverInfo.pathProxy).length > 0) {
208
- for (const proxyPath of Object.keys(serverInfo.pathProxy)) {
209
- if (proxyPath === "node_modules") continue;
210
- clientPaths.push(`http://localhost:${serverInfo.port}/${proxyPath}/`);
211
- }
212
- } else {
213
- clientPaths.push(`http://localhost:${serverInfo.port}/`);
214
- }
215
- }
216
- if (clientPaths.length > 0) {
217
- logger.info("클라이언트 개발 서버 접속 주소\n" + clientPaths.join("\n"));
218
- }
219
-
220
- const buildResults = Array.from(resultCache.values()).mapMany();
221
- this._logging(buildResults, logger);
222
- }
223
- }, 300);
224
- }
225
- });
226
-
227
- logger.debug("빌드 프로세스 명령 전송...");
228
- busyReqCntMap.set("all", (busyReqCntMap.get("all") ?? 0) + 1);
229
- logger.log("빌드를 시작합니다...");
62
+ logger.debug("빌드 프로세스 시작...");
63
+ const multiBuildRunner = new SdMultiBuildRunner()
64
+ .on("change", () => {
65
+ logger.debug("빌드를 시작합니다...");
66
+ })
67
+ .on("complete", (messages) => {
68
+ this.#logging(messages, logger);
69
+ });
230
70
 
231
71
  await pkgPaths.parallelAsync(async (pkgPath) => {
232
- await this._runCommandAsync(
233
- cluster,
234
- "watch",
235
- projConf,
72
+ await multiBuildRunner.runAsync({
73
+ cmd: "watch",
236
74
  pkgPath,
237
- opt.inspectNames.includes(path.basename(pkgPath)) ? ["--inspect"] : [],
238
- );
75
+ projConf: projConf,
76
+ });
239
77
  });
240
-
241
- busyReqCntMap.set("all", (busyReqCntMap.get("all") ?? 0) - 1);
242
- if (Array.from(busyReqCntMap.values()).every((v) => v === 0)) {
243
- const buildResults = Array.from(resultCache.values()).mapMany();
244
- this._logging(buildResults, logger);
245
- }
246
78
  }
247
79
 
248
- public static async buildAsync(opt: {
249
- confFileRelPath: string;
250
- optNames: string[];
251
- pkgNames: string[];
252
- }): Promise<void> {
80
+ static async buildAsync(opt: { confFileRelPath: string; optNames: string[]; pkgNames: string[] }): Promise<void> {
253
81
  const logger = Logger.get(["simplysm", "sd-cli", "SdCliProject", "buildAsync"]);
254
82
 
255
83
  logger.debug("프로젝트 설정 가져오기...");
256
84
  const projConf = (await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)).default(
257
85
  false,
258
86
  opt.optNames,
259
- ) as ISdCliConfig;
87
+ ) as ISdProjectConfig;
260
88
 
261
89
  logger.debug("프로젝트 package.json 가져오기...");
262
- const projNpmConf = (await FsUtil.readJsonAsync(path.resolve(process.cwd(), "package.json"))) as INpmConfig;
90
+ const projNpmConf = FsUtil.readJson(path.resolve(process.cwd(), "package.json")) as INpmConfig;
263
91
 
264
92
  logger.debug("패키지 목록 구성...");
265
93
  if (!projNpmConf.workspaces) {
266
94
  throw new Error("프로젝트 package.json에 workspaces가 설정되어있지 않습니다.");
267
95
  }
268
- const allPkgPaths = await projNpmConf.workspaces.mapManyAsync(async (item) => await FsUtil.globAsync(item));
96
+ const allPkgPaths = projNpmConf.workspaces.mapMany((item) => FsUtil.glob(item)).map((item) => PathUtil.norm(item));
269
97
  let pkgPaths = allPkgPaths.filter((pkgPath) => path.basename(pkgPath) in projConf.packages);
270
98
  if (opt.pkgNames.length !== 0) {
271
99
  pkgPaths = pkgPaths.filter((pkgPath) => opt.pkgNames.includes(path.basename(pkgPath)));
@@ -274,29 +102,17 @@ export class SdCliProject {
274
102
  logger.debug("프로젝트 및 패키지 버전 설정...");
275
103
  await this._upgradeVersionAsync(projNpmConf, allPkgPaths);
276
104
 
277
- logger.debug("빌드 프로세스 준비...");
278
- const cluster = await this._prepareClusterAsync();
279
-
280
- logger.debug("빌드 프로세스 명령 전달...");
281
- const results = (
282
- await pkgPaths.parallelAsync(async (pkgPath) => {
283
- /*const pkgConf = projConf.packages[path.basename(pkgPath)]!;
284
- if (pkgConf.type === "client") {
285
- const builderKeys = Object.keys(pkgConf.builder ?? {web: {}});
286
- return (await builderKeys.parallelAsync(async (builderKey) => {
287
- return await this._runCommandAsync(cluster, "build", projConf, pkgPath, builderKey);
288
- })).mapMany();
289
- }
290
- else {
291
- }*/
292
- return await this._runCommandAsync(cluster, "build", projConf, pkgPath);
293
- })
294
- ).mapMany();
295
-
296
- logger.debug("빌드 프로세스 닫기...");
297
- this._closeCluster(cluster);
105
+ logger.debug("빌드 프로세스 시작...");
106
+ const parallelBuildRunner = new SdMultiBuildRunner();
298
107
 
299
- this._logging(results, logger);
108
+ const messages = await pkgPaths.parallelAsync(async (pkgPath) => {
109
+ return await parallelBuildRunner.runAsync({
110
+ cmd: "build",
111
+ pkgPath,
112
+ projConf: projConf,
113
+ });
114
+ });
115
+ this.#logging(messages.mapMany(), logger);
300
116
  }
301
117
 
302
118
  public static async publishAsync(opt: {
@@ -311,10 +127,10 @@ export class SdCliProject {
311
127
  const projConf = (await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)).default(
312
128
  false,
313
129
  opt.optNames,
314
- ) as ISdCliConfig;
130
+ ) as ISdProjectConfig;
315
131
 
316
132
  logger.debug("프로젝트 package.json 가져오기...");
317
- const projNpmConf = (await FsUtil.readJsonAsync(path.resolve(process.cwd(), "package.json"))) as INpmConfig;
133
+ const projNpmConf = FsUtil.readJson(path.resolve(process.cwd(), "package.json")) as INpmConfig;
318
134
 
319
135
  if (opt.noBuild) {
320
136
  logger.warn("빌드하지 않고, 배포하는것은 상당히 위험합니다.");
@@ -334,9 +150,10 @@ export class SdCliProject {
334
150
  if (!projNpmConf.workspaces) {
335
151
  throw new Error("프로젝트 package.json에 workspaces가 설정되어있지 않습니다.");
336
152
  }
337
- const allPkgPaths = (
338
- await projNpmConf.workspaces.mapManyAsync(async (item) => await FsUtil.globAsync(item))
339
- ).filter((item) => !item.includes("."));
153
+ const allPkgPaths = projNpmConf.workspaces
154
+ .mapMany((item) => FsUtil.glob(item))
155
+ .filter((item) => !item.includes("."))
156
+ .map((item) => PathUtil.norm(item));
340
157
  let pkgPaths = allPkgPaths.filter((pkgPath) => path.basename(pkgPath) in projConf.packages);
341
158
  if (opt.pkgNames.length !== 0) {
342
159
  pkgPaths = pkgPaths.filter((pkgPath) => opt.pkgNames.includes(path.basename(pkgPath)));
@@ -347,20 +164,18 @@ export class SdCliProject {
347
164
 
348
165
  // 빌드
349
166
  if (!opt.noBuild) {
350
- logger.debug("빌드 프로세스 준비...");
351
- const cluster = await this._prepareClusterAsync();
352
-
353
- logger.debug("빌드 프로세스 명령 전달...");
354
- const results = (
355
- await pkgPaths.parallelAsync(async (pkgPath) => {
356
- return await this._runCommandAsync(cluster, "build", projConf, pkgPath);
357
- })
358
- ).mapMany();
359
-
360
- logger.debug("빌드 프로세스 닫기...");
361
- this._closeCluster(cluster);
167
+ logger.debug("빌드 프로세스 시작...");
168
+ const parallelBuildRunner = new SdMultiBuildRunner();
169
+
170
+ const messages = await pkgPaths.parallelAsync(async (pkgPath) => {
171
+ return await parallelBuildRunner.runAsync({
172
+ cmd: "build",
173
+ pkgPath,
174
+ projConf: projConf,
175
+ });
176
+ });
362
177
 
363
- this._logging(results, logger);
178
+ this.#logging(messages.mapMany(), logger);
364
179
  }
365
180
 
366
181
  // GIT 사용중일경우, 새 버전 커밋 및 TAG 생성
@@ -411,11 +226,11 @@ export class SdCliProject {
411
226
  logger.info(`모든 배포가 완료되었습니다. (v${projNpmConf.version})`);
412
227
  }
413
228
 
414
- private static async _publishPkgAsync(pkgPath: string, pkgPubConf: TSdCliPackageConfig["publish"]): Promise<void> {
229
+ private static async _publishPkgAsync(pkgPath: string, pkgPubConf: TSdPackageConfig["publish"]): Promise<void> {
415
230
  if (pkgPubConf === "npm") {
416
231
  await SdProcess.spawnAsync("yarn npm publish --access public", { cwd: pkgPath });
417
232
  } else if (pkgPubConf?.type === "local-directory") {
418
- const pkgNpmConf = (await FsUtil.readJsonAsync(path.resolve(pkgPath, "package.json"))) as INpmConfig;
233
+ const pkgNpmConf = FsUtil.readJson(path.resolve(pkgPath, "package.json")) as INpmConfig;
419
234
 
420
235
  const targetRootPath = pkgPubConf.path.replace(/%([^%]*)%/g, (item) => {
421
236
  const envName = item.replace(/%/g, "");
@@ -428,16 +243,16 @@ export class SdCliProject {
428
243
  return process.env[envName] ?? item;
429
244
  });
430
245
 
431
- const filePaths = await FsUtil.globAsync(path.resolve(pkgPath, "dist", "**", "*"), {
246
+ const filePaths = FsUtil.glob(path.resolve(pkgPath, "dist", "**", "*"), {
432
247
  dot: true,
433
248
  nodir: true,
434
249
  });
435
250
 
436
- await filePaths.parallelAsync(async (filePath) => {
251
+ for (const filePath of filePaths) {
437
252
  const relativeFilePath = path.relative(path.resolve(pkgPath, "dist"), filePath);
438
253
  const targetPath = PathUtil.posix(targetRootPath, relativeFilePath);
439
- await FsUtil.copyAsync(filePath, targetPath);
440
- });
254
+ FsUtil.copy(filePath, targetPath);
255
+ }
441
256
  } else if (pkgPubConf?.type === "ftp" || pkgPubConf?.type === "ftps" || pkgPubConf?.type === "sftp") {
442
257
  const ftp = await SdStorage.connectAsync(pkgPubConf.type, {
443
258
  host: pkgPubConf.host,
@@ -470,8 +285,8 @@ export class SdCliProject {
470
285
  const newVersion = semver.inc(projNpmConf.version, "patch")!;
471
286
  projNpmConf.version = newVersion;
472
287
 
473
- const pkgNames = await allPkgPaths.mapAsync(async (pkgPath) => {
474
- const pkgNpmConf = await FsUtil.readJsonAsync(path.resolve(pkgPath, "package.json"));
288
+ const pkgNames = allPkgPaths.map((pkgPath) => {
289
+ const pkgNpmConf = FsUtil.readJson(path.resolve(pkgPath, "package.json"));
475
290
  return pkgNpmConf.name;
476
291
  });
477
292
 
@@ -489,12 +304,12 @@ export class SdCliProject {
489
304
  updateDepVersion(projNpmConf.peerDependencies);
490
305
 
491
306
  const projNpmConfFilePath = path.resolve(process.cwd(), "package.json");
492
- await FsUtil.writeJsonAsync(projNpmConfFilePath, projNpmConf, { space: 2 });
307
+ FsUtil.writeJson(projNpmConfFilePath, projNpmConf, { space: 2 });
493
308
 
494
309
  // 각 패키지 package.json 버전 설정
495
310
  await allPkgPaths.parallelAsync(async (pkgPath) => {
496
311
  const pkgNpmConfFilePath = path.resolve(pkgPath, "package.json");
497
- const pkgNpmConf = await FsUtil.readJsonAsync(pkgNpmConfFilePath);
312
+ const pkgNpmConf = FsUtil.readJson(pkgNpmConfFilePath);
498
313
  pkgNpmConf.version = newVersion;
499
314
 
500
315
  updateDepVersion(pkgNpmConf.dependencies);
@@ -502,24 +317,22 @@ export class SdCliProject {
502
317
  updateDepVersion(pkgNpmConf.devDependencies);
503
318
  updateDepVersion(pkgNpmConf.peerDependencies);
504
319
 
505
- await FsUtil.writeJsonAsync(pkgNpmConfFilePath, pkgNpmConf, { space: 2 });
320
+ FsUtil.writeJson(pkgNpmConfFilePath, pkgNpmConf, { space: 2 });
506
321
 
507
322
  if (FsUtil.exists(path.resolve(pkgPath, "plugin.xml"))) {
508
323
  const cordovaPluginConfFilePath = path.resolve(pkgPath, "plugin.xml");
509
- const cordovaPluginConfXml = await xml2js.parseStringPromise(
510
- await FsUtil.readFileAsync(cordovaPluginConfFilePath),
511
- );
324
+ const cordovaPluginConfXml = await xml2js.parseStringPromise(FsUtil.readFile(cordovaPluginConfFilePath));
512
325
  cordovaPluginConfXml.plugin.$.version = newVersion;
513
326
 
514
- await FsUtil.writeFileAsync(cordovaPluginConfFilePath, new xml2js.Builder().buildObject(cordovaPluginConfXml));
327
+ FsUtil.writeFile(cordovaPluginConfFilePath, new xml2js.Builder().buildObject(cordovaPluginConfXml));
515
328
  }
516
329
  });
517
330
  }
518
331
 
519
- private static _logging(buildResults: ISdCliPackageBuildResult[], logger: Logger): void {
332
+ static #logging(buildResults: ISdBuildMessage[], logger: Logger): void {
520
333
  const messageMap = buildResults.toSetMap(
521
334
  (item) => item.severity,
522
- (item) => SdCliBuildResultUtil.getMessage(item),
335
+ (item) => SdCliConvertMessageUtil.getBuildMessageString(item),
523
336
  );
524
337
 
525
338
  if (messageMap.has("message")) {
@@ -537,162 +350,4 @@ export class SdCliProject {
537
350
 
538
351
  logger.info("모든 빌드가 완료되었습니다.");
539
352
  }
540
-
541
- // piscina 사용시 ts파일을 못찾으므로 그냥 이렇게..
542
- private static async _prepareClusterAsync(): Promise<cp.ChildProcess> {
543
- const logger = Logger.get(["simplysm", "sd-cli", "SdCliProject", "_runBuildClusterAsync"]);
544
- return await new Promise<cp.ChildProcess>((resolve, reject) => {
545
- const cluster = cp.fork(fileURLToPath(import.meta.resolve("../build-cluster")), [], {
546
- stdio: ["pipe", "pipe", "pipe", "ipc"],
547
- env: {
548
- ...process.env,
549
- // "NG_BUILD_PARALLEL_TS": "0"
550
- },
551
- });
552
-
553
- cluster.stdout!.pipe(process.stdout);
554
- cluster.stderr!.pipe(process.stderr);
555
-
556
- cluster.on("exit", (code) => {
557
- if (code != null && code !== 0) {
558
- const err = new Error(`오류와 함께 닫힘 (${code})`);
559
- logger.error(err);
560
- reject(err);
561
- return;
562
- }
563
- });
564
-
565
- cluster.on("error", (err) => {
566
- logger.error(err);
567
- reject(err);
568
- });
569
-
570
- cluster.on("message", (message) => {
571
- if (message === "ready") {
572
- logger.debug("빌드 클러스터 프로세스가 준비되었습니다.");
573
- resolve(cluster);
574
- }
575
- });
576
- });
577
- }
578
-
579
- private static async _runCommandAsync(
580
- cluster: cp.ChildProcess,
581
- cmd: "watch",
582
- projConf: ISdCliConfig,
583
- pkgPath: string,
584
- execArgs: string[],
585
- ): Promise<void>;
586
- private static async _runCommandAsync(
587
- cluster: cp.ChildProcess,
588
- cmd: "build",
589
- projConf: ISdCliConfig,
590
- pkgPath: string,
591
- ): Promise<ISdCliPackageBuildResult[]>;
592
- private static async _runCommandAsync(
593
- cluster: cp.ChildProcess,
594
- cmd: "watch" | "build",
595
- projConf: ISdCliConfig,
596
- pkgPath: string,
597
- execArgs?: string[],
598
- ): Promise<ISdCliPackageBuildResult[] | void> {
599
- return await new Promise<ISdCliPackageBuildResult[] | void>((resolve) => {
600
- const cb = (message: ISdCliBuildClusterResMessage): void => {
601
- if (cmd === "watch" && message.type === "ready" && message.req.cmd === cmd && message.req.pkgPath === pkgPath) {
602
- cluster.off("message", cb);
603
- resolve();
604
- } else if (
605
- cmd === "build" &&
606
- message.type === "complete" &&
607
- message.req.cmd === cmd &&
608
- message.req.pkgPath === pkgPath
609
- ) {
610
- cluster.off("message", cb);
611
- resolve(message.result?.buildResults);
612
- }
613
- };
614
- cluster.on("message", cb);
615
-
616
- cluster.send({
617
- cmd,
618
- projConf,
619
- pkgPath,
620
- execArgs,
621
- });
622
- });
623
- }
624
-
625
- private static _closeCluster(cluster: cp.ChildProcess): void {
626
- cluster.kill("SIGKILL");
627
- }
628
-
629
- private static async _restartServerAsync(
630
- pkgOrOpt:
631
- | { path: string; conf: ISdCliServerPackageConfig }
632
- | {
633
- port: number;
634
- },
635
- prevServerProcess?: cp.ChildProcess,
636
- ): Promise<{
637
- worker: cp.ChildProcess;
638
- port: number;
639
- }> {
640
- const logger = Logger.get(["simplysm", "sd-cli", "SdCliProject", "_restartServerAsync"]);
641
-
642
- if (prevServerProcess) {
643
- prevServerProcess.kill("SIGKILL");
644
- }
645
-
646
- const npmConf =
647
- "path" in pkgOrOpt
648
- ? ((await FsUtil.readJsonAsync(path.resolve(pkgOrOpt.path, "package.json"))) as INpmConfig)
649
- : undefined;
650
-
651
- return await new Promise<{
652
- worker: cp.ChildProcess;
653
- port: number;
654
- }>((resolve, reject) => {
655
- const worker = cp.fork(
656
- fileURLToPath(import.meta.resolve("../server-worker")),
657
- [JsonConvert.stringify("path" in pkgOrOpt ? pkgOrOpt.path : pkgOrOpt)],
658
- {
659
- stdio: ["pipe", "pipe", "pipe", "ipc"],
660
- env: {
661
- ...process.env,
662
- NODE_ENV: "development",
663
- TZ: "Asia/Seoul",
664
- SD_VERSION: npmConf?.version ?? "serverless",
665
- ...("path" in pkgOrOpt ? pkgOrOpt.conf.env : {}),
666
- },
667
- },
668
- );
669
-
670
- worker.stdout!.pipe(process.stdout);
671
- worker.stderr!.pipe(process.stderr);
672
-
673
- worker.on("exit", (code) => {
674
- if (code != null && code !== 0) {
675
- const err = new Error(`오류와 함께 닫힘 (${code})`);
676
- logger.error(err);
677
- reject(err);
678
- return;
679
- }
680
- });
681
-
682
- worker.on("error", (err) => {
683
- logger.error(err);
684
- reject(err);
685
- });
686
-
687
- worker.on("message", (message: any) => {
688
- if ("port" in message) {
689
- logger.debug("서버가 시작되었습니다.");
690
- resolve({
691
- worker,
692
- port: message.port,
693
- });
694
- }
695
- });
696
- });
697
- }
698
353
  }
package/src/index.ts CHANGED
@@ -1,24 +1,27 @@
1
- export * from "./build-tools/SdCliCordova";
2
- export * from "./build-tools/SdCliIndexFileGenerator";
3
- export * from "./build-tools/SdCliNgRoutesFileGenerator";
4
- export * from "./build-tools/SdLinter";
5
- export * from "./build-tools/SdNgBundler";
6
- export * from "./build-tools/SdNgBundlerContext";
7
- export * from "./build-tools/SdReactBundler";
8
- export * from "./build-tools/SdReactBundlerContext";
9
- export * from "./build-tools/SdServerBundler";
10
- export * from "./build-tools/SdTsCompiler";
11
- export * from "./build-tools/SdTsLibBundler";
12
- export * from "./builders/SdCliClientBuilder";
13
- export * from "./builders/SdCliJsLibLinter";
14
- export * from "./builders/SdCliServerBuilder";
15
- export * from "./builders/SdCliTsLibBuilder";
16
- export * from "./bundle-plugins/sdNgPlugin";
17
- export * from "./bundle-plugins/sdReactPlugin";
18
- export * from "./bundle-plugins/sdServerPlugin";
19
- export * from "./commons";
1
+ export * from "./entry/SdCliCordova";
20
2
  export * from "./entry/SdCliElectron";
21
3
  export * from "./entry/SdCliLocalUpdate";
22
4
  export * from "./entry/SdCliProject";
23
- export * from "./utils/SdCliBuildResultUtil";
5
+ export * from "./pkg-builders/client/createSdNgPlugin";
6
+ export * from "./pkg-builders/client/SdClientBuildRunner";
7
+ export * from "./pkg-builders/client/SdCliNgRoutesFileGenerator";
8
+ export * from "./pkg-builders/client/SdNgBundler";
9
+ export * from "./pkg-builders/client/SdNgBundlerContext";
10
+ export * from "./pkg-builders/lib/SdCliIndexFileGenerator";
11
+ export * from "./pkg-builders/lib/SdJsLibBuildRunner";
12
+ export * from "./pkg-builders/lib/SdTsLibBuilder";
13
+ export * from "./pkg-builders/lib/SdTsLibBuildRunner";
14
+ export * from "./pkg-builders/SdMultiBuildRunner";
15
+ export * from "./pkg-builders/server/createSdServerPlugin";
16
+ export * from "./pkg-builders/server/SdServerBuildRunner";
17
+ export * from "./pkg-builders/server/SdServerBundler";
18
+ export * from "./ts-builder/SdTsCompiler";
19
+ export * from "./ts-builder/SdTsCompileWorker";
20
+ export * from "./types/build-plugin.type";
21
+ export * from "./types/build.type";
22
+ export * from "./types/common-configs.type";
23
+ export * from "./types/sd-configs.type";
24
+ export * from "./types/ts-compiler.type";
25
+ export * from "./types/workers.type";
26
+ export * from "./utils/SdCliConvertMessageUtil";
24
27
  export * from "./utils/SdCliPerformanceTime";