@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.
- package/dist/{build-tools → entry}/SdCliCordova.d.ts +5 -6
- package/dist/{build-tools → entry}/SdCliCordova.js +117 -99
- package/dist/entry/SdCliCordova.js.map +1 -0
- package/dist/entry/SdCliElectron.d.ts +2 -2
- package/dist/entry/SdCliElectron.js +50 -40
- package/dist/entry/SdCliElectron.js.map +1 -1
- package/dist/entry/SdCliLocalUpdate.d.ts +1 -2
- package/dist/entry/SdCliLocalUpdate.js +26 -27
- package/dist/entry/SdCliLocalUpdate.js.map +1 -1
- package/dist/entry/SdCliProject.d.ts +1 -5
- package/dist/entry/SdCliProject.js +62 -288
- package/dist/entry/SdCliProject.js.map +1 -1
- package/dist/index.d.ts +23 -20
- package/dist/index.js +23 -20
- package/dist/index.js.map +1 -1
- package/dist/pkg-builders/SdMultiBuildRunner.d.ts +21 -0
- package/dist/pkg-builders/SdMultiBuildRunner.js +174 -0
- package/dist/pkg-builders/SdMultiBuildRunner.js.map +1 -0
- package/dist/pkg-builders/client/SdCliNgRoutesFileGenerator.d.ts +4 -0
- package/dist/{build-tools → pkg-builders/client}/SdCliNgRoutesFileGenerator.js +7 -7
- package/dist/pkg-builders/client/SdCliNgRoutesFileGenerator.js.map +1 -0
- package/dist/pkg-builders/client/SdClientBuildRunner.d.ts +20 -0
- package/dist/pkg-builders/client/SdClientBuildRunner.js +135 -0
- package/dist/pkg-builders/client/SdClientBuildRunner.js.map +1 -0
- package/dist/pkg-builders/client/SdNgBundler.d.ts +29 -0
- package/dist/{build-tools → pkg-builders/client}/SdNgBundler.js +100 -95
- package/dist/pkg-builders/client/SdNgBundler.js.map +1 -0
- package/dist/{build-tools → pkg-builders/client}/SdNgBundlerContext.d.ts +1 -2
- package/dist/{build-tools → pkg-builders/client}/SdNgBundlerContext.js +19 -45
- package/dist/pkg-builders/client/SdNgBundlerContext.js.map +1 -0
- package/dist/pkg-builders/client/createSdNgPlugin.d.ts +10 -0
- package/dist/{bundle-plugins/sdNgPlugin.js → pkg-builders/client/createSdNgPlugin.js} +32 -33
- package/dist/pkg-builders/client/createSdNgPlugin.js.map +1 -0
- package/dist/pkg-builders/lib/SdCliIndexFileGenerator.d.ts +5 -0
- package/dist/{build-tools → pkg-builders/lib}/SdCliIndexFileGenerator.js +11 -11
- package/dist/pkg-builders/lib/SdCliIndexFileGenerator.js.map +1 -0
- package/dist/pkg-builders/lib/SdJsLibBuildRunner.d.ts +16 -0
- package/dist/pkg-builders/lib/SdJsLibBuildRunner.js +81 -0
- package/dist/pkg-builders/lib/SdJsLibBuildRunner.js.map +1 -0
- package/dist/pkg-builders/lib/SdTsLibBuildRunner.d.ts +13 -0
- package/dist/pkg-builders/lib/SdTsLibBuildRunner.js +89 -0
- package/dist/pkg-builders/lib/SdTsLibBuildRunner.js.map +1 -0
- package/dist/pkg-builders/lib/SdTsLibBuilder.d.ts +14 -0
- package/dist/pkg-builders/lib/SdTsLibBuilder.js +54 -0
- package/dist/pkg-builders/lib/SdTsLibBuilder.js.map +1 -0
- package/dist/pkg-builders/server/SdServerBuildRunner.d.ts +17 -0
- package/dist/{builders/SdCliServerBuilder.js → pkg-builders/server/SdServerBuildRunner.js} +48 -53
- package/dist/pkg-builders/server/SdServerBuildRunner.js.map +1 -0
- package/dist/pkg-builders/server/SdServerBundler.d.ts +19 -0
- package/dist/{build-tools → pkg-builders/server}/SdServerBundler.js +25 -30
- package/dist/pkg-builders/server/SdServerBundler.js.map +1 -0
- package/dist/pkg-builders/server/createSdServerPlugin.d.ts +10 -0
- package/dist/pkg-builders/server/createSdServerPlugin.js +53 -0
- package/dist/pkg-builders/server/createSdServerPlugin.js.map +1 -0
- package/dist/sd-cli.js +61 -54
- package/dist/sd-cli.js.map +1 -1
- package/dist/ts-builder/SdTsCompileWorker.d.ts +9 -0
- package/dist/ts-builder/SdTsCompileWorker.js +16 -0
- package/dist/ts-builder/SdTsCompileWorker.js.map +1 -0
- package/dist/ts-builder/SdTsCompiler.d.ts +7 -0
- package/dist/{build-tools → ts-builder}/SdTsCompiler.js +226 -212
- package/dist/ts-builder/SdTsCompiler.js.map +1 -0
- package/dist/types/build-plugin.type.d.ts +14 -0
- package/dist/types/build-plugin.type.js +2 -0
- package/dist/types/build-plugin.type.js.map +1 -0
- package/dist/types/build.type.d.ts +15 -0
- package/dist/types/build.type.js +2 -0
- package/dist/types/build.type.js.map +1 -0
- package/dist/types/common-configs.type.d.ts +22 -0
- package/dist/types/common-configs.type.js +2 -0
- package/dist/types/common-configs.type.js.map +1 -0
- package/dist/types/sd-configs.type.d.ts +99 -0
- package/dist/types/sd-configs.type.js +2 -0
- package/dist/types/sd-configs.type.js.map +1 -0
- package/dist/types/ts-compiler.type.d.ts +29 -0
- package/dist/types/ts-compiler.type.js +2 -0
- package/dist/types/ts-compiler.type.js.map +1 -0
- package/dist/types/workers.type.d.ts +49 -0
- package/dist/types/workers.type.js +2 -0
- package/dist/types/workers.type.js.map +1 -0
- package/dist/utils/SdCliConvertMessageUtil.d.ts +21 -0
- package/dist/utils/SdCliConvertMessageUtil.js +137 -0
- package/dist/utils/SdCliConvertMessageUtil.js.map +1 -0
- package/dist/workers/compile-worker.js +27 -0
- package/dist/workers/compile-worker.js.map +1 -0
- package/dist/workers/lint-worker.js +36 -0
- package/dist/workers/lint-worker.js.map +1 -0
- package/dist/workers/server-worker.d.ts +1 -0
- package/dist/workers/server-worker.js +49 -0
- package/dist/workers/server-worker.js.map +1 -0
- package/lib/dev-worker.cjs +5 -0
- package/package.json +7 -10
- package/src/entry/SdCliCordova.ts +363 -0
- package/src/entry/SdCliElectron.ts +96 -69
- package/src/entry/SdCliLocalUpdate.ts +43 -44
- package/src/entry/SdCliProject.ts +72 -417
- package/src/index.ts +23 -20
- package/src/pkg-builders/SdMultiBuildRunner.ts +250 -0
- package/src/{build-tools → pkg-builders/client}/SdCliNgRoutesFileGenerator.ts +7 -7
- package/src/pkg-builders/client/SdClientBuildRunner.ts +191 -0
- package/src/{build-tools → pkg-builders/client}/SdNgBundler.ts +125 -121
- package/src/pkg-builders/client/SdNgBundlerContext.ts +111 -0
- package/src/{bundle-plugins/sdNgPlugin.ts → pkg-builders/client/createSdNgPlugin.ts} +43 -46
- package/src/{build-tools → pkg-builders/lib}/SdCliIndexFileGenerator.ts +11 -11
- package/src/pkg-builders/lib/SdJsLibBuildRunner.ts +105 -0
- package/src/pkg-builders/lib/SdTsLibBuildRunner.ts +128 -0
- package/src/pkg-builders/lib/SdTsLibBuilder.ts +69 -0
- package/src/{builders/SdCliServerBuilder.ts → pkg-builders/server/SdServerBuildRunner.ts} +66 -78
- package/src/{build-tools → pkg-builders/server}/SdServerBundler.ts +40 -41
- package/src/pkg-builders/server/createSdServerPlugin.ts +77 -0
- package/src/sd-cli.ts +197 -211
- package/src/ts-builder/SdTsCompileWorker.ts +21 -0
- package/src/ts-builder/SdTsCompiler.ts +758 -0
- package/src/types/build-plugin.type.ts +16 -0
- package/src/types/build.type.ts +17 -0
- package/src/types/common-configs.type.ts +27 -0
- package/src/types/sd-configs.type.ts +114 -0
- package/src/types/ts-compiler.type.ts +29 -0
- package/src/types/workers.type.ts +27 -0
- package/src/utils/SdCliConvertMessageUtil.ts +177 -0
- package/src/workers/compile-worker.ts +31 -0
- package/src/workers/lint-worker.ts +44 -0
- package/src/workers/server-worker.ts +52 -0
- package/tsconfig.json +7 -1
- package/dist/build-cluster.js +0 -201
- package/dist/build-cluster.js.map +0 -1
- package/dist/build-tools/SdCliCordova.js.map +0 -1
- package/dist/build-tools/SdCliIndexFileGenerator.d.ts +0 -5
- package/dist/build-tools/SdCliIndexFileGenerator.js.map +0 -1
- package/dist/build-tools/SdCliNgRoutesFileGenerator.d.ts +0 -4
- package/dist/build-tools/SdCliNgRoutesFileGenerator.js.map +0 -1
- package/dist/build-tools/SdLinter.d.ts +0 -5
- package/dist/build-tools/SdLinter.js +0 -49
- package/dist/build-tools/SdLinter.js.map +0 -1
- package/dist/build-tools/SdNgBundler.d.ts +0 -29
- package/dist/build-tools/SdNgBundler.js.map +0 -1
- package/dist/build-tools/SdNgBundlerContext.js.map +0 -1
- package/dist/build-tools/SdReactBundler.d.ts +0 -25
- package/dist/build-tools/SdReactBundler.js +0 -295
- package/dist/build-tools/SdReactBundler.js.map +0 -1
- package/dist/build-tools/SdReactBundlerContext.d.ts +0 -14
- package/dist/build-tools/SdReactBundlerContext.js +0 -59
- package/dist/build-tools/SdReactBundlerContext.js.map +0 -1
- package/dist/build-tools/SdServerBundler.d.ts +0 -20
- package/dist/build-tools/SdServerBundler.js.map +0 -1
- package/dist/build-tools/SdTsCompiler.d.ts +0 -34
- package/dist/build-tools/SdTsCompiler.js.map +0 -1
- package/dist/build-tools/SdTsLibBundler.d.ts +0 -13
- package/dist/build-tools/SdTsLibBundler.js +0 -58
- package/dist/build-tools/SdTsLibBundler.js.map +0 -1
- package/dist/builders/SdCliClientBuilder.d.ts +0 -18
- package/dist/builders/SdCliClientBuilder.js +0 -172
- package/dist/builders/SdCliClientBuilder.js.map +0 -1
- package/dist/builders/SdCliJsLibLinter.d.ts +0 -13
- package/dist/builders/SdCliJsLibLinter.js +0 -60
- package/dist/builders/SdCliJsLibLinter.js.map +0 -1
- package/dist/builders/SdCliServerBuilder.d.ts +0 -15
- package/dist/builders/SdCliServerBuilder.js.map +0 -1
- package/dist/builders/SdCliTsLibBuilder.d.ts +0 -12
- package/dist/builders/SdCliTsLibBuilder.js +0 -90
- package/dist/builders/SdCliTsLibBuilder.js.map +0 -1
- package/dist/bundle-plugins/sdNgPlugin.d.ts +0 -16
- package/dist/bundle-plugins/sdNgPlugin.js.map +0 -1
- package/dist/bundle-plugins/sdReactPlugin.d.ts +0 -16
- package/dist/bundle-plugins/sdReactPlugin.js +0 -117
- package/dist/bundle-plugins/sdReactPlugin.js.map +0 -1
- package/dist/bundle-plugins/sdServerPlugin.d.ts +0 -16
- package/dist/bundle-plugins/sdServerPlugin.js +0 -63
- package/dist/bundle-plugins/sdServerPlugin.js.map +0 -1
- package/dist/commons.d.ts +0 -145
- package/dist/commons.js +0 -2
- package/dist/commons.js.map +0 -1
- package/dist/server-worker.js +0 -57
- package/dist/server-worker.js.map +0 -1
- package/dist/utils/SdCliBuildResultUtil.d.ts +0 -16
- package/dist/utils/SdCliBuildResultUtil.js +0 -54
- package/dist/utils/SdCliBuildResultUtil.js.map +0 -1
- package/src/build-cluster.ts +0 -212
- package/src/build-tools/SdCliCordova.ts +0 -340
- package/src/build-tools/SdLinter.ts +0 -65
- package/src/build-tools/SdNgBundlerContext.ts +0 -137
- package/src/build-tools/SdReactBundler.ts +0 -372
- package/src/build-tools/SdReactBundlerContext.ts +0 -71
- package/src/build-tools/SdTsCompiler.ts +0 -754
- package/src/build-tools/SdTsLibBundler.ts +0 -72
- package/src/builders/SdCliClientBuilder.ts +0 -233
- package/src/builders/SdCliJsLibLinter.ts +0 -72
- package/src/builders/SdCliTsLibBuilder.ts +0 -126
- package/src/bundle-plugins/sdReactPlugin.ts +0 -164
- package/src/bundle-plugins/sdServerPlugin.ts +0 -94
- package/src/commons.ts +0 -171
- package/src/server-worker.ts +0 -65
- package/src/utils/SdCliBuildResultUtil.ts +0 -63
- /package/dist/{build-cluster.d.ts → workers/compile-worker.d.ts} +0 -0
- /package/dist/{server-worker.d.ts → workers/lint-worker.d.ts} +0 -0
|
@@ -1,34 +1,28 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
|
-
import { FsUtil, Logger, PathUtil, SdFsWatcher } from "@simplysm/sd-core-node";
|
|
3
|
-
import {
|
|
4
|
-
INpmConfig,
|
|
5
|
-
ISdCliBuilderResult,
|
|
6
|
-
ISdCliConfig,
|
|
7
|
-
ISdCliPackageBuildResult,
|
|
8
|
-
ISdCliServerPackageConfig,
|
|
9
|
-
ITsConfig,
|
|
10
|
-
} from "../commons";
|
|
2
|
+
import { FsUtil, Logger, PathUtil, SdFsWatcher, TNormPath } from "@simplysm/sd-core-node";
|
|
11
3
|
import path from "path";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
#
|
|
4
|
+
import { ObjectUtil, StringUtil } from "@simplysm/sd-core-common";
|
|
5
|
+
import { SdServerBundler } from "./SdServerBundler";
|
|
6
|
+
import { ISdProjectConfig, ISdServerPackageConfig } from "../../types/sd-configs.type";
|
|
7
|
+
import { ISdBuildMessage, ISdBuildRunnerResult } from "../../types/build.type";
|
|
8
|
+
import { INpmConfig, ITsConfig } from "../../types/common-configs.type";
|
|
9
|
+
|
|
10
|
+
export class SdServerBuildRunner extends EventEmitter {
|
|
11
|
+
#logger = Logger.get(["simplysm", "sd-cli", "SdCliServerBuildRunner"]);
|
|
12
|
+
#pkgConf: ISdServerPackageConfig;
|
|
13
|
+
#serverBundler?: SdServerBundler;
|
|
20
14
|
#extModules?: { name: string; exists: boolean }[];
|
|
21
15
|
|
|
22
16
|
public constructor(
|
|
23
|
-
private readonly _projConf:
|
|
24
|
-
private readonly _pkgPath:
|
|
17
|
+
private readonly _projConf: ISdProjectConfig,
|
|
18
|
+
private readonly _pkgPath: TNormPath,
|
|
25
19
|
) {
|
|
26
20
|
super();
|
|
27
|
-
this.#pkgConf = this._projConf.packages[path.basename(_pkgPath)] as
|
|
21
|
+
this.#pkgConf = this._projConf.packages[path.basename(_pkgPath)] as ISdServerPackageConfig;
|
|
28
22
|
}
|
|
29
23
|
|
|
30
24
|
public override on(event: "change", listener: () => void): this;
|
|
31
|
-
public override on(event: "complete", listener: (result:
|
|
25
|
+
public override on(event: "complete", listener: (result: ISdBuildRunnerResult) => void): this;
|
|
32
26
|
public override on(event: string | symbol, listener: (...args: any[]) => void): this {
|
|
33
27
|
super.on(event, listener);
|
|
34
28
|
return this;
|
|
@@ -38,53 +32,47 @@ export class SdCliServerBuilder extends EventEmitter {
|
|
|
38
32
|
this.emit("change");
|
|
39
33
|
|
|
40
34
|
this._debug("dist 초기화...");
|
|
41
|
-
|
|
35
|
+
FsUtil.remove(path.resolve(this._pkgPath, "dist"));
|
|
42
36
|
|
|
43
37
|
this._debug("GEN .config...");
|
|
44
38
|
const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
|
|
45
|
-
|
|
39
|
+
FsUtil.writeFile(confDistPath, JSON.stringify(this.#pkgConf.configs ?? {}, undefined, 2));
|
|
46
40
|
|
|
47
|
-
const result = await this._runAsync(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
41
|
+
const result = await this._runAsync(true);
|
|
42
|
+
const res: ISdBuildRunnerResult = {
|
|
43
|
+
affectedFilePathSet: result.affectedFileSet,
|
|
44
|
+
buildMessages: result.buildMessages,
|
|
45
|
+
emitFileSet: result.emitFileSet,
|
|
46
|
+
};
|
|
47
|
+
this.emit("complete", res);
|
|
52
48
|
|
|
53
49
|
this._debug("WATCH...");
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this.emit("change");
|
|
64
|
-
|
|
65
|
-
this.#builder!.markForChanges(currChangeFiles);
|
|
50
|
+
const watcher = SdFsWatcher.watch(Array.from(result.watchFileSet)).onChange({ delay: 300 }, async (changeInfos) => {
|
|
51
|
+
this.emit("change");
|
|
52
|
+
|
|
53
|
+
const watchResult = await this._runAsync(true, new Set(changeInfos.map((item) => PathUtil.norm(item.path))));
|
|
54
|
+
const watchRes: ISdBuildRunnerResult = {
|
|
55
|
+
affectedFilePathSet: watchResult.affectedFileSet,
|
|
56
|
+
buildMessages: watchResult.buildMessages,
|
|
57
|
+
emitFileSet: watchResult.emitFileSet,
|
|
58
|
+
};
|
|
66
59
|
|
|
67
|
-
|
|
68
|
-
this.emit("complete", {
|
|
69
|
-
affectedFilePaths: Array.from(watchResult.affectedFileSet),
|
|
70
|
-
buildResults: watchResult.buildResults,
|
|
71
|
-
});
|
|
60
|
+
this.emit("complete", watchRes);
|
|
72
61
|
|
|
73
|
-
|
|
74
|
-
});
|
|
62
|
+
watcher.replaceWatchPaths(watchResult.watchFileSet);
|
|
75
63
|
});
|
|
76
64
|
}
|
|
77
65
|
|
|
78
|
-
public async buildAsync(): Promise<
|
|
79
|
-
const npmConfig =
|
|
66
|
+
public async buildAsync(): Promise<ISdBuildRunnerResult> {
|
|
67
|
+
const npmConfig = FsUtil.readJson(path.resolve(this._pkgPath, "package.json")) as INpmConfig;
|
|
80
68
|
const extModules = await this._getExternalModulesAsync();
|
|
81
69
|
|
|
82
70
|
this._debug("dist 초기화...");
|
|
83
|
-
|
|
71
|
+
FsUtil.remove(path.resolve(this._pkgPath, "dist"));
|
|
84
72
|
|
|
85
73
|
this._debug("GEN .config.json...");
|
|
86
74
|
const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
|
|
87
|
-
|
|
75
|
+
FsUtil.writeJson(confDistPath, this.#pkgConf.configs ?? {}, { space: 2 });
|
|
88
76
|
|
|
89
77
|
this._debug("GEN package.json...");
|
|
90
78
|
{
|
|
@@ -103,12 +91,12 @@ export class SdCliServerBuilder extends EventEmitter {
|
|
|
103
91
|
distNpmConfig.scripts = { start: "pm2 start pm2.json" };
|
|
104
92
|
}
|
|
105
93
|
|
|
106
|
-
|
|
94
|
+
FsUtil.writeJson(path.resolve(this._pkgPath, "dist/package.json"), distNpmConfig, { space: 2 });
|
|
107
95
|
}
|
|
108
96
|
|
|
109
97
|
this._debug("GEN openssl.cnf...");
|
|
110
98
|
{
|
|
111
|
-
|
|
99
|
+
FsUtil.writeFile(
|
|
112
100
|
path.resolve(this._pkgPath, "dist/openssl.cnf"),
|
|
113
101
|
`
|
|
114
102
|
nodejs_conf = openssl_init
|
|
@@ -138,7 +126,7 @@ Options = UnsafeLegacyRenegotiation`.trim(),
|
|
|
138
126
|
if (this.#pkgConf.pm2) {
|
|
139
127
|
this._debug("GEN pm2.json...");
|
|
140
128
|
|
|
141
|
-
|
|
129
|
+
FsUtil.writeJson(
|
|
142
130
|
path.resolve(this._pkgPath, "dist/pm2.json"),
|
|
143
131
|
{
|
|
144
132
|
name: this.#pkgConf.pm2.name ?? npmConfig.name.replace(/@/g, "").replace(/\//g, "-"),
|
|
@@ -172,7 +160,7 @@ Options = UnsafeLegacyRenegotiation`.trim(),
|
|
|
172
160
|
|
|
173
161
|
const iisDistPath = path.resolve(this._pkgPath, "dist/web.config");
|
|
174
162
|
const serverExeFilePath = this.#pkgConf.iis.nodeExeFilePath ?? "C:\\Program Files\\nodejs\\node.exe";
|
|
175
|
-
|
|
163
|
+
FsUtil.writeFile(
|
|
176
164
|
iisDistPath,
|
|
177
165
|
`
|
|
178
166
|
<configuration>
|
|
@@ -207,17 +195,22 @@ Options = UnsafeLegacyRenegotiation`.trim(),
|
|
|
207
195
|
);
|
|
208
196
|
}
|
|
209
197
|
|
|
210
|
-
const result = await this._runAsync(
|
|
198
|
+
const result = await this._runAsync(false);
|
|
211
199
|
return {
|
|
212
|
-
|
|
213
|
-
|
|
200
|
+
affectedFilePathSet: result.affectedFileSet,
|
|
201
|
+
buildMessages: result.buildMessages,
|
|
202
|
+
emitFileSet: result.emitFileSet,
|
|
214
203
|
};
|
|
215
204
|
}
|
|
216
205
|
|
|
217
|
-
private async _runAsync(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
206
|
+
private async _runAsync(
|
|
207
|
+
dev: boolean,
|
|
208
|
+
modifiedFileSet?: Set<TNormPath>,
|
|
209
|
+
): Promise<{
|
|
210
|
+
watchFileSet: Set<TNormPath>;
|
|
211
|
+
affectedFileSet: Set<TNormPath>;
|
|
212
|
+
buildMessages: ISdBuildMessage[];
|
|
213
|
+
emitFileSet: Set<TNormPath>;
|
|
221
214
|
}> {
|
|
222
215
|
const localUpdatePaths = Object.keys(this._projConf.localUpdates ?? {}).mapMany((key) =>
|
|
223
216
|
FsUtil.glob(path.resolve(this._pkgPath, "../../node_modules", key)),
|
|
@@ -226,38 +219,36 @@ Options = UnsafeLegacyRenegotiation`.trim(),
|
|
|
226
219
|
this._debug(`BUILD 준비...`);
|
|
227
220
|
const tsConfig = FsUtil.readJson(path.resolve(this._pkgPath, "tsconfig.json")) as ITsConfig;
|
|
228
221
|
this.#extModules = this.#extModules ?? (await this._getExternalModulesAsync());
|
|
229
|
-
this.#
|
|
230
|
-
this.#
|
|
222
|
+
this.#serverBundler =
|
|
223
|
+
this.#serverBundler ??
|
|
231
224
|
new SdServerBundler({
|
|
232
|
-
dev
|
|
225
|
+
dev,
|
|
233
226
|
pkgPath: this._pkgPath,
|
|
234
227
|
entryPoints: tsConfig.files
|
|
235
228
|
? tsConfig.files.map((item) => path.resolve(this._pkgPath, item))
|
|
236
229
|
: [path.resolve(this._pkgPath, "src/main.ts")],
|
|
237
230
|
external: this.#extModules.map((item) => item.name),
|
|
238
|
-
watchScopePaths: [path.resolve(this._pkgPath, "../"), ...localUpdatePaths],
|
|
231
|
+
watchScopePaths: [path.resolve(this._pkgPath, "../"), ...localUpdatePaths].map((item) => PathUtil.norm(item)),
|
|
239
232
|
});
|
|
240
233
|
|
|
241
|
-
this._debug(`BUILD
|
|
242
|
-
const
|
|
234
|
+
this._debug(`BUILD...`);
|
|
235
|
+
const bundleResult = await this.#serverBundler.bundleAsync(modifiedFileSet);
|
|
243
236
|
|
|
244
237
|
//-- filePaths
|
|
245
238
|
const watchFileSet = new Set(
|
|
246
|
-
Array.from(
|
|
239
|
+
Array.from(bundleResult.watchFileSet).filter(
|
|
247
240
|
(item) =>
|
|
248
241
|
PathUtil.isChildPath(item, path.resolve(this._pkgPath, "../")) ||
|
|
249
242
|
localUpdatePaths.some((lu) => PathUtil.isChildPath(item, lu)),
|
|
250
243
|
),
|
|
251
244
|
);
|
|
252
245
|
|
|
253
|
-
this._debug(`LINT...`);
|
|
254
|
-
const lintResults = await SdLinter.lintAsync(this._pkgPath, buildResult.affectedFileSet, buildResult.program);
|
|
255
|
-
|
|
256
246
|
this._debug(`빌드 완료`);
|
|
257
247
|
return {
|
|
258
248
|
watchFileSet,
|
|
259
|
-
affectedFileSet:
|
|
260
|
-
|
|
249
|
+
affectedFileSet: bundleResult.affectedFileSet,
|
|
250
|
+
buildMessages: bundleResult.results,
|
|
251
|
+
emitFileSet: bundleResult.emitFileSet,
|
|
261
252
|
};
|
|
262
253
|
}
|
|
263
254
|
|
|
@@ -276,10 +267,7 @@ Options = UnsafeLegacyRenegotiation`.trim(),
|
|
|
276
267
|
const npmConfigMap = new Map<string, INpmConfig>();
|
|
277
268
|
|
|
278
269
|
const fn = async (currPath: string): Promise<void> => {
|
|
279
|
-
const npmConfig = npmConfigMap.getOrCreate(
|
|
280
|
-
currPath,
|
|
281
|
-
await FsUtil.readJsonAsync(path.resolve(currPath, "package.json")),
|
|
282
|
-
);
|
|
270
|
+
const npmConfig = npmConfigMap.getOrCreate(currPath, FsUtil.readJson(path.resolve(currPath, "package.json")));
|
|
283
271
|
|
|
284
272
|
const deps = {
|
|
285
273
|
defaults: [
|
|
@@ -1,40 +1,44 @@
|
|
|
1
|
-
import { ISdCliPackageBuildResult } from "../commons";
|
|
2
1
|
import esbuild from "esbuild";
|
|
3
2
|
import path from "path";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
3
|
+
import { FsUtil, Logger, PathUtil, TNormPath } from "@simplysm/sd-core-node";
|
|
4
|
+
import { SdCliConvertMessageUtil } from "../../utils/SdCliConvertMessageUtil";
|
|
5
|
+
import { ISdCliServerPluginResultCache } from "../../types/build-plugin.type";
|
|
6
|
+
import { ISdBuildMessage } from "../../types/build.type";
|
|
7
|
+
import { createSdServerPlugin } from "./createSdServerPlugin";
|
|
8
|
+
import { BuildOutputFile, BuildOutputFileType } from "@angular/build/src/tools/esbuild/bundler-context";
|
|
9
|
+
import { convertOutputFile } from "@angular/build/src/tools/esbuild/utils";
|
|
7
10
|
|
|
8
11
|
export class SdServerBundler {
|
|
9
12
|
readonly #logger = Logger.get(["simplysm", "sd-cli", "SdServerBundler"]);
|
|
10
13
|
|
|
11
14
|
#context?: esbuild.BuildContext;
|
|
12
15
|
|
|
13
|
-
#modifiedFileSet = new Set<
|
|
14
|
-
#resultCache:
|
|
16
|
+
readonly #modifiedFileSet = new Set<TNormPath>();
|
|
17
|
+
readonly #resultCache: ISdCliServerPluginResultCache = {};
|
|
18
|
+
|
|
19
|
+
readonly #outputCache = new Map<TNormPath, string | number>();
|
|
15
20
|
|
|
16
21
|
constructor(
|
|
17
22
|
private readonly _opt: {
|
|
18
23
|
dev: boolean;
|
|
19
|
-
pkgPath:
|
|
24
|
+
pkgPath: TNormPath;
|
|
20
25
|
entryPoints: string[];
|
|
21
26
|
external?: string[];
|
|
22
|
-
watchScopePaths:
|
|
27
|
+
watchScopePaths: TNormPath[];
|
|
23
28
|
},
|
|
24
29
|
) {}
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
async bundleAsync(modifiedFileSet?: Set<TNormPath>): Promise<{
|
|
32
|
+
watchFileSet: Set<TNormPath>;
|
|
33
|
+
affectedFileSet: Set<TNormPath>;
|
|
34
|
+
results: ISdBuildMessage[];
|
|
35
|
+
emitFileSet: Set<TNormPath>;
|
|
36
|
+
}> {
|
|
37
|
+
this.#modifiedFileSet.clear();
|
|
38
|
+
if (modifiedFileSet) {
|
|
39
|
+
this.#modifiedFileSet.adds(...modifiedFileSet);
|
|
29
40
|
}
|
|
30
|
-
}
|
|
31
41
|
|
|
32
|
-
async bundleAsync(): Promise<{
|
|
33
|
-
program: ts.Program;
|
|
34
|
-
watchFileSet: Set<string>;
|
|
35
|
-
affectedFileSet: Set<string>;
|
|
36
|
-
results: ISdCliPackageBuildResult[];
|
|
37
|
-
}> {
|
|
38
42
|
if (!this.#context) {
|
|
39
43
|
this.#context = await esbuild.context({
|
|
40
44
|
entryPoints: this._opt.entryPoints,
|
|
@@ -45,7 +49,7 @@ export class SdServerBundler {
|
|
|
45
49
|
mainFields: ["es2020", "es2015", "module", "main"],
|
|
46
50
|
conditions: ["es2020", "es2015", "module"],
|
|
47
51
|
tsconfig: path.resolve(this._opt.pkgPath, "tsconfig.json"),
|
|
48
|
-
write:
|
|
52
|
+
write: false,
|
|
49
53
|
metafile: true,
|
|
50
54
|
outdir: path.resolve(this._opt.pkgPath, "dist"),
|
|
51
55
|
format: "esm",
|
|
@@ -92,7 +96,7 @@ const __filename = __fileURLToPath__(import.meta.url);
|
|
|
92
96
|
const __dirname = __path__.dirname(__filename);`.trim(),
|
|
93
97
|
},
|
|
94
98
|
plugins: [
|
|
95
|
-
|
|
99
|
+
createSdServerPlugin({
|
|
96
100
|
modifiedFileSet: this.#modifiedFileSet,
|
|
97
101
|
dev: this._opt.dev,
|
|
98
102
|
pkgPath: this._opt.pkgPath,
|
|
@@ -103,9 +107,23 @@ const __dirname = __path__.dirname(__filename);`.trim(),
|
|
|
103
107
|
});
|
|
104
108
|
}
|
|
105
109
|
|
|
110
|
+
const emitFileSet = new Set<TNormPath>();
|
|
106
111
|
let result: esbuild.BuildResult | esbuild.BuildFailure;
|
|
107
112
|
try {
|
|
108
113
|
result = await this.#context.rebuild();
|
|
114
|
+
|
|
115
|
+
const outputFiles: BuildOutputFile[] =
|
|
116
|
+
result.outputFiles?.map((file) => convertOutputFile(file, BuildOutputFileType.Root)) ?? [];
|
|
117
|
+
|
|
118
|
+
for (const outputFile of outputFiles) {
|
|
119
|
+
const distFilePath = PathUtil.norm(this._opt.pkgPath, outputFile.path);
|
|
120
|
+
const prev = this.#outputCache.get(distFilePath);
|
|
121
|
+
if (prev !== Buffer.from(outputFile.contents).toString("base64")) {
|
|
122
|
+
FsUtil.writeFile(distFilePath, outputFile.contents);
|
|
123
|
+
this.#outputCache.set(distFilePath, Buffer.from(outputFile.contents).toString("base64"));
|
|
124
|
+
emitFileSet.add(distFilePath);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
109
127
|
} catch (err) {
|
|
110
128
|
result = err;
|
|
111
129
|
for (const e of err.errors) {
|
|
@@ -116,29 +134,10 @@ const __dirname = __path__.dirname(__filename);`.trim(),
|
|
|
116
134
|
}
|
|
117
135
|
|
|
118
136
|
return {
|
|
119
|
-
program: this.#resultCache.program!,
|
|
120
137
|
watchFileSet: this.#resultCache.watchFileSet!,
|
|
121
138
|
affectedFileSet: this.#resultCache.affectedFileSet!,
|
|
122
|
-
results:
|
|
123
|
-
|
|
124
|
-
type: "build" as const,
|
|
125
|
-
filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
|
|
126
|
-
line: warn.location?.line,
|
|
127
|
-
char: warn.location?.column,
|
|
128
|
-
code: warn.text.slice(0, warn.text.indexOf(":")),
|
|
129
|
-
severity: "warning" as const,
|
|
130
|
-
message: `(${warn.pluginName}) ${warn.text.slice(warn.text.indexOf(":") + 1)}`,
|
|
131
|
-
})),
|
|
132
|
-
...result.errors.map((err) => ({
|
|
133
|
-
type: "build" as const,
|
|
134
|
-
filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
|
|
135
|
-
line: err.location?.line,
|
|
136
|
-
char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
|
|
137
|
-
code: err.text.slice(0, err.text.indexOf(":")),
|
|
138
|
-
severity: "error" as const,
|
|
139
|
-
message: `(${err.pluginName}) ${err.text.slice(err.text.indexOf(":") + 1)}`,
|
|
140
|
-
})),
|
|
141
|
-
],
|
|
139
|
+
results: SdCliConvertMessageUtil.convertToBuildMessagesFromEsbuild(result, this._opt.pkgPath),
|
|
140
|
+
emitFileSet: emitFileSet,
|
|
142
141
|
};
|
|
143
142
|
}
|
|
144
143
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import esbuild from "esbuild";
|
|
2
|
+
import { SdCliConvertMessageUtil } from "../../utils/SdCliConvertMessageUtil";
|
|
3
|
+
import { ISdCliServerPluginResultCache } from "../../types/build-plugin.type";
|
|
4
|
+
import { PathUtil, TNormPath } from "@simplysm/sd-core-node";
|
|
5
|
+
import { SdTsCompileWorker } from "../../ts-builder/SdTsCompileWorker";
|
|
6
|
+
import { ISdTsCompilerResult } from "../../types/ts-compiler.type";
|
|
7
|
+
|
|
8
|
+
export function createSdServerPlugin(conf: {
|
|
9
|
+
pkgPath: TNormPath;
|
|
10
|
+
dev: boolean;
|
|
11
|
+
modifiedFileSet: Set<TNormPath>;
|
|
12
|
+
result: ISdCliServerPluginResultCache;
|
|
13
|
+
watchScopePaths: TNormPath[];
|
|
14
|
+
}): esbuild.Plugin {
|
|
15
|
+
return {
|
|
16
|
+
name: "sd-server-compile",
|
|
17
|
+
setup: async (build: esbuild.PluginBuild) => {
|
|
18
|
+
const tsCompiler = await SdTsCompileWorker.new({
|
|
19
|
+
pkgPath: conf.pkgPath,
|
|
20
|
+
additionalOptions: { declaration: false },
|
|
21
|
+
isDevMode: conf.dev,
|
|
22
|
+
isForBundle: true,
|
|
23
|
+
watchScopePaths: conf.watchScopePaths,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
let tsCompileResult: ISdTsCompilerResult;
|
|
27
|
+
|
|
28
|
+
build.onStart(async () => {
|
|
29
|
+
tsCompileResult = await tsCompiler.compileAsync(conf.modifiedFileSet);
|
|
30
|
+
|
|
31
|
+
conf.result.watchFileSet = tsCompileResult.watchFileSet;
|
|
32
|
+
conf.result.affectedFileSet = tsCompileResult.affectedFileSet;
|
|
33
|
+
|
|
34
|
+
//-- return err/warn
|
|
35
|
+
return SdCliConvertMessageUtil.convertToEsbuildFromBuildMessages(tsCompileResult.messages, conf.pkgPath);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
build.onLoad({ filter: /\.ts$/ }, (args) => {
|
|
39
|
+
const emittedJsFile = tsCompileResult.emittedFilesCacheMap.get(PathUtil.norm(args.path))?.last();
|
|
40
|
+
if (!emittedJsFile) {
|
|
41
|
+
throw new Error(`ts 빌더 결과 emit 파일이 존재하지 않습니다. ${args.path}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const contents = emittedJsFile.text;
|
|
45
|
+
return { contents, loader: "js" };
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
build.onLoad({ filter: /\.[cm]?js$/ }, (args) => {
|
|
49
|
+
conf.result.watchFileSet!.add(PathUtil.norm(args.path));
|
|
50
|
+
return null;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
build.onLoad(
|
|
54
|
+
{
|
|
55
|
+
filter: new RegExp(
|
|
56
|
+
"(" +
|
|
57
|
+
Object.keys(build.initialOptions.loader!)
|
|
58
|
+
.map((item) => "\\" + item)
|
|
59
|
+
.join("|") +
|
|
60
|
+
")$",
|
|
61
|
+
),
|
|
62
|
+
},
|
|
63
|
+
(args) => {
|
|
64
|
+
conf.result.watchFileSet!.add(PathUtil.norm(args.path));
|
|
65
|
+
return null;
|
|
66
|
+
},
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
build.onEnd((result) => {
|
|
70
|
+
conf.result.outputFiles = result.outputFiles;
|
|
71
|
+
conf.result.metafile = result.metafile;
|
|
72
|
+
|
|
73
|
+
conf.modifiedFileSet.clear();
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|