@simplysm/sd-cli 10.0.36 → 10.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/SdLinter.js.map +1 -1
  2. package/dist/SdTsIncrementalBuilder.d.ts +17 -4
  3. package/dist/SdTsIncrementalBuilder.js +29 -33
  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 -97
  9. package/dist/builders/SdCliClientBuilder.js.map +1 -1
  10. package/dist/builders/SdCliJsLibLinter.js.map +1 -1
  11. package/dist/builders/SdCliServerBuilder.d.ts +2 -1
  12. package/dist/builders/SdCliServerBuilder.js +68 -13
  13. package/dist/builders/SdCliServerBuilder.js.map +1 -1
  14. package/dist/builders/SdCliTsLibBuilder.d.ts +5 -2
  15. package/dist/builders/SdCliTsLibBuilder.js +64 -10
  16. package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
  17. package/dist/commons.d.ts +28 -2
  18. package/dist/commons.js.map +1 -1
  19. package/dist/entry/SdCliElectron.d.ts +7 -0
  20. package/dist/entry/SdCliElectron.js +42 -0
  21. package/dist/entry/SdCliElectron.js.map +1 -0
  22. package/dist/entry/SdCliLocalUpdate.d.ts +3 -3
  23. package/dist/entry/SdCliLocalUpdate.js +20 -26
  24. package/dist/entry/SdCliLocalUpdate.js.map +1 -1
  25. package/dist/entry/SdCliProject.d.ts +3 -3
  26. package/dist/entry/SdCliProject.js +87 -36
  27. package/dist/entry/SdCliProject.js.map +1 -1
  28. package/dist/index.d.ts +1 -0
  29. package/dist/index.js +2 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/sd-cli.d.ts +1 -1
  32. package/dist/sd-cli.js +62 -16
  33. package/dist/sd-cli.js.map +1 -1
  34. package/dist/server-worker.js.map +1 -1
  35. package/dist/utils/SdCliBuildResultUtil.js +1 -1
  36. package/dist/utils/SdCliBuildResultUtil.js.map +1 -1
  37. package/dist/utils/SdCliViteElectronMainPlugin.d.ts +6 -0
  38. package/dist/utils/SdCliViteElectronMainPlugin.js +81 -0
  39. package/dist/utils/SdCliViteElectronMainPlugin.js.map +1 -0
  40. package/dist/utils/SdCliViteExternalPlugin.d.ts +7 -0
  41. package/dist/utils/SdCliViteExternalPlugin.js +98 -0
  42. package/dist/utils/SdCliViteExternalPlugin.js.map +1 -0
  43. package/dist/utils/SdCliViteLoggerPlugin.d.ts +6 -0
  44. package/dist/utils/SdCliViteLoggerPlugin.js +24 -0
  45. package/dist/utils/SdCliViteLoggerPlugin.js.map +1 -0
  46. package/dist/utils/SdCliViteNodeGlobalPlugin.d.ts +2 -0
  47. package/dist/utils/SdCliViteNodeGlobalPlugin.js +29 -0
  48. package/dist/utils/SdCliViteNodeGlobalPlugin.js.map +1 -0
  49. package/dist/utils/SdCliViteReactSwcPlugin.d.ts +2 -0
  50. package/dist/utils/SdCliViteReactSwcPlugin.js +141 -0
  51. package/dist/utils/SdCliViteReactSwcPlugin.js.map +1 -0
  52. package/dist/utils/SdCliViteWatchWithResolutionsPlugin.d.ts +2 -0
  53. package/dist/utils/SdCliViteWatchWithResolutionsPlugin.js +26 -0
  54. package/dist/utils/SdCliViteWatchWithResolutionsPlugin.js.map +1 -0
  55. package/dist/utils/getElectronReactExternals.d.ts +1 -0
  56. package/dist/utils/getElectronReactExternals.js +17 -0
  57. package/dist/utils/getElectronReactExternals.js.map +1 -0
  58. package/dist/utils/sdCliTsDefineTransformer.d.ts +4 -0
  59. package/dist/utils/sdCliTsDefineTransformer.js +26 -0
  60. package/dist/utils/sdCliTsDefineTransformer.js.map +1 -0
  61. package/package.json +25 -10
  62. package/src/SdLinter.ts +2 -2
  63. package/src/SdTsIncrementalBuilder.ts +116 -94
  64. package/src/build-cluster.ts +173 -111
  65. package/src/builders/SdCliClientBuilder.ts +226 -204
  66. package/src/builders/SdCliServerBuilder.ts +311 -240
  67. package/src/builders/SdCliTsLibBuilder.ts +160 -89
  68. package/src/commons.ts +66 -34
  69. package/src/entry/SdCliElectron.ts +55 -0
  70. package/src/entry/SdCliLocalUpdate.ts +104 -101
  71. package/src/entry/SdCliProject.ts +452 -401
  72. package/src/index.ts +1 -0
  73. package/src/sd-cli.ts +185 -141
  74. package/src/utils/SdCliBuildResultUtil.ts +1 -2
  75. package/src/utils/SdCliViteElectronMainPlugin.ts +86 -0
  76. package/src/utils/SdCliViteExternalPlugin.ts +112 -0
  77. package/src/utils/SdCliViteLoggerPlugin.ts +29 -0
  78. package/src/utils/SdCliViteNodeGlobalPlugin.ts +31 -0
  79. package/src/utils/SdCliViteReactSwcPlugin.ts +154 -0
  80. package/src/utils/SdCliViteWatchWithResolutionsPlugin.ts +29 -0
  81. package/src/utils/getElectronReactExternals.ts +19 -0
  82. package/src/utils/sdCliTsDefineTransformer.ts +31 -0
  83. package/.eslintrc.cjs +0 -18
  84. package/dist/utils/SdCliConfigUtil.d.ts +0 -7
  85. package/dist/utils/SdCliConfigUtil.js +0 -69
  86. package/dist/utils/SdCliConfigUtil.js.map +0 -1
  87. package/src/utils/SdCliConfigUtil.ts +0 -94
@@ -1,103 +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): Promise<SdTsIncrementalBuilder> {
18
- const tsConfigFilePath = path.resolve(pkgPath, "tsconfig.json");
19
- const parsedTsConfig = ts.parseJsonConfigFileContent(await FsUtil.readJsonAsync(tsConfigFilePath), ts.sys, pkgPath);
20
- const host = ts.createIncrementalCompilerHost(parsedTsConfig.options);
21
- return new SdTsIncrementalBuilder(pkgPath, parsedTsConfig.options, host, emitJs);
22
- }
23
-
24
- public async buildAsync(): Promise<{
25
- affectedFilePaths: string[];
26
- results: ISdCliPackageBuildResult[];
27
- }> {
28
- const logger = Logger.get(["simplysm", "sd-cli", "SdTsIncrementalBuilder", "buildAsync"]);
29
-
30
- const srcGlobPath = path.resolve(this._pkgPath, "src/**/*.{ts,tsx}");
31
- const srcFilePaths = await FsUtil.globAsync(srcGlobPath);
32
- this.builderProgram = ts.createSemanticDiagnosticsBuilderProgram(
33
- srcFilePaths,
34
- this._options,
35
- this._host,
36
- this.builderProgram
37
- );
38
-
39
- const diagnostics: ts.Diagnostic[] = [];
40
- const affectedFilePaths: string[] = [];
41
-
42
- diagnostics.push(
43
- ...this.builderProgram.getOptionsDiagnostics(),
44
- ...this.builderProgram.getGlobalDiagnostics(),
45
- );
46
-
47
- logger.debug(`[${path.basename(this._pkgPath)}] 영향받는 파일 확인 및 처리중...`);
48
- const srcFilePathSet = new Set<string>(srcFilePaths);
49
- while (true) {
50
- const semanticResult = this.builderProgram.getSemanticDiagnosticsOfNextAffectedFile(undefined, (sourceFile) => {
51
- return !srcFilePathSet.has(path.resolve(sourceFile.fileName));
52
- });
53
- if (!semanticResult) break;
54
- diagnostics.push(...semanticResult.result);
55
-
56
- if ("fileName" in semanticResult.affected) {
57
- const emitResult = this.builderProgram.emit(semanticResult.affected, (filePath, data, writeByteOrderMark) => {
58
- let realFilePath = filePath; //.replace(/\.js$/, ".mjs");
59
- if (PathUtil.isChildPath(realFilePath, path.resolve(this._pkgPath, "dist", path.basename(this._pkgPath), "src"))) {
60
- realFilePath = path.resolve(this._pkgPath, "dist", path.relative(path.resolve(this._pkgPath, "dist", path.basename(this._pkgPath), "src"), realFilePath));
61
- }
62
-
63
- if (this._writeFileCache.get(realFilePath) !== data) {
64
- this._host.writeFile(realFilePath, data, writeByteOrderMark);
65
- }
66
- this._writeFileCache.set(realFilePath, data);
67
- }, undefined, !this._emitJs);
68
- diagnostics.push(...emitResult.diagnostics);
69
-
70
- diagnostics.push(...this.builderProgram.getSyntacticDiagnostics(semanticResult.affected));
71
- affectedFilePaths.push(path.resolve(semanticResult.affected.fileName));
72
- }
73
-
74
- /*const result = this.builderProgram.emitNextAffectedFile((filePath, data, writeByteOrderMark) => {
75
- let realFilePath = filePath.replace(/\.js$/, ".mjs");
76
- if (PathUtil.isChildPath(realFilePath, path.resolve(this._pkgPath, "dist", path.basename(this._pkgPath), "src"))) {
77
- realFilePath = path.resolve(this._pkgPath, "dist", path.relative(path.resolve(this._pkgPath, "dist", path.basename(this._pkgPath), "src"), realFilePath));
78
- }
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
+ }
79
26
 
80
- if (this._writeFileCache.get(realFilePath) !== data) {
81
- ts.sys.writeFile(realFilePath, data, writeByteOrderMark);
82
- }
83
- this._writeFileCache.set(realFilePath, data);
84
- }, undefined, !this._emitJs);
85
- if (!result) break;
86
- diagnostics.push(...result.result.diagnostics);
87
-
88
- if ("fileName" in result.affected && srcFilePathSet.has(path.resolve(result.affected.fileName))) {
89
- diagnostics.push(...this.builderProgram.getSemanticDiagnostics(result.affected));
90
- diagnostics.push(...this.builderProgram.getSyntacticDiagnostics(result.affected));
91
- affectedFilePaths.push(path.resolve(result.affected.fileName));
92
- }*/
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
+ );
93
46
  }
94
- logger.debug(`[${path.basename(this._pkgPath)}] 영향받는 파일 확인 및 처리 완료`, affectedFilePaths);
95
47
 
96
- 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);
117
+
118
+ const buildResults = diagnostics.map((item) => SdCliBuildResultUtil.convertFromTsDiag(item));
97
119
 
98
- return {
99
- affectedFilePaths,
100
- results: buildResults
101
- };
102
- }
120
+ return {
121
+ affectedFilePaths,
122
+ results: buildResults
123
+ };
124
+ }
103
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
  }