@simplysm/sd-cli 10.0.37 → 10.0.40

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 +92 -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 +26 -12
  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 +457 -394
  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,114 +1,125 @@
1
1
  import path from "path";
2
2
  import ts from "typescript";
3
- import { SdCliBuildResultUtil } from "./utils/SdCliBuildResultUtil";
4
- import { FsUtil, Logger, PathUtil } from "@simplysm/sd-core-node";
5
- import { ISdCliPackageBuildResult } from "./commons";
3
+ import {SdCliBuildResultUtil} from "./utils/SdCliBuildResultUtil";
4
+ import {FsUtil, Logger, PathUtil} from "@simplysm/sd-core-node";
5
+ import {ISdCliPackageBuildResult} from "./commons";
6
+
7
+
8
+ interface IOptTransform<T> {
9
+ fn: (_: ts.Program, arg: T) => ts.TransformerFactory<ts.SourceFile>,
10
+ args: T
11
+ }
6
12
 
7
13
  export class SdTsIncrementalBuilder {
8
- public builderProgram?: ts.SemanticDiagnosticsBuilderProgram;
9
- private readonly _writeFileCache = new Map<string, string>();
10
-
11
- public constructor(private readonly _pkgPath: string,
12
- private readonly _options: ts.CompilerOptions,
13
- private readonly _host: ts.CompilerHost,
14
- private readonly _emitJs: boolean) {
15
- }
16
-
17
- public static async createAsync(pkgPath: string, emitJs: boolean, dev: boolean): Promise<SdTsIncrementalBuilder> {
18
- const tsConfigFilePath = path.resolve(pkgPath, "tsconfig.json");
19
- const parsedTsConfig = ts.parseJsonConfigFileContent(await FsUtil.readJsonAsync(tsConfigFilePath), ts.sys, pkgPath);
20
- const tsCompilerOptions = parsedTsConfig.options.jsx === ts.JsxEmit.ReactJSX && dev ? {
21
- ...parsedTsConfig.options,
22
- jsx: ts.JsxEmit.ReactJSXDev
23
- } : parsedTsConfig.options;
24
- const host = ts.createIncrementalCompilerHost(tsCompilerOptions);
25
- return new SdTsIncrementalBuilder(pkgPath, tsCompilerOptions, host, emitJs);
26
- }
27
-
28
- public async buildAsync(): Promise<{
29
- affectedFilePaths: string[];
30
- results: ISdCliPackageBuildResult[];
31
- }> {
32
- const logger = Logger.get(["simplysm", "sd-cli", "SdTsIncrementalBuilder", "buildAsync"]);
33
-
34
- const srcGlobPath = path.resolve(this._pkgPath, "src/**/*.{ts,tsx}");
35
- const srcFilePaths = await FsUtil.globAsync(srcGlobPath);
36
- this.builderProgram = ts.createSemanticDiagnosticsBuilderProgram(
37
- srcFilePaths,
38
- this._options,
39
- this._host,
40
- this.builderProgram
41
- );
42
-
43
- const diagnostics: ts.Diagnostic[] = [];
44
- const affectedFilePaths: string[] = [];
45
-
46
- diagnostics.push(
47
- ...this.builderProgram.getOptionsDiagnostics(),
48
- ...this.builderProgram.getGlobalDiagnostics(),
49
- );
50
-
51
- logger.debug(`[${path.basename(this._pkgPath)}] 영향받는 파일 확인 및 처리중...`);
52
- const srcFilePathSet = new Set<string>(srcFilePaths);
53
- while (true) {
54
- const semanticResult = this.builderProgram.getSemanticDiagnosticsOfNextAffectedFile(undefined, (sourceFile) => {
55
- return !srcFilePathSet.has(path.resolve(sourceFile.fileName));
56
- });
57
- if (!semanticResult) break;
58
- diagnostics.push(...semanticResult.result);
59
-
60
- if ("fileName" in semanticResult.affected) {
61
- const emitResult = this.builderProgram.emit(semanticResult.affected, (filePath, data, writeByteOrderMark) => {
62
- let realFilePath = filePath;
63
- let realData = data;
64
- if (PathUtil.isChildPath(realFilePath, path.resolve(this._pkgPath, "dist", path.basename(this._pkgPath), "src"))) {
65
- realFilePath = path.resolve(this._pkgPath, "dist", path.relative(path.resolve(this._pkgPath, "dist", path.basename(this._pkgPath), "src"), realFilePath));
66
-
67
- if (filePath.endsWith(".js.map")) {
68
- const sourceMapContents = JSON.parse(realData);
69
- sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
70
- realData = JSON.stringify(sourceMapContents);
71
- }
72
- }
73
-
74
- if (this._writeFileCache.get(realFilePath) !== realData) {
75
- this._host.writeFile(realFilePath, realData, writeByteOrderMark);
76
- }
77
- this._writeFileCache.set(realFilePath, realData);
78
- }, undefined, !this._emitJs);
79
- diagnostics.push(...emitResult.diagnostics);
80
-
81
- diagnostics.push(...this.builderProgram.getSyntacticDiagnostics(semanticResult.affected));
82
- affectedFilePaths.push(path.resolve(semanticResult.affected.fileName));
83
- }
84
-
85
- /*const result = this.builderProgram.emitNextAffectedFile((filePath, data, writeByteOrderMark) => {
86
- let realFilePath = filePath.replace(/\.js$/, ".mjs");
87
- if (PathUtil.isChildPath(realFilePath, path.resolve(this._pkgPath, "dist", path.basename(this._pkgPath), "src"))) {
88
- realFilePath = path.resolve(this._pkgPath, "dist", path.relative(path.resolve(this._pkgPath, "dist", path.basename(this._pkgPath), "src"), realFilePath));
89
- }
14
+ public builderProgram?: ts.SemanticDiagnosticsBuilderProgram;
15
+ private readonly _writeFileCache = new Map<string, string>();
16
+
17
+ public constructor(private readonly _pkgPath: string,
18
+ private readonly _compilerOptions: ts.CompilerOptions,
19
+ private readonly _host: ts.CompilerHost,
20
+ private readonly _opt: {
21
+ emitJs: boolean | string[],
22
+ compilerOptions?: ts.CompilerOptions,
23
+ transforms?: IOptTransform<any>[]
24
+ }) {
25
+ }
90
26
 
91
- if (this._writeFileCache.get(realFilePath) !== data) {
92
- ts.sys.writeFile(realFilePath, data, writeByteOrderMark);
93
- }
94
- this._writeFileCache.set(realFilePath, data);
95
- }, undefined, !this._emitJs);
96
- if (!result) break;
97
- diagnostics.push(...result.result.diagnostics);
98
-
99
- if ("fileName" in result.affected && srcFilePathSet.has(path.resolve(result.affected.fileName))) {
100
- diagnostics.push(...this.builderProgram.getSemanticDiagnostics(result.affected));
101
- diagnostics.push(...this.builderProgram.getSyntacticDiagnostics(result.affected));
102
- affectedFilePaths.push(path.resolve(result.affected.fileName));
103
- }*/
27
+ public static async createAsync(pkgPath: string, optFn: (compilerOptions: ts.CompilerOptions) => {
28
+ emitJs: boolean | string[],
29
+ compilerOptions?: ts.CompilerOptions,
30
+ transforms?: IOptTransform<any>[]
31
+ }): Promise<SdTsIncrementalBuilder> {
32
+ const tsConfigFilePath = path.resolve(pkgPath, "tsconfig.json");
33
+ const parsedTsConfig = ts.parseJsonConfigFileContent(await FsUtil.readJsonAsync(tsConfigFilePath), ts.sys, pkgPath);
34
+ const opt = optFn(parsedTsConfig.options);
35
+ const compilerOptions = {
36
+ ...parsedTsConfig.options,
37
+ ...opt?.compilerOptions
38
+ };
39
+ const host = ts.createIncrementalCompilerHost(compilerOptions);
40
+ return new SdTsIncrementalBuilder(
41
+ pkgPath,
42
+ compilerOptions,
43
+ host,
44
+ opt
45
+ );
104
46
  }
105
- logger.debug(`[${path.basename(this._pkgPath)}] 영향받는 파일 확인 및 처리 완료`, affectedFilePaths);
106
47
 
107
- const buildResults = diagnostics.map((item) => SdCliBuildResultUtil.convertFromTsDiag(item));
48
+ public async buildAsync(): Promise<{
49
+ affectedFilePaths: string[];
50
+ results: ISdCliPackageBuildResult[];
51
+ }> {
52
+ const logger = Logger.get(["simplysm", "sd-cli", "SdTsIncrementalBuilder", "buildAsync"]);
53
+
54
+ const distPath = this._compilerOptions.outDir ?? path.resolve(this._pkgPath, "dist");
55
+ const srcGlobPath = path.resolve(this._pkgPath, "src/**/*.{ts,tsx}");
56
+ const srcFilePaths = await FsUtil.globAsync(srcGlobPath);
57
+ this.builderProgram = ts.createSemanticDiagnosticsBuilderProgram(
58
+ srcFilePaths,
59
+ this._compilerOptions,
60
+ this._host,
61
+ this.builderProgram
62
+ );
63
+
64
+ const diagnostics: ts.Diagnostic[] = [];
65
+ const affectedFilePaths: string[] = [];
66
+
67
+ diagnostics.push(
68
+ ...this.builderProgram.getOptionsDiagnostics(),
69
+ ...this.builderProgram.getGlobalDiagnostics(),
70
+ );
71
+
72
+ const program = this.builderProgram.getProgram();
73
+
74
+ logger.debug(`[${path.basename(this._pkgPath)}] 영향받는 파일 확인 및 처리중...`);
75
+ const srcFilePathSet = new Set<string>(srcFilePaths);
76
+ while (true) {
77
+ const semanticResult = this.builderProgram.getSemanticDiagnosticsOfNextAffectedFile(undefined, (sourceFile) => {
78
+ return !srcFilePathSet.has(path.resolve(sourceFile.fileName));
79
+ });
80
+ if (!semanticResult) break;
81
+ diagnostics.push(...semanticResult.result);
82
+
83
+ if ("fileName" in semanticResult.affected) {
84
+ const emitResult = this.builderProgram.emit
85
+ (semanticResult.affected,
86
+ (filePath, data, writeByteOrderMark) => {
87
+ let realFilePath = filePath;
88
+ let realData = data;
89
+ if (PathUtil.isChildPath(realFilePath, path.resolve(distPath, path.basename(this._pkgPath), "src"))) {
90
+ realFilePath = path.resolve(distPath, path.relative(path.resolve(distPath, path.basename(this._pkgPath), "src"), realFilePath));
91
+
92
+ if (filePath.endsWith(".js.map")) {
93
+ const sourceMapContents = JSON.parse(realData);
94
+ sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
95
+ realData = JSON.stringify(sourceMapContents);
96
+ }
97
+ }
98
+
99
+ if (this._writeFileCache.get(realFilePath) !== realData) {
100
+ this._host.writeFile(realFilePath, realData, writeByteOrderMark);
101
+ }
102
+ this._writeFileCache.set(realFilePath, realData);
103
+ },
104
+ undefined,
105
+ Array.isArray(this._opt.emitJs) ? !this._opt.emitJs.includes(path.resolve(semanticResult.affected.fileName)) : !this._opt.emitJs,
106
+ this._opt.transforms ? {
107
+ before: this._opt.transforms.map((item) => typeof item.fn === "function" ? item.fn(program, item.args) : (item.fn["default"] as any)(program, item.args))
108
+ } : undefined
109
+ );
110
+ diagnostics.push(...emitResult.diagnostics);
111
+
112
+ diagnostics.push(...this.builderProgram.getSyntacticDiagnostics(semanticResult.affected));
113
+ affectedFilePaths.push(path.resolve(semanticResult.affected.fileName));
114
+ }
115
+ }
116
+ logger.debug(`[${path.basename(this._pkgPath)}] 영향받는 파일 확인 및 처리 완료`, affectedFilePaths);
108
117
 
109
- return {
110
- affectedFilePaths,
111
- results: buildResults
112
- };
113
- }
118
+ const buildResults = diagnostics.map((item) => SdCliBuildResultUtil.convertFromTsDiag(item));
119
+
120
+ return {
121
+ affectedFilePaths,
122
+ results: buildResults
123
+ };
124
+ }
114
125
  }
@@ -1,133 +1,195 @@
1
1
  import cluster from "node:cluster";
2
- import { SdCliTsLibBuilder } from "./builders/SdCliTsLibBuilder";
3
- import { FsUtil, Logger, LoggerSeverity } from "@simplysm/sd-core-node";
2
+ import {SdCliTsLibBuilder} from "./builders/SdCliTsLibBuilder";
3
+ import {FsUtil, Logger, LoggerSeverity} from "@simplysm/sd-core-node";
4
4
  import path from "path";
5
- import { SdCliJsLibLinter } from "./builders/SdCliJsLibLinter";
6
- import { EventEmitter } from "events";
7
- import { ISdCliBuildClusterReqMessage, ISdCliBuildClusterResMessage } from "./commons";
8
- import { NeverEntryError } from "@simplysm/sd-core-common";
9
- import { SdCliServerBuilder } from "./builders/SdCliServerBuilder";
10
- import { SdCliClientBuilder } from "./builders/SdCliClientBuilder";
5
+ import {SdCliJsLibLinter} from "./builders/SdCliJsLibLinter";
6
+ import {EventEmitter} from "events";
7
+ import {ISdCliBuildClusterReqMessage, ISdCliBuildClusterResMessage} from "./commons";
8
+ import {NeverEntryError} from "@simplysm/sd-core-common";
9
+ import {SdCliServerBuilder} from "./builders/SdCliServerBuilder";
10
+ import {SdCliClientBuilder} from "./builders/SdCliClientBuilder";
11
11
 
12
12
  Error.stackTraceLimit = Infinity;
13
13
  EventEmitter.defaultMaxListeners = 0;
14
14
 
15
15
  if (Boolean(process.env["SD_DEBUG"])) {
16
- Logger.setConfig({
17
- console: {
18
- level: LoggerSeverity.debug
19
- }
20
- });
21
- }
22
- else {
23
- Logger.setConfig({
24
- dot: true
25
- });
16
+ Logger.setConfig({
17
+ console: {
18
+ level: LoggerSeverity.debug
19
+ }
20
+ });
21
+ } else {
22
+ Logger.setConfig({
23
+ dot: true
24
+ });
26
25
  }
27
26
 
28
27
  const logger = Logger.get(["simplysm", "sd-cli", "build-cluster"]);
29
28
 
30
29
  if (cluster.isPrimary) {
31
- logger.debug(`메인 프로세스 ${process.pid} 시작`);
30
+ cluster.schedulingPolicy = cluster.SCHED_RR;
31
+ logger.debug(`메인 프로세스 ${process.pid} 시작`);
32
32
 
33
- cluster.on("exit", (worker, code) => {
34
- logger.debug(`워커 프로세스 ${worker.process.pid} 종료 (code: ${code})`);
35
- });
33
+ cluster.on("exit", (worker, code) => {
34
+ logger.debug(`워커 프로세스 ${worker.process.pid} 종료 (code: ${code})`);
35
+ });
36
36
 
37
- cluster.on("message", (worker, message) => {
38
- sendMessage(message);
39
- });
37
+ cluster.on("message", (worker, message) => {
38
+ sendMessage(message);
39
+ });
40
40
 
41
- process.on("message", (message) => {
42
- cluster.fork({
43
- "SD_CLUSTER_MESSAGE": JSON.stringify(message)
41
+ process.on("message", (message) => {
42
+ cluster.fork({
43
+ "SD_CLUSTER_MESSAGE": JSON.stringify(message)
44
+ });
44
45
  });
45
- });
46
- process.send!("ready");
47
- }
48
- else {
49
- const message = JSON.parse(process.env["SD_CLUSTER_MESSAGE"]!) as ISdCliBuildClusterReqMessage;
46
+ process.send!("ready");
47
+ } else {
48
+ const message = JSON.parse(process.env["SD_CLUSTER_MESSAGE"]!) as ISdCliBuildClusterReqMessage;
50
49
 
51
- if (message.cmd === "watch") {
52
- // [library] javascript
53
- if (message.pkgConf.type === "library" && !FsUtil.exists(path.resolve(message.pkgPath, "tsconfig.json"))) {
54
- await new SdCliJsLibLinter(message.pkgPath)
55
- .on("change", () => {
56
- sendMessage({ type: "change", req: message });
57
- })
58
- .on("complete", (result) => {
59
- sendMessage({ type: "complete", result, req: message });
60
- })
61
- .watchAsync();
62
- sendMessage({ type: "ready", req: message });
63
- }
64
- // [library] typescript
65
- else if (message.pkgConf.type === "library" && FsUtil.exists(path.resolve(message.pkgPath, "tsconfig.json"))) {
66
- await new SdCliTsLibBuilder(message.pkgPath)
67
- .on("change", () => {
68
- sendMessage({ type: "change", req: message });
69
- })
70
- .on("complete", (result) => {
71
- sendMessage({ type: "complete", result, req: message });
72
- })
73
- .watchAsync();
74
- sendMessage({ type: "ready", req: message });
75
- }
76
- // [server]
77
- else if (message.pkgConf.type === "server") {
78
- await new SdCliServerBuilder(message.pkgPath, message.pkgConf)
79
- .on("change", () => {
80
- sendMessage({ type: "change", req: message });
81
- })
82
- .on("complete", (result) => {
83
- sendMessage({ type: "complete", result, req: message });
84
- })
85
- .watchAsync();
86
- sendMessage({ type: "ready", req: message });
87
- }
88
- // [client]
89
- else if (message.pkgConf.type === "client") {
90
- await new SdCliClientBuilder(message.pkgPath)
91
- .on("change", () => {
92
- sendMessage({ type: "change", req: message });
93
- })
94
- .on("complete", (result) => {
95
- sendMessage({ type: "complete", result, req: message });
96
- })
97
- .watchAsync();
98
- sendMessage({ type: "ready", req: message });
99
- }
100
- else {
101
- throw new NeverEntryError();
102
- }
103
- }
104
- else { // build
105
- // [library] javascript
106
- if (message.pkgConf.type === "library" && !FsUtil.exists(path.resolve(message.pkgPath, "tsconfig.json"))) {
107
- const result = await new SdCliJsLibLinter(message.pkgPath).buildAsync();
108
- sendMessage({ type: "complete", result, req: message });
109
- }
110
- // [library] typescript
111
- else if (message.pkgConf.type === "library" && FsUtil.exists(path.resolve(message.pkgPath, "tsconfig.json"))) {
112
- const result = await new SdCliTsLibBuilder(message.pkgPath).buildAsync();
113
- sendMessage({ type: "complete", result, req: message });
114
- }
115
- // [server]
116
- else if (message.pkgConf.type === "server") {
117
- const result = await new SdCliServerBuilder(message.pkgPath, message.pkgConf).buildAsync();
118
- sendMessage({ type: "complete", result, req: message });
119
- }
120
- // [server]
121
- else if (message.pkgConf.type === "client") {
122
- const result = await new SdCliClientBuilder(message.pkgPath).buildAsync();
123
- sendMessage({ type: "complete", result, req: message });
124
- }
125
- else {
126
- throw new NeverEntryError();
50
+ if (message.cmd === "watch") {
51
+ // [library] javascript
52
+ if (message.pkgConf.type === "library" && !FsUtil.exists(path.resolve(message.pkgPath, "tsconfig.json"))) {
53
+ if (message.withLint) {
54
+ await new SdCliJsLibLinter(message.pkgPath)
55
+ .on("change", () => {
56
+ sendMessage({
57
+ type: "change",
58
+ req: message
59
+ });
60
+ })
61
+ .on("complete", (result) => {
62
+ sendMessage({
63
+ type: "complete",
64
+ result,
65
+ req: message
66
+ });
67
+ })
68
+ .watchAsync();
69
+ }
70
+ sendMessage({
71
+ type: "ready",
72
+ req: message
73
+ });
74
+ }
75
+ // [library] typescript
76
+ else if (message.pkgConf.type === "library" && FsUtil.exists(path.resolve(message.pkgPath, "tsconfig.json"))) {
77
+ await new SdCliTsLibBuilder(message.pkgPath, message.pkgConf, message.withLint)
78
+ .on("change", () => {
79
+ sendMessage({
80
+ type: "change",
81
+ req: message
82
+ });
83
+ })
84
+ .on("complete", (result) => {
85
+ sendMessage({
86
+ type: "complete",
87
+ result,
88
+ req: message
89
+ });
90
+ })
91
+ .watchAsync();
92
+ sendMessage({
93
+ type: "ready",
94
+ req: message
95
+ });
96
+ }
97
+ // [server]
98
+ else if (message.pkgConf.type === "server") {
99
+ await new SdCliServerBuilder(message.pkgPath, message.pkgConf, message.withLint)
100
+ .on("change", () => {
101
+ sendMessage({
102
+ type: "change",
103
+ req: message
104
+ });
105
+ })
106
+ .on("complete", (result) => {
107
+ sendMessage({
108
+ type: "complete",
109
+ result,
110
+ req: message
111
+ });
112
+ })
113
+ .watchAsync();
114
+ sendMessage({
115
+ type: "ready",
116
+ req: message
117
+ });
118
+ }
119
+ // [client]
120
+ else if (message.pkgConf.type === "client") {
121
+ await new SdCliClientBuilder(message.pkgPath, message.pkgConf, message.builderKey ?? "web", message.withLint)
122
+ .on("change", () => {
123
+ sendMessage({
124
+ type: "change",
125
+ req: message
126
+ });
127
+ })
128
+ .on("complete", (result) => {
129
+ sendMessage({
130
+ type: "complete",
131
+ result,
132
+ req: message
133
+ });
134
+ })
135
+ .watchAsync();
136
+ sendMessage({
137
+ type: "ready",
138
+ req: message
139
+ });
140
+ } else {
141
+ throw new NeverEntryError();
142
+ }
143
+ } else { // build
144
+ // [library] javascript
145
+ if (message.pkgConf.type === "library" && !FsUtil.exists(path.resolve(message.pkgPath, "tsconfig.json"))) {
146
+ if (message.withLint) {
147
+ const result = await new SdCliJsLibLinter(message.pkgPath).buildAsync();
148
+ sendMessage({
149
+ type: "complete",
150
+ result,
151
+ req: message
152
+ });
153
+ } else {
154
+ sendMessage({
155
+ type: "complete",
156
+ result: undefined,
157
+ req: message
158
+ });
159
+ }
160
+ }
161
+ // [library] typescript
162
+ else if (message.pkgConf.type === "library" && FsUtil.exists(path.resolve(message.pkgPath, "tsconfig.json"))) {
163
+ const result = await new SdCliTsLibBuilder(message.pkgPath, message.pkgConf, message.withLint).buildAsync();
164
+ sendMessage({
165
+ type: "complete",
166
+ result,
167
+ req: message
168
+ });
169
+ }
170
+ // [server]
171
+ else if (message.pkgConf.type === "server") {
172
+ const result = await new SdCliServerBuilder(message.pkgPath, message.pkgConf, message.withLint).buildAsync();
173
+ sendMessage({
174
+ type: "complete",
175
+ result,
176
+ req: message
177
+ });
178
+ }
179
+ // [client]
180
+ else if (message.pkgConf.type === "client") {
181
+ const result = await new SdCliClientBuilder(message.pkgPath, message.pkgConf, message.builderKey ?? "web", message.withLint).buildAsync();
182
+ sendMessage({
183
+ type: "complete",
184
+ result,
185
+ req: message
186
+ });
187
+ } else {
188
+ throw new NeverEntryError();
189
+ }
127
190
  }
128
- }
129
191
  }
130
192
 
131
193
  function sendMessage(message: ISdCliBuildClusterResMessage): void {
132
- process.send!(message);
194
+ process.send!(message);
133
195
  }