@simplysm/sd-cli 12.9.16 → 12.9.18
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/entry/sd-cli-cordova.d.ts +1 -1
- package/dist/entry/sd-cli-cordova.js +3 -3
- package/dist/entry/sd-cli-cordova.js.map +1 -1
- package/dist/entry/sd-cli-electron.d.ts +2 -2
- package/dist/entry/sd-cli-local-update.d.ts +2 -2
- package/dist/entry/sd-cli-local-update.js.map +1 -1
- package/dist/entry/sd-cli-project.d.ts +3 -3
- package/dist/entry/sd-cli-project.js +4 -4
- package/dist/entry/sd-cli-project.js.map +1 -1
- package/dist/entry/utils/loadProjConfAsync.d.ts +1 -1
- package/dist/entry/utils/loadProjConfAsync.js +1 -1
- package/dist/entry/utils/loadProjConfAsync.js.map +1 -1
- package/dist/fix/convert-private-underscore.d.ts +1 -0
- package/dist/fix/convert-private-underscore.js +49 -0
- package/dist/fix/convert-private-underscore.js.map +1 -0
- package/dist/fix/convert-private.d.ts +1 -0
- package/dist/fix/convert-private.js +60 -0
- package/dist/fix/convert-private.js.map +1 -0
- package/dist/pkg-builders/client/sd-cli-ng-routes.file-generator.d.ts +1 -1
- package/dist/pkg-builders/client/sd-cli-ng-routes.file-generator.js +3 -3
- package/dist/pkg-builders/client/sd-cli-ng-routes.file-generator.js.map +1 -1
- package/dist/pkg-builders/client/sd-client.build-runner.d.ts +5 -18
- package/dist/pkg-builders/client/sd-client.build-runner.js +32 -90
- package/dist/pkg-builders/client/sd-client.build-runner.js.map +1 -1
- package/dist/pkg-builders/client/sd-ng.bundler.d.ts +2 -1
- package/dist/pkg-builders/client/sd-ng.bundler.js +2 -2
- package/dist/pkg-builders/client/sd-ng.bundler.js.map +1 -1
- package/dist/pkg-builders/client/sd-ng.plugin-creator.d.ts +2 -1
- package/dist/pkg-builders/client/sd-ng.plugin-creator.js +1 -1
- package/dist/pkg-builders/client/sd-ng.plugin-creator.js.map +1 -1
- package/dist/pkg-builders/commons/build-runner.base.d.ts +27 -0
- package/dist/pkg-builders/commons/build-runner.base.js +93 -0
- package/dist/pkg-builders/commons/build-runner.base.js.map +1 -0
- package/dist/pkg-builders/commons/scope-path.d.ts +7 -0
- package/dist/pkg-builders/commons/scope-path.js +13 -0
- package/dist/pkg-builders/commons/scope-path.js.map +1 -0
- package/dist/pkg-builders/lib/sd-cli-index.file-generator.d.ts +1 -1
- package/dist/pkg-builders/lib/sd-cli-index.file-generator.js +2 -2
- package/dist/pkg-builders/lib/sd-cli-index.file-generator.js.map +1 -1
- package/dist/pkg-builders/lib/sd-js-lib.build-runner.d.ts +7 -15
- package/dist/pkg-builders/lib/sd-js-lib.build-runner.js +15 -54
- package/dist/pkg-builders/lib/sd-js-lib.build-runner.js.map +1 -1
- package/dist/pkg-builders/lib/sd-ts-lib.build-runner.d.ts +5 -16
- package/dist/pkg-builders/lib/sd-ts-lib.build-runner.js +31 -85
- package/dist/pkg-builders/lib/sd-ts-lib.build-runner.js.map +1 -1
- package/dist/pkg-builders/lib/sd-ts-lib.builder.d.ts +2 -1
- package/dist/pkg-builders/lib/sd-ts-lib.builder.js +2 -2
- package/dist/pkg-builders/lib/sd-ts-lib.builder.js.map +1 -1
- package/dist/pkg-builders/sd-multi.build-runner.d.ts +2 -1
- package/dist/pkg-builders/sd-multi.build-runner.js +4 -4
- package/dist/pkg-builders/sd-multi.build-runner.js.map +1 -1
- package/dist/pkg-builders/server/sd-server.build-runner.d.ts +6 -17
- package/dist/pkg-builders/server/sd-server.build-runner.js +87 -137
- package/dist/pkg-builders/server/sd-server.build-runner.js.map +1 -1
- package/dist/pkg-builders/server/sd-server.bundler.d.ts +2 -1
- package/dist/pkg-builders/server/sd-server.bundler.js +2 -2
- package/dist/pkg-builders/server/sd-server.bundler.js.map +1 -1
- package/dist/pkg-builders/server/sd-server.plugin-creator.d.ts +2 -1
- package/dist/pkg-builders/server/sd-server.plugin-creator.js +3 -2
- package/dist/pkg-builders/server/sd-server.plugin-creator.js.map +1 -1
- package/dist/sd-cli-entry.js +69 -61
- package/dist/sd-cli-entry.js.map +1 -1
- package/dist/sd-cli.js +33 -28
- package/dist/sd-cli.js.map +1 -1
- package/dist/ts-compiler/sd-dependency-analyzer.d.ts +3 -3
- package/dist/ts-compiler/sd-dependency-analyzer.js +9 -16
- package/dist/ts-compiler/sd-dependency-analyzer.js.map +1 -1
- package/dist/ts-compiler/sd-ts-compiler.d.ts +1 -2
- package/dist/ts-compiler/sd-ts-compiler.js +70 -19
- package/dist/ts-compiler/sd-ts-compiler.js.map +1 -1
- package/dist/types/config.types.d.ts +3 -2
- package/dist/types/ts-compiler.types.d.ts +2 -1
- package/package.json +8 -7
- package/src/entry/sd-cli-cordova.ts +4 -4
- package/src/entry/sd-cli-electron.ts +2 -2
- package/src/entry/sd-cli-local-update.ts +2 -2
- package/src/entry/sd-cli-project.ts +6 -6
- package/src/entry/utils/loadProjConfAsync.ts +2 -2
- package/src/fix/convert-private-underscore.ts +69 -0
- package/src/fix/convert-private.ts +74 -0
- package/src/pkg-builders/client/sd-cli-ng-routes.file-generator.ts +3 -3
- package/src/pkg-builders/client/sd-client.build-runner.ts +39 -126
- package/src/pkg-builders/client/sd-ng.bundler.ts +4 -3
- package/src/pkg-builders/client/sd-ng.plugin-creator.ts +3 -2
- package/src/pkg-builders/commons/build-runner.base.ts +149 -0
- package/src/pkg-builders/commons/scope-path.ts +17 -0
- package/src/pkg-builders/lib/sd-cli-index.file-generator.ts +2 -2
- package/src/pkg-builders/lib/sd-js-lib.build-runner.ts +29 -74
- package/src/pkg-builders/lib/sd-ts-lib.build-runner.ts +35 -130
- package/src/pkg-builders/lib/sd-ts-lib.builder.ts +3 -2
- package/src/pkg-builders/sd-multi.build-runner.ts +4 -4
- package/src/pkg-builders/server/sd-server.build-runner.ts +99 -187
- package/src/pkg-builders/server/sd-server.bundler.ts +4 -3
- package/src/pkg-builders/server/sd-server.plugin-creator.ts +13 -8
- package/src/sd-cli-entry.ts +115 -81
- package/src/sd-cli.ts +14 -11
- package/src/ts-compiler/sd-dependency-analyzer.ts +10 -17
- package/src/ts-compiler/sd-ts-compiler.ts +79 -30
- package/src/types/config.types.ts +9 -2
- package/src/types/ts-compiler.types.ts +2 -1
- package/tests/deps/sd-dependency-analyzer.spec.ts +1 -1
- package/dist/workers/style-bundler.worker.d.ts +0 -1
- package/dist/workers/style-bundler.worker.js +0 -56
- package/dist/workers/style-bundler.worker.js.map +0 -1
- package/src/workers/style-bundler.worker.ts +0 -70
|
@@ -1,125 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FsUtils, PathUtils, SdFsWatcher, SdLogger, TNormPath } from "@simplysm/sd-core-node";
|
|
1
|
+
import { FsUtils, PathUtils, SdLogger, TNormPath } from "@simplysm/sd-core-node";
|
|
3
2
|
import path from "path";
|
|
4
3
|
import { SdNgBundler } from "./sd-ng.bundler";
|
|
5
|
-
import { SdCliNgRoutesFileGenerator } from "./sd-cli-ng-routes.file-generator";
|
|
6
4
|
import { SdCliCordova } from "../../entry/sd-cli-cordova";
|
|
7
5
|
import { SdCliElectron } from "../../entry/sd-cli-electron";
|
|
8
|
-
import {
|
|
6
|
+
import { BuildRunnerBase, IBuildRunnerRunResult } from "../commons/build-runner.base";
|
|
7
|
+
import { SdCliNgRoutesFileGenerator } from "./sd-cli-ng-routes.file-generator";
|
|
9
8
|
import { INpmConfig } from "../../types/common-configs.types";
|
|
10
|
-
import { ISdBuildMessage, ISdBuildRunnerResult } from "../../types/build.types";
|
|
11
9
|
|
|
12
|
-
export class SdClientBuildRunner extends
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
private _npmConf: INpmConfig;
|
|
10
|
+
export class SdClientBuildRunner extends BuildRunnerBase<"client"> {
|
|
11
|
+
protected override _logger = SdLogger.get(["simplysm", "sd-cli", "SdClientBuildRunner"]);
|
|
12
|
+
|
|
16
13
|
private _ngBundlers?: SdNgBundler[];
|
|
17
14
|
private _cordova?: SdCliCordova;
|
|
18
|
-
private _watchScopePathSet: Set<TNormPath>;
|
|
19
|
-
|
|
20
|
-
constructor(
|
|
21
|
-
private _projConf: ISdProjectConfig,
|
|
22
|
-
private _pkgPath: TNormPath,
|
|
23
|
-
) {
|
|
24
|
-
super();
|
|
25
|
-
this._pkgConf = this._projConf.packages[path.basename(_pkgPath)] as ISdClientPackageConfig;
|
|
26
|
-
this._npmConf = FsUtils.readJson(path.resolve(_pkgPath, "package.json")) as INpmConfig;
|
|
27
|
-
|
|
28
|
-
const localUpdatePaths = Object.keys(this._projConf.localUpdates ?? {}).mapMany((key) =>
|
|
29
|
-
FsUtils.glob(path.resolve(this._pkgPath, "../../node_modules", key)),
|
|
30
|
-
);
|
|
31
|
-
this._watchScopePathSet = new Set(
|
|
32
|
-
[
|
|
33
|
-
path.resolve(this._pkgPath, "../"),
|
|
34
|
-
...localUpdatePaths,
|
|
35
|
-
].map((item) => PathUtils.norm(item)),
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
override on(event: "change", listener: () => void): this;
|
|
40
|
-
override on(event: "complete", listener: (result: ISdBuildRunnerResult) => void): this;
|
|
41
|
-
override on(event: string | symbol, listener: (...args: any[]) => void): this {
|
|
42
|
-
super.on(event, listener);
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async buildAsync(): Promise<ISdBuildRunnerResult> {
|
|
47
|
-
this._debug("dist 초기화...");
|
|
48
|
-
FsUtils.remove(path.resolve(this._pkgPath, "dist"));
|
|
49
15
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
.
|
|
56
|
-
this.
|
|
57
|
-
|
|
16
|
+
protected override async _runAsync(
|
|
17
|
+
dev: boolean,
|
|
18
|
+
modifiedFileSet?: Set<TNormPath>,
|
|
19
|
+
): Promise<IBuildRunnerRunResult> {
|
|
20
|
+
if (!modifiedFileSet) {
|
|
21
|
+
this._debug("GEN .config...");
|
|
22
|
+
const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
|
|
23
|
+
FsUtils.writeFile(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
|
|
24
|
+
|
|
25
|
+
const npmConf = FsUtils.readJson(path.resolve(this._pkgPath, "package.json")) as INpmConfig;
|
|
26
|
+
|
|
27
|
+
if ("@angular/router" in (npmConf.dependencies ?? {})) {
|
|
28
|
+
if (!dev) {
|
|
29
|
+
this._debug(`GEN routes.ts...`);
|
|
30
|
+
SdCliNgRoutesFileGenerator.run(this._pkgPath, this._pkgConf.noLazyRoute);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
this._debug(`Watch for GEN routes.ts...`);
|
|
34
|
+
SdCliNgRoutesFileGenerator.watch(this._pkgPath, this._pkgConf.noLazyRoute);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
58
37
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
buildMessages: result.buildMessages,
|
|
64
|
-
emitFileSet: result.emitFileSet,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async watchAsync() {
|
|
69
|
-
this.emit("change");
|
|
70
|
-
|
|
71
|
-
this._debug("dist 초기화...");
|
|
72
|
-
FsUtils.remove(path.resolve(this._pkgPath, "dist"));
|
|
73
|
-
|
|
74
|
-
if (this._npmConf.dependencies && Object.keys(this._npmConf.dependencies)
|
|
75
|
-
.includes("@angular/router")) {
|
|
76
|
-
this._debug(`WATCH GEN routes.ts...`);
|
|
77
|
-
SdCliNgRoutesFileGenerator.watch(this._pkgPath, this._pkgConf.noLazyRoute);
|
|
38
|
+
else {
|
|
39
|
+
for (const ngBundler of this._ngBundlers!) {
|
|
40
|
+
ngBundler.markForChanges(Array.from(modifiedFileSet));
|
|
41
|
+
}
|
|
78
42
|
}
|
|
79
43
|
|
|
80
|
-
this._debug("GEN .config...");
|
|
81
|
-
const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
|
|
82
|
-
FsUtils.writeFile(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
|
|
83
|
-
|
|
84
|
-
const result = await this._runAsync({ dev: !this._pkgConf.forceProductionMode });
|
|
85
|
-
const res: ISdBuildRunnerResult = {
|
|
86
|
-
affectedFilePathSet: result.affectedFileSet,
|
|
87
|
-
buildMessages: result.buildMessages,
|
|
88
|
-
emitFileSet: result.emitFileSet,
|
|
89
|
-
};
|
|
90
|
-
this.emit("complete", res);
|
|
91
|
-
|
|
92
|
-
this._debug("WATCH...");
|
|
93
|
-
let lastWatchFileSet = result.watchFileSet;
|
|
94
|
-
SdFsWatcher.watch(Array.from(this._watchScopePathSet))
|
|
95
|
-
.onChange({ delay: 100 }, async (changeInfos) => {
|
|
96
|
-
const currentChangeInfos = changeInfos.filter((item) => lastWatchFileSet.has(item.path));
|
|
97
|
-
if (currentChangeInfos.length < 1) return;
|
|
98
|
-
|
|
99
|
-
this.emit("change");
|
|
100
|
-
|
|
101
|
-
for (const ngBundler of this._ngBundlers!) {
|
|
102
|
-
ngBundler.markForChanges(currentChangeInfos.map((item) => item.path));
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const watchResult = await this._runAsync({ dev: !this._pkgConf.forceProductionMode });
|
|
106
|
-
const watchRes: ISdBuildRunnerResult = {
|
|
107
|
-
affectedFilePathSet: watchResult.affectedFileSet,
|
|
108
|
-
buildMessages: watchResult.buildMessages,
|
|
109
|
-
emitFileSet: watchResult.emitFileSet,
|
|
110
|
-
};
|
|
111
|
-
this.emit("complete", watchRes);
|
|
112
|
-
|
|
113
|
-
lastWatchFileSet = watchResult.watchFileSet;
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
private async _runAsync(opt: { dev: boolean }): Promise<{
|
|
118
|
-
watchFileSet: Set<TNormPath>;
|
|
119
|
-
affectedFileSet: Set<TNormPath>;
|
|
120
|
-
buildMessages: ISdBuildMessage[];
|
|
121
|
-
emitFileSet: Set<TNormPath>;
|
|
122
|
-
}> {
|
|
123
44
|
const ngBundlerBuilderTypes = Object.keys(this._pkgConf.builder ?? { web: {} }) as (
|
|
124
45
|
| "web"
|
|
125
46
|
| "electron"
|
|
@@ -140,15 +61,15 @@ export class SdClientBuildRunner extends EventEmitter {
|
|
|
140
61
|
this._ngBundlers = ngBundlerBuilderTypes.map(
|
|
141
62
|
(ngBundlerBuilderType) =>
|
|
142
63
|
new SdNgBundler({
|
|
143
|
-
dev
|
|
64
|
+
dev,
|
|
144
65
|
builderType: ngBundlerBuilderType,
|
|
145
66
|
pkgPath: this._pkgPath,
|
|
146
67
|
outputPath:
|
|
147
68
|
ngBundlerBuilderType === "web"
|
|
148
69
|
? PathUtils.norm(this._pkgPath, "dist")
|
|
149
|
-
: ngBundlerBuilderType === "electron" && !
|
|
70
|
+
: ngBundlerBuilderType === "electron" && !dev
|
|
150
71
|
? PathUtils.norm(this._pkgPath, ".electron/src")
|
|
151
|
-
: ngBundlerBuilderType === "cordova" && !
|
|
72
|
+
: ngBundlerBuilderType === "cordova" && !dev
|
|
152
73
|
? PathUtils.norm(this._pkgPath, ".cordova/www")
|
|
153
74
|
: PathUtils.norm(this._pkgPath, "dist", ngBundlerBuilderType),
|
|
154
75
|
env: {
|
|
@@ -162,7 +83,7 @@ export class SdClientBuildRunner extends EventEmitter {
|
|
|
162
83
|
cordovaConfig: ngBundlerBuilderType === "cordova"
|
|
163
84
|
? this._pkgConf.builder!.cordova
|
|
164
85
|
: undefined,
|
|
165
|
-
|
|
86
|
+
watchScopePathSet: this._watchScopePathSet,
|
|
166
87
|
}),
|
|
167
88
|
);
|
|
168
89
|
}
|
|
@@ -174,12 +95,12 @@ export class SdClientBuildRunner extends EventEmitter {
|
|
|
174
95
|
const emitFileSet = new Set(buildResults.mapMany((item) => Array.from(item.emitFileSet)));
|
|
175
96
|
const results = buildResults.mapMany((item) => item.results).distinct();
|
|
176
97
|
|
|
177
|
-
if (!
|
|
98
|
+
if (!dev && this._cordova) {
|
|
178
99
|
this._debug("CORDOVA BUILD...");
|
|
179
100
|
await this._cordova.buildAsync(path.resolve(this._pkgPath, "dist"));
|
|
180
101
|
}
|
|
181
102
|
|
|
182
|
-
if (!
|
|
103
|
+
if (!dev && this._pkgConf.builder?.electron) {
|
|
183
104
|
this._debug("ELECTRON BUILD...");
|
|
184
105
|
await SdCliElectron.buildAsync({
|
|
185
106
|
pkgPath: this._pkgPath,
|
|
@@ -188,20 +109,12 @@ export class SdClientBuildRunner extends EventEmitter {
|
|
|
188
109
|
}
|
|
189
110
|
|
|
190
111
|
this._debug(`빌드 완료`);
|
|
191
|
-
|
|
192
|
-
Array.from(watchFileSet).filter((item) =>
|
|
193
|
-
Array.from(this._watchScopePathSet).some((scope) => PathUtil.isChildPath(item, scope)),
|
|
194
|
-
),
|
|
195
|
-
);*/
|
|
112
|
+
|
|
196
113
|
return {
|
|
197
114
|
watchFileSet,
|
|
198
115
|
affectedFileSet,
|
|
199
|
-
buildMessages: results,
|
|
116
|
+
buildMessages: results,
|
|
200
117
|
emitFileSet,
|
|
201
118
|
};
|
|
202
119
|
}
|
|
203
|
-
|
|
204
|
-
private _debug(msg: string): void {
|
|
205
|
-
this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
|
|
206
|
-
}
|
|
207
120
|
}
|
|
@@ -45,6 +45,7 @@ import { ISdClientBuilderCordovaConfig } from "../../types/config.types";
|
|
|
45
45
|
import { ISdCliNgPluginResultCache } from "../../types/build-plugin.types";
|
|
46
46
|
import { ISdBuildMessage } from "../../types/build.types";
|
|
47
47
|
import nodeModule from "node:module";
|
|
48
|
+
import { ScopePathSet } from "../commons/scope-path";
|
|
48
49
|
|
|
49
50
|
export class SdNgBundler {
|
|
50
51
|
private _logger = SdLogger.get(["simplysm", "sd-cli", "SdNgBundler"]);
|
|
@@ -78,7 +79,7 @@ export class SdNgBundler {
|
|
|
78
79
|
env: Record<string, string> | undefined;
|
|
79
80
|
external: string[];
|
|
80
81
|
cordovaConfig: ISdClientBuilderCordovaConfig | undefined;
|
|
81
|
-
|
|
82
|
+
watchScopePathSet: ScopePathSet;
|
|
82
83
|
},
|
|
83
84
|
) {
|
|
84
85
|
this._pkgNpmConf = FsUtils.readJson(path.resolve(this._opt.pkgPath, "package.json"));
|
|
@@ -243,7 +244,7 @@ export class SdNgBundler {
|
|
|
243
244
|
for (const outputFile of outputFiles) {
|
|
244
245
|
const distFilePath = PathUtils.norm(this._opt.outputPath, outputFile.path);
|
|
245
246
|
const prevHash = this._outputHashCache.get(distFilePath);
|
|
246
|
-
const currHash = HashUtils.get(outputFile.contents);
|
|
247
|
+
const currHash = HashUtils.get(Buffer.from(outputFile.contents));
|
|
247
248
|
if (prevHash !== currHash) {
|
|
248
249
|
FsUtils.writeFile(distFilePath, outputFile.contents);
|
|
249
250
|
this._outputHashCache.set(distFilePath, currHash);
|
|
@@ -522,7 +523,7 @@ export class SdNgBundler {
|
|
|
522
523
|
dev: this._opt.dev,
|
|
523
524
|
pkgPath: this._opt.pkgPath,
|
|
524
525
|
result: this._ngResultCache,
|
|
525
|
-
|
|
526
|
+
watchScopePathSet: this._opt.watchScopePathSet,
|
|
526
527
|
}),
|
|
527
528
|
...(this._opt.builderType === "electron"
|
|
528
529
|
? []
|
|
@@ -8,13 +8,14 @@ import { SdCliConvertMessageUtils } from "../../utils/sd-cli-convert-message.uti
|
|
|
8
8
|
import { ISdCliNgPluginResultCache } from "../../types/build-plugin.types";
|
|
9
9
|
import { ISdTsCompilerResult } from "../../types/ts-compiler.types";
|
|
10
10
|
import { SdTsCompiler } from "../../ts-compiler/sd-ts-compiler";
|
|
11
|
+
import { ScopePathSet } from "../commons/scope-path";
|
|
11
12
|
|
|
12
13
|
export function createSdNgPlugin(conf: {
|
|
13
14
|
pkgPath: TNormPath;
|
|
14
15
|
dev: boolean;
|
|
15
16
|
modifiedFileSet: Set<TNormPath>;
|
|
16
17
|
result: ISdCliNgPluginResultCache;
|
|
17
|
-
|
|
18
|
+
watchScopePathSet: ScopePathSet;
|
|
18
19
|
}): esbuild.Plugin {
|
|
19
20
|
let perf: SdCliPerformanceTimer;
|
|
20
21
|
const logger = SdLogger.get(["simplysm", "sd-cli", "createSdNgPlugin"]);
|
|
@@ -31,7 +32,7 @@ export function createSdNgPlugin(conf: {
|
|
|
31
32
|
additionalOptions: { declaration: false },
|
|
32
33
|
isDevMode: conf.dev,
|
|
33
34
|
isForBundle: true,
|
|
34
|
-
|
|
35
|
+
watchScopePathSet: conf.watchScopePathSet,
|
|
35
36
|
});
|
|
36
37
|
|
|
37
38
|
let tsCompileResult: ISdTsCompilerResult;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import {
|
|
3
|
+
FsUtils,
|
|
4
|
+
ISdFsWatcherChangeInfo,
|
|
5
|
+
PathUtils,
|
|
6
|
+
SdFsWatcher,
|
|
7
|
+
SdLogger,
|
|
8
|
+
TNormPath,
|
|
9
|
+
} from "@simplysm/sd-core-node";
|
|
10
|
+
import { ISdProjectConfig, TSdPackageConfig } from "../../types/config.types";
|
|
11
|
+
import { ISdBuildMessage, ISdBuildRunnerResult } from "../../types/build.types";
|
|
12
|
+
import path from "path";
|
|
13
|
+
import { ScopePathSet } from "./scope-path";
|
|
14
|
+
|
|
15
|
+
export abstract class BuildRunnerBase<T extends "server" | "library" | "client"> extends EventEmitter {
|
|
16
|
+
protected abstract _logger: SdLogger;
|
|
17
|
+
|
|
18
|
+
protected _pkgName: string;
|
|
19
|
+
protected _pkgConf: TSdPackageConfig<T>;
|
|
20
|
+
|
|
21
|
+
protected _watchScopePathSet: ScopePathSet;
|
|
22
|
+
|
|
23
|
+
override on(event: "change", listener: () => void): this;
|
|
24
|
+
override on(event: "complete", listener: (result: ISdBuildRunnerResult) => void): this;
|
|
25
|
+
override on(event: string | symbol, listener: (...args: any[]) => void): this {
|
|
26
|
+
super.on(event, listener);
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
constructor(
|
|
31
|
+
protected _projConf: ISdProjectConfig,
|
|
32
|
+
protected _pkgPath: TNormPath,
|
|
33
|
+
) {
|
|
34
|
+
super();
|
|
35
|
+
|
|
36
|
+
this._pkgName = path.basename(_pkgPath);
|
|
37
|
+
this._pkgConf = this._projConf.packages[this._pkgName] as TSdPackageConfig<T>;
|
|
38
|
+
|
|
39
|
+
const localUpdatePaths = Object.keys(this._projConf.localUpdates ?? {}).mapMany((key) =>
|
|
40
|
+
FsUtils.glob(path.resolve(this._pkgPath, "../../node_modules", key)),
|
|
41
|
+
);
|
|
42
|
+
this._watchScopePathSet = new ScopePathSet(
|
|
43
|
+
[path.resolve(this._pkgPath, "../"), ...localUpdatePaths].map((item) => PathUtils.norm(item)),
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async buildAsync(): Promise<ISdBuildRunnerResult> {
|
|
48
|
+
const distPath = path.resolve(this._pkgPath, "dist");
|
|
49
|
+
if (FsUtils.exists(distPath)) {
|
|
50
|
+
this._debug("dist 초기화...");
|
|
51
|
+
FsUtils.remove(distPath);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const result = await this._runAsync(false);
|
|
55
|
+
return {
|
|
56
|
+
affectedFilePathSet: result.affectedFileSet,
|
|
57
|
+
buildMessages: result.buildMessages,
|
|
58
|
+
emitFileSet: result.emitFileSet,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async watchAsync() {
|
|
63
|
+
this.emit("change");
|
|
64
|
+
|
|
65
|
+
const distPath = path.resolve(this._pkgPath, "dist");
|
|
66
|
+
if (FsUtils.exists(distPath)) {
|
|
67
|
+
this._debug("dist 초기화...");
|
|
68
|
+
FsUtils.remove(distPath);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const result = await this._runAsync(!this._pkgConf.forceProductionMode);
|
|
72
|
+
const res: ISdBuildRunnerResult = {
|
|
73
|
+
affectedFilePathSet: result.affectedFileSet,
|
|
74
|
+
buildMessages: result.buildMessages,
|
|
75
|
+
emitFileSet: result.emitFileSet,
|
|
76
|
+
};
|
|
77
|
+
this.emit("complete", res);
|
|
78
|
+
|
|
79
|
+
this._debug("WATCH...");
|
|
80
|
+
let lastWatchFileSet = result.watchFileSet;
|
|
81
|
+
SdFsWatcher.watch(this._watchScopePathSet.toArray())
|
|
82
|
+
.onChange({ delay: 100 }, async (changeInfos) => {
|
|
83
|
+
const modifiedFileSet = this._getModifiedFileSet(changeInfos, lastWatchFileSet);
|
|
84
|
+
if (modifiedFileSet.size < 1) return;
|
|
85
|
+
|
|
86
|
+
this.emit("change");
|
|
87
|
+
|
|
88
|
+
let watchResult: IBuildRunnerRunResult;
|
|
89
|
+
try {
|
|
90
|
+
watchResult = await this._runAsync(!this._pkgConf.forceProductionMode, modifiedFileSet);
|
|
91
|
+
|
|
92
|
+
lastWatchFileSet = watchResult.watchFileSet;
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
watchResult = {
|
|
96
|
+
affectedFileSet: modifiedFileSet,
|
|
97
|
+
buildMessages: [
|
|
98
|
+
{
|
|
99
|
+
filePath: undefined,
|
|
100
|
+
line: undefined,
|
|
101
|
+
char: undefined,
|
|
102
|
+
code: undefined,
|
|
103
|
+
severity: "error",
|
|
104
|
+
message: `파일 변경 처리 중 오류 발생: ${err}`,
|
|
105
|
+
type: "watch",
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
emitFileSet: new Set(),
|
|
109
|
+
watchFileSet: lastWatchFileSet,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
this.emit("complete", {
|
|
114
|
+
affectedFilePathSet: watchResult.affectedFileSet,
|
|
115
|
+
buildMessages: watchResult.buildMessages,
|
|
116
|
+
emitFileSet: watchResult.emitFileSet,
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
protected _getModifiedFileSet(
|
|
122
|
+
changeInfos: ISdFsWatcherChangeInfo[],
|
|
123
|
+
lastWatchFileSet?: Set<TNormPath>,
|
|
124
|
+
) {
|
|
125
|
+
return new Set(
|
|
126
|
+
(
|
|
127
|
+
lastWatchFileSet
|
|
128
|
+
? changeInfos.filter((item) => lastWatchFileSet.has(item.path))
|
|
129
|
+
: changeInfos
|
|
130
|
+
).map(item => item.path),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
protected abstract _runAsync(
|
|
135
|
+
dev: boolean,
|
|
136
|
+
modifiedFileSet?: Set<TNormPath>,
|
|
137
|
+
): Promise<IBuildRunnerRunResult>;
|
|
138
|
+
|
|
139
|
+
protected _debug(msg: string): void {
|
|
140
|
+
this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface IBuildRunnerRunResult {
|
|
145
|
+
watchFileSet?: Set<TNormPath>;
|
|
146
|
+
affectedFileSet: Set<TNormPath>;
|
|
147
|
+
buildMessages: ISdBuildMessage[];
|
|
148
|
+
emitFileSet: Set<TNormPath>;
|
|
149
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PathUtils, TNormPath } from "@simplysm/sd-core-node";
|
|
2
|
+
|
|
3
|
+
export class ScopePathSet {
|
|
4
|
+
private _data: Set<TNormPath>;
|
|
5
|
+
|
|
6
|
+
constructor(arr?: TNormPath[]) {
|
|
7
|
+
this._data = new Set(arr);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
inScope(filePath: string) {
|
|
11
|
+
return Array.from(this._data).some((scope) => PathUtils.isChildPath(filePath, scope));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
toArray() {
|
|
15
|
+
return Array.from(this._data);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -26,7 +26,7 @@ export class SdCliIndexFileGenerator {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
// 내부 파일들 import
|
|
29
|
-
const filePaths = this
|
|
29
|
+
const filePaths = this._getFilePaths(pkgPath);
|
|
30
30
|
for (const filePath of filePaths.orderBy()) {
|
|
31
31
|
const requirePath = PathUtils.posix(path.relative(path.dirname(indexFilePath), filePath))
|
|
32
32
|
.replace(/\.tsx?$/, "")
|
|
@@ -47,7 +47,7 @@ export class SdCliIndexFileGenerator {
|
|
|
47
47
|
return content;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
static
|
|
50
|
+
private static _getFilePaths(pkgPath: string): string[] {
|
|
51
51
|
const indexFilePath = path.resolve(pkgPath, "src/index.ts");
|
|
52
52
|
|
|
53
53
|
const tsconfig = FsUtils.readJson(path.resolve(pkgPath, "tsconfig.json"));
|
|
@@ -1,94 +1,53 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
FsUtils,
|
|
3
|
+
ISdFsWatcherChangeInfo,
|
|
4
|
+
PathUtils,
|
|
5
|
+
SdLogger,
|
|
6
|
+
TNormPath,
|
|
7
|
+
} from "@simplysm/sd-core-node";
|
|
2
8
|
import path from "path";
|
|
3
|
-
import { EventEmitter } from "events";
|
|
4
9
|
import { SdCliConvertMessageUtils } from "../../utils/sd-cli-convert-message.utils";
|
|
5
10
|
// import { TSdLintWorkerType } from "../../types/workers.type";
|
|
6
|
-
import { ISdProjectConfig } from "../../types/config.types";
|
|
7
|
-
import { ISdBuildRunnerResult } from "../../types/build.types";
|
|
8
11
|
import { ESLint } from "eslint";
|
|
12
|
+
import { BuildRunnerBase, IBuildRunnerRunResult } from "../commons/build-runner.base";
|
|
9
13
|
|
|
10
|
-
export class SdJsLibBuildRunner extends
|
|
11
|
-
|
|
12
|
-
private readonly _pkgName: string;
|
|
14
|
+
export class SdJsLibBuildRunner extends BuildRunnerBase<"library"> {
|
|
15
|
+
protected override _logger = SdLogger.get(["simplysm", "sd-cli", "SdJsLibBuildRunner"]);
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
protected override async _runAsync(
|
|
18
|
+
dev: boolean,
|
|
19
|
+
modifiedFileSet?: Set<TNormPath>,
|
|
20
|
+
): Promise<IBuildRunnerRunResult> {
|
|
21
|
+
const filePathSet = modifiedFileSet ?? new Set(
|
|
22
|
+
FsUtils.glob(path.resolve(this._pkgPath, "src/**/*.js")).map(item => PathUtils.norm(item)),
|
|
23
|
+
);
|
|
15
24
|
|
|
16
|
-
constructor(
|
|
17
|
-
private readonly _projConf: ISdProjectConfig,
|
|
18
|
-
private readonly _pkgPath: string,
|
|
19
|
-
) {
|
|
20
|
-
super();
|
|
21
|
-
this._pkgName = path.basename(_pkgPath);
|
|
22
|
-
|
|
23
|
-
// this._lintWorker = new SdWorker(import.meta.resolve("../../workers/lint-worker"));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
override on(event: "change", listener: () => void): this;
|
|
27
|
-
override on(event: "complete", listener: (result: ISdBuildRunnerResult) => void): this;
|
|
28
|
-
override on(event: string | symbol, listener: (...args: any[]) => void): this {
|
|
29
|
-
super.on(event, listener);
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async buildAsync(): Promise<ISdBuildRunnerResult> {
|
|
34
25
|
this._debug("LINT...");
|
|
35
|
-
const srcGlobPath = path.resolve(this._pkgPath, "src/**/*.js");
|
|
36
|
-
const srcFilePaths = FsUtils.glob(srcGlobPath);
|
|
37
26
|
|
|
38
|
-
const lintResults = await this
|
|
27
|
+
const lintResults = await this._lintAsync(filePathSet);
|
|
39
28
|
const messages = SdCliConvertMessageUtils.convertToBuildMessagesFromEslint(lintResults);
|
|
40
29
|
|
|
41
30
|
this._debug(`LINT 완료`);
|
|
31
|
+
|
|
42
32
|
return {
|
|
43
|
-
|
|
33
|
+
affectedFileSet: filePathSet,
|
|
44
34
|
buildMessages: messages,
|
|
45
35
|
emitFileSet: new Set(),
|
|
46
36
|
};
|
|
47
37
|
}
|
|
48
38
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const messages = SdCliConvertMessageUtils.convertToBuildMessagesFromEslint(lintResults);
|
|
57
|
-
|
|
58
|
-
this._debug(`LINT 완료`);
|
|
59
|
-
const res: ISdBuildRunnerResult = {
|
|
60
|
-
affectedFilePathSet: new Set(srcFilePaths.map((item) => PathUtils.norm(item))),
|
|
61
|
-
buildMessages: messages,
|
|
62
|
-
emitFileSet: new Set(),
|
|
63
|
-
};
|
|
64
|
-
this.emit("complete", res);
|
|
65
|
-
|
|
66
|
-
SdFsWatcher.watch([srcGlobPath]).onChange({ delay: 100 }, async (changeInfos) => {
|
|
67
|
-
const watchFilePaths = changeInfos.filter((item) => FsUtils.exists(item.path)).map((item) => item.path);
|
|
68
|
-
if (watchFilePaths.length < 1) return;
|
|
69
|
-
|
|
70
|
-
this.emit("change");
|
|
71
|
-
|
|
72
|
-
this._debug("LINT...");
|
|
73
|
-
|
|
74
|
-
const watchLintResults = await this.#lintAsync(new Set(watchFilePaths));
|
|
75
|
-
const watchMessages = SdCliConvertMessageUtils.convertToBuildMessagesFromEslint(watchLintResults);
|
|
76
|
-
|
|
77
|
-
this._debug(`LINT 완료`);
|
|
78
|
-
|
|
79
|
-
const watchRes: ISdBuildRunnerResult = {
|
|
80
|
-
affectedFilePathSet: new Set(changeInfos.map((item) => PathUtils.norm(item.path))),
|
|
81
|
-
buildMessages: watchMessages,
|
|
82
|
-
emitFileSet: new Set(),
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
this.emit("complete", watchRes);
|
|
86
|
-
});
|
|
39
|
+
protected override _getModifiedFileSet(changeInfos: ISdFsWatcherChangeInfo[]) {
|
|
40
|
+
return new Set(
|
|
41
|
+
changeInfos.filter((item) =>
|
|
42
|
+
FsUtils.exists(item.path)
|
|
43
|
+
&& PathUtils.isChildPath(item.path, path.resolve(this._pkgPath, "src")),
|
|
44
|
+
).map(item => item.path),
|
|
45
|
+
);
|
|
87
46
|
}
|
|
88
47
|
|
|
89
|
-
async
|
|
48
|
+
private async _lintAsync(fileSet: Set<string>) {
|
|
90
49
|
const lintFilePaths = Array.from(fileSet)
|
|
91
|
-
.filter((item) => PathUtils.isChildPath(item, this._pkgPath))
|
|
50
|
+
.filter((item) => PathUtils.isChildPath(item, path.resolve(this._pkgPath, "src")))
|
|
92
51
|
.filter((item) => item.endsWith(".js"))
|
|
93
52
|
.filter((item) => FsUtils.exists(item));
|
|
94
53
|
|
|
@@ -99,8 +58,4 @@ export class SdJsLibBuildRunner extends EventEmitter {
|
|
|
99
58
|
const linter = new ESLint({ cwd: this._pkgPath, cache: false });
|
|
100
59
|
return await linter.lintFiles(lintFilePaths);
|
|
101
60
|
}
|
|
102
|
-
|
|
103
|
-
private _debug(msg: string): void {
|
|
104
|
-
this._logger.debug(`[${this._pkgName}] ${msg}`);
|
|
105
|
-
}
|
|
106
61
|
}
|