@simplysm/sd-cli 10.0.66 → 11.0.4

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 (89) hide show
  1. package/dist/build-cluster.js +16 -15
  2. package/dist/build-cluster.js.map +1 -1
  3. package/dist/build-tools/SdNgBundler.d.ts +20 -0
  4. package/dist/build-tools/SdNgBundler.js +312 -0
  5. package/dist/build-tools/SdNgBundler.js.map +1 -0
  6. package/dist/build-tools/SdTsBundler.d.ts +15 -0
  7. package/dist/build-tools/SdTsBundler.js +96 -0
  8. package/dist/build-tools/SdTsBundler.js.map +1 -0
  9. package/dist/build-tools/SdTsCompiler.d.ts +28 -0
  10. package/dist/build-tools/SdTsCompiler.js +212 -0
  11. package/dist/build-tools/SdTsCompiler.js.map +1 -0
  12. package/dist/builders/SdCliClientBuilder.d.ts +5 -7
  13. package/dist/builders/SdCliClientBuilder.js +75 -267
  14. package/dist/builders/SdCliClientBuilder.js.map +1 -1
  15. package/dist/builders/SdCliServerBuilder.d.ts +4 -3
  16. package/dist/builders/SdCliServerBuilder.js +82 -218
  17. package/dist/builders/SdCliServerBuilder.js.map +1 -1
  18. package/dist/builders/SdCliTsLibBuilder.d.ts +3 -4
  19. package/dist/builders/SdCliTsLibBuilder.js +37 -87
  20. package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
  21. package/dist/commons.d.ts +11 -5
  22. package/dist/entry/SdCliProject.js +22 -18
  23. package/dist/entry/SdCliProject.js.map +1 -1
  24. package/dist/index.d.ts +3 -11
  25. package/dist/index.js +3 -11
  26. package/dist/index.js.map +1 -1
  27. package/dist/sd-cli.js +0 -19
  28. package/dist/sd-cli.js.map +1 -1
  29. package/dist/server-worker.js +3 -0
  30. package/dist/server-worker.js.map +1 -1
  31. package/package.json +17 -19
  32. package/src/build-cluster.ts +16 -15
  33. package/src/build-tools/SdNgBundler.ts +381 -0
  34. package/src/build-tools/SdTsBundler.ts +106 -0
  35. package/src/build-tools/SdTsCompiler.ts +304 -0
  36. package/src/builders/SdCliClientBuilder.ts +93 -312
  37. package/src/builders/SdCliServerBuilder.ts +99 -242
  38. package/src/builders/SdCliTsLibBuilder.ts +41 -111
  39. package/src/commons.ts +11 -5
  40. package/src/entry/SdCliElectron.ts +3 -3
  41. package/src/entry/SdCliLocalUpdate.ts +3 -3
  42. package/src/entry/SdCliProject.ts +33 -26
  43. package/src/index.ts +3 -11
  44. package/src/sd-cli.ts +0 -23
  45. package/src/server-worker.ts +3 -0
  46. package/dist/build-tools/SdTsIncrementalBuilder.d.ts +0 -29
  47. package/dist/build-tools/SdTsIncrementalBuilder.js +0 -75
  48. package/dist/build-tools/SdTsIncrementalBuilder.js.map +0 -1
  49. package/dist/entry/SdCliPwaAssets.d.ts +0 -6
  50. package/dist/entry/SdCliPwaAssets.js +0 -39
  51. package/dist/entry/SdCliPwaAssets.js.map +0 -1
  52. package/dist/utils/SdCliViteElectronMainPlugin.d.ts +0 -6
  53. package/dist/utils/SdCliViteElectronMainPlugin.js +0 -96
  54. package/dist/utils/SdCliViteElectronMainPlugin.js.map +0 -1
  55. package/dist/utils/SdCliViteExternalPlugin.d.ts +0 -6
  56. package/dist/utils/SdCliViteExternalPlugin.js +0 -85
  57. package/dist/utils/SdCliViteExternalPlugin.js.map +0 -1
  58. package/dist/utils/SdCliViteLazyImportPlugin.d.ts +0 -2
  59. package/dist/utils/SdCliViteLazyImportPlugin.js +0 -23
  60. package/dist/utils/SdCliViteLazyImportPlugin.js.map +0 -1
  61. package/dist/utils/SdCliViteLoggerPlugin.d.ts +0 -6
  62. package/dist/utils/SdCliViteLoggerPlugin.js +0 -24
  63. package/dist/utils/SdCliViteLoggerPlugin.js.map +0 -1
  64. package/dist/utils/SdCliViteNodeGlobalPlugin.d.ts +0 -2
  65. package/dist/utils/SdCliViteNodeGlobalPlugin.js +0 -29
  66. package/dist/utils/SdCliViteNodeGlobalPlugin.js.map +0 -1
  67. package/dist/utils/SdCliViteReactSwcPlugin.d.ts +0 -2
  68. package/dist/utils/SdCliViteReactSwcPlugin.js +0 -139
  69. package/dist/utils/SdCliViteReactSwcPlugin.js.map +0 -1
  70. package/dist/utils/SdCliViteServeOptimizeExcludePlugin.d.ts +0 -2
  71. package/dist/utils/SdCliViteServeOptimizeExcludePlugin.js +0 -36
  72. package/dist/utils/SdCliViteServeOptimizeExcludePlugin.js.map +0 -1
  73. package/dist/utils/getElectronReactExternals.d.ts +0 -1
  74. package/dist/utils/getElectronReactExternals.js +0 -17
  75. package/dist/utils/getElectronReactExternals.js.map +0 -1
  76. package/dist/utils/sdCliTsDefineTransformer.d.ts +0 -4
  77. package/dist/utils/sdCliTsDefineTransformer.js +0 -26
  78. package/dist/utils/sdCliTsDefineTransformer.js.map +0 -1
  79. package/src/build-tools/SdTsIncrementalBuilder.ts +0 -125
  80. package/src/entry/SdCliPwaAssets.ts +0 -50
  81. package/src/utils/SdCliViteElectronMainPlugin.ts +0 -102
  82. package/src/utils/SdCliViteExternalPlugin.ts +0 -98
  83. package/src/utils/SdCliViteLazyImportPlugin.ts +0 -26
  84. package/src/utils/SdCliViteLoggerPlugin.ts +0 -29
  85. package/src/utils/SdCliViteNodeGlobalPlugin.ts +0 -31
  86. package/src/utils/SdCliViteReactSwcPlugin.ts +0 -153
  87. package/src/utils/SdCliViteServeOptimizeExcludePlugin.ts +0 -42
  88. package/src/utils/getElectronReactExternals.ts +0 -19
  89. package/src/utils/sdCliTsDefineTransformer.ts +0 -33
@@ -1,20 +1,21 @@
1
1
  import {EventEmitter} from "events";
2
- import {FsUtil, Logger} from "@simplysm/sd-core-node";
3
- import {INpmConfig, ISdCliBuilderResult, ISdCliPackageBuildResult, ISdCliServerPackageConfig} from "../commons";
4
- import esbuild from "esbuild";
2
+ import {FsUtil, Logger, SdFsWatcher} from "@simplysm/sd-core-node";
3
+ import {INpmConfig, ISdCliBuilderResult, ISdCliConfig, ISdCliServerPackageConfig} from "../commons";
5
4
  import path from "path";
6
- import {SdTsIncrementalBuilder} from "../build-tools/SdTsIncrementalBuilder";
5
+ import {SdTsCompiler} from "../build-tools/SdTsCompiler";
7
6
  import {SdLinter} from "../build-tools/SdLinter";
8
- import {ObjectUtil, StringUtil} from "@simplysm/sd-core-common";
9
- import esbuildPluginTsc from 'esbuild-plugin-tsc';
7
+ import {FunctionQueue, ObjectUtil, StringUtil} from "@simplysm/sd-core-common";
8
+ import {SdTsBundler} from "../build-tools/SdTsBundler";
10
9
 
11
10
  export class SdCliServerBuilder extends EventEmitter {
12
11
  private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliServerBuilder"]);
12
+ private readonly _pkgConf: ISdCliServerPackageConfig;
13
13
 
14
- public constructor(private readonly _pkgPath: string,
15
- private readonly _pkgConf: ISdCliServerPackageConfig,
14
+ public constructor(private readonly _projConf: ISdCliConfig,
15
+ private readonly _pkgPath: string,
16
16
  private readonly _withLint: boolean) {
17
17
  super();
18
+ this._pkgConf = this._projConf.packages[path.basename(_pkgPath)] as ISdCliServerPackageConfig;
18
19
  }
19
20
 
20
21
  public override on(event: "change", listener: () => void): this;
@@ -25,148 +26,68 @@ export class SdCliServerBuilder extends EventEmitter {
25
26
  }
26
27
 
27
28
  public async watchAsync(): Promise<void> {
28
- this._debug("빌드 준비...");
29
- const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, () => ({emitJs: false}));
29
+ const extModules = await this._getExternalModulesAsync();
30
30
 
31
31
  this._debug("dist 초기화...");
32
32
  await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
33
33
 
34
- this.emit("change");
35
-
36
34
  this._debug("GEN .config...");
37
35
  const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
38
36
  await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
39
37
 
40
- this._debug(`BUILD...`);
41
- const tsConfig = await FsUtil.readJsonAsync(path.resolve(this._pkgPath, "tsconfig.json"));
42
-
43
- const extModules = await this._getExternalModulesAsync();
44
- let isFirst = true;
45
- const ctx = await esbuild.context({
46
- entryPoints: "files" in tsConfig ? tsConfig.files.map((relPath) => path.resolve(this._pkgPath, relPath)) : [
47
- path.resolve(this._pkgPath, "src", "main.ts"),
38
+ this._debug(`BUILD 준비...`);
39
+ const builder = new SdTsBundler({
40
+ dev: false,
41
+ pkgPath: this._pkgPath,
42
+ entryPoints: [
43
+ path.resolve(this._pkgPath, "src/main.ts")
48
44
  ],
49
- keepNames: true,
50
- bundle: true,
51
- sourcemap: true,
52
- target: "node20",
53
- mainFields: ["es2021", "es2020", "module", "main"],
54
- conditions: ["es2021", "es2020", "es2015", "module"],
55
- tsconfig: path.resolve(this._pkgPath, "tsconfig.json"),
56
- write: true,
57
- format: "esm",
58
- resolveExtensions: [".js", ".mjs", ".cjs", ".jsx", ".ts", ".tsx"],
59
- loader: {
60
- ".xlsx": "binary",
61
- ".xls": "binary",
62
- ".docx": "binary",
63
- ".doc": "binary",
64
- ".pptx": "binary",
65
- ".ppt": "binary",
66
- ".woff": "binary",
67
- ".woff2": "binary",
68
- ".ttf": "binary",
69
- ".eot": "binary",
70
- ".otf": "binary",
71
- ".csv": "binary",
72
- ".zip": "binary",
73
- ".pfx": "binary",
74
- ".pkl": "binary",
75
- },
76
- platform: "node",
77
- logLevel: "silent",
78
- outdir: path.resolve(this._pkgPath, "dist"),
79
- external: extModules.map((item) => item.name),
80
- banner: {
81
- js: `
82
- import __path__ from 'path';
83
- import { fileURLToPath as __fileURLToPath__ } from 'url';
84
- import { createRequire as __createRequire__ } from 'module';
85
-
86
- const require = __createRequire__(import.meta.url);
87
- const __filename = __fileURLToPath__(import.meta.url);
88
- const __dirname = __path__.dirname(__filename);`.trim()
89
- },
90
- plugins: [
91
- esbuildPluginTsc(),
92
- {
93
- name: "sd-additional",
94
- setup: ({
95
- onEnd,
96
- onStart
97
- }) => {
98
- onStart(() => {
99
- if (!isFirst) {
100
- this.emit("change");
101
- this._debug(`BUILD...`);
102
- }
103
- isFirst = false;
104
- });
105
-
106
- onEnd(async (result) => {
107
- try {
108
- const buildResults = [
109
- ...result.warnings.map((warn) => ({
110
- filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
111
- line: warn.location?.line,
112
- char: warn.location?.column,
113
- code: undefined,
114
- severity: "warning" as const,
115
- message: warn.text
116
- })),
117
- ...result.errors.map((err) => ({
118
- filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
119
- line: err.location?.line,
120
- char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
121
- code: undefined,
122
- severity: "error" as const,
123
- message: err.text
124
- }))
125
- ];
126
-
127
- this._debug("CHECK...");
128
- const checkResult = await sdTsProgram.buildAsync();
129
-
130
- this._debug("LINT...");
131
- const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
132
-
133
- this._debug(`빌드 완료`);
134
- this.emit("complete", {
135
- affectedFilePaths: checkResult.affectedFilePaths,
136
- buildResults: [...buildResults, ...checkResult.results, ...lintResults]
137
- });
138
- }
139
- catch (err) {
140
- this._logger.error(err);
141
- }
142
- });
143
- },
144
- },
145
- {
146
- name: "jsdom-patch",
147
- setup: ({onLoad}) => {
148
- onLoad({filter: /XMLHttpRequest-impl\.js$/}, async (args) => {
149
- let contents = await FsUtil.readFileAsync(args.path);
150
- contents = contents.replace(
151
- './xhr-sync-worker.js',
152
- 'jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js'
153
- );
154
- return {contents};
155
- });
156
- },
157
- }
158
- ]
45
+ external: extModules.map((item) => item.name)
159
46
  });
160
- await ctx.watch();
47
+
48
+ const checker = new SdTsCompiler({
49
+ pkgPath: this._pkgPath,
50
+ emit: false,
51
+ emitDts: false,
52
+ globalStyle: false
53
+ });
54
+
55
+ this._debug("WATCH...");
56
+ const fnQ = new FunctionQueue();
57
+ SdFsWatcher
58
+ .watch([
59
+ path.resolve(this._pkgPath, "src/**/*.*")
60
+ ], {
61
+ ignoreInitial: false
62
+ })
63
+ .onChange({
64
+ delay: 100
65
+ }, () => {
66
+ fnQ.runLast(async () => {
67
+ this.emit("change");
68
+
69
+ this._debug(`BUILD...`);
70
+ const buildResults = await builder.bundleAsync();
71
+
72
+ this._debug("CHECK...");
73
+ const checkResult = await checker.buildAsync();
74
+
75
+ this._debug(`LINT...`);
76
+ const lintResults = await SdLinter.lintAsync(checkResult.affectedFilePaths, checker.program);
77
+
78
+ this._debug(`빌드 완료`);
79
+ this.emit("complete", {
80
+ affectedFilePaths: checkResult.affectedFilePaths,
81
+ buildResults: [...buildResults, ...checkResult.results, ...lintResults]
82
+ });
83
+ });
84
+ });
161
85
  }
162
86
 
163
87
  public async buildAsync(): Promise<ISdCliBuilderResult> {
164
88
  const npmConfig = (await FsUtil.readJsonAsync(path.resolve(this._pkgPath, "package.json"))) as INpmConfig;
165
89
  const extModules = await this._getExternalModulesAsync();
166
90
 
167
- this._debug("빌드 준비...");
168
- const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, () => ({emitJs: false}));
169
-
170
91
  this._debug("dist 초기화...");
171
92
  await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
172
93
 
@@ -174,6 +95,29 @@ const __dirname = __path__.dirname(__filename);`.trim()
174
95
  const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
175
96
  await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
176
97
 
98
+ this._debug("GEN package.json...");
99
+ {
100
+ const deps = extModules.filter((item) => item.exists).map((item) => item.name);
101
+
102
+ const distNpmConfig = ObjectUtil.clone(npmConfig);
103
+ distNpmConfig.dependencies = {};
104
+ for (const dep of deps) {
105
+ distNpmConfig.dependencies[dep] = "*";
106
+ }
107
+ delete distNpmConfig.optionalDependencies;
108
+ delete distNpmConfig.devDependencies;
109
+ delete distNpmConfig.peerDependencies;
110
+
111
+ if (this._pkgConf.pm2 && !this._pkgConf.pm2.noStartScript) {
112
+ distNpmConfig.scripts = {"start": "pm2 start pm2.json"};
113
+ }
114
+
115
+ await FsUtil.writeFileAsync(
116
+ path.resolve(this._pkgPath, "dist/package.json"),
117
+ JSON.stringify(distNpmConfig, undefined, 2)
118
+ );
119
+ }
120
+
177
121
  if (this._pkgConf.pm2) {
178
122
  this._debug("GEN pm2.json...");
179
123
 
@@ -204,8 +148,9 @@ const __dirname = __path__.dirname(__filename);`.trim()
204
148
  );
205
149
  }
206
150
 
207
- this._debug("GEN web.config...");
208
151
  if (this._pkgConf.iis) {
152
+ this._debug("GEN web.config...");
153
+
209
154
  const iisDistPath = path.resolve(this._pkgPath, "dist/web.config");
210
155
  const serverExeFilePath = this._pkgConf.iis.nodeExeFilePath ?? "C:\\Program Files\\nodejs\\node.exe";
211
156
  await FsUtil.writeFileAsync(iisDistPath, `
@@ -232,119 +177,31 @@ const __dirname = __path__.dirname(__filename);`.trim()
232
177
  `.trim());
233
178
  }
234
179
 
235
- this._debug("GEN package.json...");
236
- {
237
- const deps = extModules.filter((item) => item.exists).map((item) => item.name);
238
-
239
- const distNpmConfig = ObjectUtil.clone(npmConfig);
240
- distNpmConfig.dependencies = {};
241
- for (const dep of deps) {
242
- distNpmConfig.dependencies[dep] = "*";
243
- }
244
- delete distNpmConfig.optionalDependencies;
245
- delete distNpmConfig.devDependencies;
246
- delete distNpmConfig.peerDependencies;
247
-
248
- if (this._pkgConf.pm2 && !this._pkgConf.pm2.noStartScript) {
249
- distNpmConfig.scripts = {"start": "pm2 start pm2.json"};
250
- }
251
-
252
- await FsUtil.writeFileAsync(
253
- path.resolve(this._pkgPath, "dist/package.json"),
254
- JSON.stringify(distNpmConfig, undefined, 2)
255
- );
256
- }
257
-
258
- this._debug("BUILD...");
259
- const tsConfig = await FsUtil.readJsonAsync(path.resolve(this._pkgPath, "tsconfig.json"));
260
- const esbuildResult = await esbuild.build({
261
- entryPoints: "files" in tsConfig ? tsConfig.files.map((relPath) => path.resolve(this._pkgPath, relPath)) : [
262
- path.resolve(this._pkgPath, "src", "main.ts"),
180
+ this._debug(`BUILD 준비...`);
181
+ const builder = new SdTsBundler({
182
+ dev: true,
183
+ pkgPath: this._pkgPath,
184
+ entryPoints: [
185
+ path.resolve(this._pkgPath, "src/main.ts")
263
186
  ],
264
- keepNames: true,
265
- bundle: true,
266
- target: "node20",
267
- mainFields: ["es2021", "es2020", "module", "main"],
268
- conditions: ["es2021", "es2020", "es2015", "module"],
269
- tsconfig: path.resolve(this._pkgPath, "tsconfig.json"),
270
- write: true,
271
- format: "esm",
272
- resolveExtensions: [".js", ".mjs", ".cjs", ".jsx", ".ts", ".tsx"],
273
- loader: {
274
- ".xlsx": "binary",
275
- ".xls": "binary",
276
- ".docx": "binary",
277
- ".doc": "binary",
278
- ".pptx": "binary",
279
- ".ppt": "binary",
280
- ".woff": "binary",
281
- ".woff2": "binary",
282
- ".ttf": "binary",
283
- ".eot": "binary",
284
- ".otf": "binary",
285
- ".csv": "binary",
286
- ".zip": "binary",
287
- ".pfx": "binary",
288
- ".pkl": "binary",
289
- },
290
- platform: "node",
291
- logLevel: "silent",
292
- outdir: path.resolve(this._pkgPath, "dist"),
293
- external: extModules.map((item) => item.name),
294
- banner: {
295
- js: `
296
- import __path__ from 'path';
297
- import { fileURLToPath as __fileURLToPath__ } from 'url';
298
- import { createRequire as __createRequire__ } from 'module';
299
-
300
- const require = __createRequire__(import.meta.url);
301
- const __filename = __fileURLToPath__(import.meta.url);
302
- const __dirname = __path__.dirname(__filename);`.trim()
303
- },
304
- plugins: [
305
- esbuildPluginTsc(),
306
- {
307
- name: "jsdom-patch",
308
- setup: ({onLoad}) => {
309
- onLoad({filter: /XMLHttpRequest-impl\.js$/}, async (args) => {
310
- let contents = await FsUtil.readFileAsync(args.path);
311
- contents = contents.replace(
312
- './xhr-sync-worker.js',
313
- 'jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js'
314
- );
315
- return {contents};
316
- });
317
- },
318
- }
319
- ]
187
+ external: extModules.map((item) => item.name)
188
+ });
189
+
190
+ const checker = new SdTsCompiler({
191
+ pkgPath: this._pkgPath,
192
+ emit: false,
193
+ emitDts: false,
194
+ globalStyle: false
320
195
  });
321
196
 
322
- const buildResults: ISdCliPackageBuildResult[] = [
323
- ...esbuildResult.warnings.map((warn) => ({
324
- filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
325
- line: warn.location?.line,
326
- char: warn.location?.column,
327
- code: undefined,
328
- severity: "warning" as const,
329
- message: warn.text,
330
- type: "build" as const
331
- })),
332
- ...esbuildResult.errors.map((err) => ({
333
- filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
334
- line: err.location?.line,
335
- char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
336
- code: undefined,
337
- severity: "warning" as const,
338
- message: err.text,
339
- type: "build" as const
340
- }))
341
- ];
197
+ this._debug(`BUILD...`);
198
+ const buildResults = await builder.bundleAsync();
342
199
 
343
200
  this._debug("CHECK...");
344
- const checkResult = await sdTsProgram.buildAsync();
201
+ const checkResult = await checker.buildAsync();
345
202
 
346
- this._debug("LINT...");
347
- const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
203
+ this._debug(`LINT...`);
204
+ const lintResults = await SdLinter.lintAsync(checkResult.affectedFilePaths, checker.program);
348
205
 
349
206
  this._debug(`빌드 완료`);
350
207
  return {
@@ -1,20 +1,16 @@
1
1
  import {FsUtil, Logger, SdFsWatcher} from "@simplysm/sd-core-node";
2
2
  import path from "path";
3
- import {ISdCliBuilderResult, ISdCliLibPackageConfig, ISdCliPackageBuildResult} from "../commons";
3
+ import {ISdCliBuilderResult, ISdCliConfig} from "../commons";
4
4
  import {EventEmitter} from "events";
5
- import {FunctionQueue, Uuid} from "@simplysm/sd-core-common";
6
- import {SdTsIncrementalBuilder} from "../build-tools/SdTsIncrementalBuilder";
5
+ import {SdTsCompiler} from "../build-tools/SdTsCompiler";
7
6
  import {SdLinter} from "../build-tools/SdLinter";
8
- import {pathToFileURL} from "url";
9
- import less from "less";
10
- import ts from "typescript";
11
- import transformKeys from "ts-transformer-keys/transformer";
7
+ import {FunctionQueue} from "@simplysm/sd-core-common";
12
8
 
13
9
  export class SdCliTsLibBuilder extends EventEmitter {
14
10
  private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliTsLibBuilder"]);
15
11
 
16
- public constructor(private readonly _pkgPath: string,
17
- private readonly _pkgConf: ISdCliLibPackageConfig,
12
+ public constructor(private readonly _projConf: ISdCliConfig,
13
+ private readonly _pkgPath: string,
18
14
  private readonly _withLint: boolean) {
19
15
  super();
20
16
  }
@@ -27,114 +23,71 @@ export class SdCliTsLibBuilder extends EventEmitter {
27
23
  }
28
24
 
29
25
  public async buildAsync(): Promise<ISdCliBuilderResult> {
30
- this._debug("빌드 준비...");
31
- const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, (opt) => ({
32
- emitJs: true,
33
- transforms: opt.jsx === ts.JsxEmit.ReactJSX ? [{fn: transformKeys, args: undefined}] : undefined
34
- }));
35
-
36
26
  this._debug("dist 초기화...");
37
27
  await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
38
28
 
39
- this._debug("BUILD...");
40
- const buildResult = await sdTsProgram.buildAsync();
41
-
42
- this._debug("LINT...");
43
- const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(buildResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
44
-
45
- let styleResult: ISdCliPackageBuildResult | undefined;
46
- if (this._pkgConf.style !== undefined) {
47
- this._debug("STYLE...");
48
- styleResult = await this._genStyleAsync();
49
- }
29
+ this._debug(`BUILD 준비...`);
30
+ const builder = new SdTsCompiler({
31
+ pkgPath: this._pkgPath,
32
+ emit: true,
33
+ emitDts: true,
34
+ globalStyle: true
35
+ });
50
36
 
51
- this._debug("COPY...");
52
- await FsUtil.copyAsync(
53
- path.resolve(this._pkgPath, "src/assets"),
54
- path.resolve(this._pkgPath, "dist/assets")
55
- );
37
+ this._debug(`BUILD & CHECK...`);
38
+ const checkResult = await builder.buildAsync();
56
39
 
40
+ this._debug("LINT...");
41
+ const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(checkResult.affectedFilePaths, builder.program);
57
42
 
58
43
  this._debug(`빌드 완료`);
59
44
  return {
60
- affectedFilePaths: buildResult.affectedFilePaths,
61
- buildResults: [...buildResult.results, ...lintResults, ...styleResult ? [styleResult] : []]
45
+ affectedFilePaths: checkResult.affectedFilePaths,
46
+ buildResults: [...checkResult.results, ...lintResults]
62
47
  };
63
48
  }
64
49
 
65
50
  public async watchAsync(): Promise<void> {
66
- this._debug("빌드 준비...");
67
- const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, (opt) => ({
68
- emitJs: true,
69
- // compilerOptions: opt.jsx === ts.JsxEmit.ReactJSX ? {jsx: ts.JsxEmit.ReactJSXDev} : undefined,
70
- transforms: opt.jsx === ts.JsxEmit.ReactJSX ? [{fn: transformKeys, args: undefined},] : undefined
71
- }));
72
-
73
51
  this._debug("dist 초기화...");
74
52
  await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
75
53
 
76
- this.emit("change");
77
-
78
- this._debug("BUILD...");
79
- const buildResult = await sdTsProgram.buildAsync();
80
-
81
- this._debug("LINT...");
82
- const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(buildResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
83
-
84
- let styleResult: ISdCliPackageBuildResult | undefined;
85
- if (this._pkgConf.style !== undefined) {
86
- this._debug("STYLE...");
87
- styleResult = await this._genStyleAsync();
88
- }
89
-
90
- this._debug("COPY...");
91
- await FsUtil.copyAsync(
92
- path.resolve(this._pkgPath, "src/assets"),
93
- path.resolve(this._pkgPath, "dist/assets")
94
- );
95
-
96
- this._debug(`빌드 완료`);
97
- this.emit("complete", {
98
- affectedFilePaths: buildResult.affectedFilePaths,
99
- buildResults: [...buildResult.results, ...lintResults, ...styleResult ? [styleResult] : []]
54
+ this._debug(`BUILD 준비...`);
55
+ const builder = new SdTsCompiler({
56
+ pkgPath: this._pkgPath,
57
+ emit: true,
58
+ emitDts: true,
59
+ globalStyle: true
100
60
  });
101
61
 
102
62
  this._debug("WATCH...");
103
63
  const fnQ = new FunctionQueue();
104
- SdFsWatcher
64
+ const watcher = SdFsWatcher
105
65
  .watch([
106
- ...sdTsProgram.builderProgram!.getSourceFiles().map((item) => item.fileName),
107
- path.resolve(this._pkgPath, "src/**/*.{ts,tsx}")
108
- ])
66
+ path.resolve(this._pkgPath, "src/**/*.*")
67
+ ], {
68
+ ignoreInitial: false
69
+ })
109
70
  .onChange({
110
- delay: 100
111
- }, () => {
71
+ delay: 100,
72
+ }, (changeInfos) => {
73
+ builder.markChanges(changeInfos.map((item) => item.path));
74
+
112
75
  fnQ.runLast(async () => {
113
76
  this.emit("change");
114
77
 
115
- this._debug(`BUILD...`);
116
- const watchBuildResult = await sdTsProgram.buildAsync();
78
+ this._debug(`CHECK & BUILD...`);
79
+ const checkResult = await builder.buildAsync();
117
80
 
118
- this._debug(`LINT...`);
119
- const watchLintResults = !this._withLint ? [] : await SdLinter.lintAsync(watchBuildResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
120
-
121
- let watchStyleResult: ISdCliPackageBuildResult | undefined;
122
- if (this._pkgConf.style !== undefined && watchBuildResult.affectedFilePaths.some((item) => item.endsWith(this._pkgConf.style!))) {
123
- this._debug("STYLE...");
124
- watchStyleResult = await this._genStyleAsync();
125
- }
126
-
127
- this._debug("COPY...");
128
- await FsUtil.copyAsync(
129
- path.resolve(this._pkgPath, "src/assets"),
130
- path.resolve(this._pkgPath, "dist/assets")
131
- );
81
+ this._debug("LINT...");
82
+ const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(checkResult.affectedFilePaths, builder.program);
132
83
 
133
84
  this._debug(`빌드 완료`);
134
85
  this.emit("complete", {
135
- affectedFilePaths: watchBuildResult.affectedFilePaths,
136
- buildResults: [...watchBuildResult.results, ...watchLintResults, ...watchStyleResult ? [watchStyleResult] : []]
86
+ affectedFilePaths: checkResult.affectedFilePaths,
87
+ buildResults: [...checkResult.results, ...lintResults]
137
88
  });
89
+
90
+ watcher.add(builder.program.getSourceFiles().map((item) => item.fileName));
138
91
  });
139
92
  });
140
93
  }
@@ -142,27 +95,4 @@ export class SdCliTsLibBuilder extends EventEmitter {
142
95
  private _debug(msg: string): void {
143
96
  this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
144
97
  }
145
-
146
- private async _genStyleAsync(): Promise<ISdCliPackageBuildResult | undefined> {
147
- const srcFilePath = path.resolve(this._pkgPath, "dist", this._pkgConf.style! + ".js");
148
- try {
149
- const styleImport = await import(pathToFileURL(srcFilePath).href + "?token=" + Uuid.new().toString());
150
- const styleText = (styleImport.default as (string | Function)[]).map((item) => typeof item === "function" ? item({}) : item).join("");
151
- const styleRendered = await less.render(styleText);
152
- await FsUtil.writeFileAsync(path.resolve(this._pkgPath, "style.css"), styleRendered.css);
153
- }
154
- catch (err) {
155
- return {
156
- code: undefined,
157
- message: err.message,
158
- severity: "error",
159
- char: undefined,
160
- line: undefined,
161
- filePath: srcFilePath,
162
- type: "style"
163
- };
164
- }
165
-
166
- return;
167
- }
168
98
  }
package/src/commons.ts CHANGED
@@ -17,10 +17,16 @@ export interface INpmConfig {
17
17
  scripts?: Record<string, string>;
18
18
  }
19
19
 
20
+ export interface ITsConfig {
21
+ files?: string[],
22
+ compilerOptions: { lib: string[] };
23
+ angularCompilerOptions?: {};
24
+ }
25
+
20
26
  export interface ISdCliBuildClusterReqMessage {
21
27
  cmd: "watch" | "build";
28
+ projConf: ISdCliConfig;
22
29
  pkgPath: string;
23
- pkgConf: TSdCliPackageConfig;
24
30
  builderKey?: "web" | "electron";
25
31
  withLint: boolean;
26
32
  }
@@ -47,17 +53,17 @@ export interface ISdCliPackageBuildResult {
47
53
  type: "build" | "lint" | "style" | undefined;
48
54
  }
49
55
 
50
- export type TSdCliConfig = {
56
+ export interface ISdCliConfig {
51
57
  packages: Record<string, TSdCliPackageConfig | undefined>;
52
58
  localUpdates?: Record<string, string>;
53
- };
54
- export type TSdCliConfigFn = (isDev: boolean, opts?: string[]) => TSdCliConfig;
59
+ }
60
+
61
+ export type TSdCliConfigFn = (isDev: boolean, opts?: string[]) => ISdCliConfig;
55
62
 
56
63
  export type TSdCliPackageConfig = ISdCliLibPackageConfig | ISdCliServerPackageConfig | ISdCliClientPackageConfig;
57
64
 
58
65
  export interface ISdCliLibPackageConfig {
59
66
  type: "library";
60
- style?: string;
61
67
  publish?: "npm";
62
68
  polyfills?: string[];
63
69
  }
@@ -1,7 +1,7 @@
1
1
  import {FsUtil, Logger, SdProcess} from "@simplysm/sd-core-node";
2
2
  import {pathToFileURL} from "url";
3
3
  import path from "path";
4
- import {INpmConfig, TSdCliConfig} from "../commons";
4
+ import {INpmConfig, ISdCliConfig} from "../commons";
5
5
  import electronBuilder from "electron-builder";
6
6
 
7
7
  export class SdCliElectron {
@@ -16,7 +16,7 @@ export class SdCliElectron {
16
16
  const electronPath = path.resolve(pkgPath, ".cache/dev/electron/src");
17
17
 
18
18
  logger.log("설정 가져오기...");
19
- const projConf = (await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)).default(true, opt.optNames) as TSdCliConfig;
19
+ const projConf = (await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)).default(true, opt.optNames) as ISdCliConfig;
20
20
  const pkgConf = projConf.packages[opt.pkgName];
21
21
  if (pkgConf?.type !== "client" || pkgConf.builder?.electron === undefined) {
22
22
  throw new Error();
@@ -66,7 +66,7 @@ export class SdCliElectron {
66
66
  const electronDistPath = path.resolve(pkgPath, ".cache/dev/electron/dist");
67
67
 
68
68
  logger.log("설정 가져오기...");
69
- const projConf = (await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)).default(true, opt.optNames) as TSdCliConfig;
69
+ const projConf = (await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)).default(true, opt.optNames) as ISdCliConfig;
70
70
  const pkgConf = projConf.packages[opt.pkgName];
71
71
  if (pkgConf?.type !== "client" || pkgConf.builder?.electron === undefined) {
72
72
  throw new Error();