@simplysm/sd-cli 10.0.37 → 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.
- package/dist/SdLinter.js.map +1 -1
- package/dist/SdTsIncrementalBuilder.d.ts +17 -4
- package/dist/SdTsIncrementalBuilder.js +18 -32
- package/dist/SdTsIncrementalBuilder.js.map +1 -1
- package/dist/build-cluster.js +98 -30
- package/dist/build-cluster.js.map +1 -1
- package/dist/builders/SdCliClientBuilder.d.ts +6 -2
- package/dist/builders/SdCliClientBuilder.js +107 -114
- package/dist/builders/SdCliClientBuilder.js.map +1 -1
- package/dist/builders/SdCliServerBuilder.d.ts +2 -1
- package/dist/builders/SdCliServerBuilder.js +38 -12
- package/dist/builders/SdCliServerBuilder.js.map +1 -1
- package/dist/builders/SdCliTsLibBuilder.d.ts +5 -2
- package/dist/builders/SdCliTsLibBuilder.js +64 -10
- package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
- package/dist/commons.d.ts +28 -2
- package/dist/entry/SdCliElectron.d.ts +7 -0
- package/dist/entry/SdCliElectron.js +42 -0
- package/dist/entry/SdCliElectron.js.map +1 -0
- package/dist/entry/SdCliLocalUpdate.d.ts +12 -0
- package/dist/entry/SdCliLocalUpdate.js +94 -0
- package/dist/entry/SdCliLocalUpdate.js.map +1 -0
- package/dist/entry/SdCliProject.d.ts +3 -3
- package/dist/entry/SdCliProject.js +87 -31
- package/dist/entry/SdCliProject.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/sd-cli.d.ts +1 -1
- package/dist/sd-cli.js +74 -13
- package/dist/sd-cli.js.map +1 -1
- package/dist/utils/SdCliBuildResultUtil.js +1 -1
- package/dist/utils/SdCliBuildResultUtil.js.map +1 -1
- package/dist/utils/SdCliViteElectronMainPlugin.d.ts +6 -0
- package/dist/utils/SdCliViteElectronMainPlugin.js +81 -0
- package/dist/utils/SdCliViteElectronMainPlugin.js.map +1 -0
- package/dist/utils/SdCliViteExternalPlugin.d.ts +7 -0
- package/dist/utils/SdCliViteExternalPlugin.js +98 -0
- package/dist/utils/SdCliViteExternalPlugin.js.map +1 -0
- package/dist/utils/SdCliViteLoggerPlugin.d.ts +6 -0
- package/dist/utils/SdCliViteLoggerPlugin.js +24 -0
- package/dist/utils/SdCliViteLoggerPlugin.js.map +1 -0
- package/dist/utils/SdCliViteNodeGlobalPlugin.d.ts +2 -0
- package/dist/utils/SdCliViteNodeGlobalPlugin.js +29 -0
- package/dist/utils/SdCliViteNodeGlobalPlugin.js.map +1 -0
- package/dist/utils/SdCliViteReactSwcPlugin.d.ts +2 -0
- package/dist/utils/SdCliViteReactSwcPlugin.js +141 -0
- package/dist/utils/SdCliViteReactSwcPlugin.js.map +1 -0
- package/dist/utils/SdCliViteWatchWithResolutionsPlugin.d.ts +2 -0
- package/dist/utils/SdCliViteWatchWithResolutionsPlugin.js +26 -0
- package/dist/utils/SdCliViteWatchWithResolutionsPlugin.js.map +1 -0
- package/dist/utils/getElectronReactExternals.d.ts +1 -0
- package/dist/utils/getElectronReactExternals.js +17 -0
- package/dist/utils/getElectronReactExternals.js.map +1 -0
- package/dist/utils/sdCliTsDefineTransformer.d.ts +4 -0
- package/dist/utils/sdCliTsDefineTransformer.js +26 -0
- package/dist/utils/sdCliTsDefineTransformer.js.map +1 -0
- package/package.json +25 -11
- package/src/SdLinter.ts +2 -2
- package/src/SdTsIncrementalBuilder.ts +116 -105
- package/src/build-cluster.ts +173 -111
- package/src/builders/SdCliClientBuilder.ts +226 -221
- package/src/builders/SdCliServerBuilder.ts +311 -275
- package/src/builders/SdCliTsLibBuilder.ts +160 -89
- package/src/commons.ts +66 -34
- package/src/entry/SdCliElectron.ts +55 -0
- package/src/entry/SdCliLocalUpdate.ts +125 -0
- package/src/entry/SdCliProject.ts +452 -395
- package/src/index.ts +1 -0
- package/src/sd-cli.ts +185 -122
- package/src/utils/SdCliBuildResultUtil.ts +1 -2
- package/src/utils/SdCliViteElectronMainPlugin.ts +86 -0
- package/src/utils/SdCliViteExternalPlugin.ts +112 -0
- package/src/utils/SdCliViteLoggerPlugin.ts +29 -0
- package/src/utils/SdCliViteNodeGlobalPlugin.ts +31 -0
- package/src/utils/SdCliViteReactSwcPlugin.ts +154 -0
- package/src/utils/SdCliViteWatchWithResolutionsPlugin.ts +29 -0
- package/src/utils/getElectronReactExternals.ts +19 -0
- package/src/utils/sdCliTsDefineTransformer.ts +31 -0
- package/.eslintrc.cjs +0 -18
- package/dist/utils/SdCliConfigUtil.d.ts +0 -7
- package/dist/utils/SdCliConfigUtil.js +0 -69
- package/dist/utils/SdCliConfigUtil.js.map +0 -1
- package/src/utils/SdCliConfigUtil.ts +0 -94
|
@@ -1,234 +1,239 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import {EventEmitter} from "events";
|
|
2
|
+
import {FsUtil, Logger, SdFsWatcher} from "@simplysm/sd-core-node";
|
|
3
|
+
import {INpmConfig, ISdCliBuilderResult, ISdCliClientPackageConfig, ISdCliPackageBuildResult} from "../commons";
|
|
4
|
+
import {FunctionQueue, MathUtil} from "@simplysm/sd-core-common";
|
|
5
5
|
import * as vite from "vite";
|
|
6
|
-
import
|
|
6
|
+
import {defineConfig, InlineConfig} from "vite";
|
|
7
7
|
import vitePluginPaths from "vite-tsconfig-paths";
|
|
8
8
|
import path from "path";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
9
|
+
import {SdTsIncrementalBuilder} from "../SdTsIncrementalBuilder";
|
|
10
|
+
import {SdLinter} from "../SdLinter";
|
|
11
|
+
import {VitePWA} from 'vite-plugin-pwa';
|
|
12
|
+
import {SdCliViteNodeGlobalPlugin} from "../utils/SdCliViteNodeGlobalPlugin";
|
|
13
|
+
import {SdCliViteServeWithResolutionsPlugin} from "../utils/SdCliViteWatchWithResolutionsPlugin";
|
|
14
|
+
import {SdCliViteLoggerPlugin} from "../utils/SdCliViteLoggerPlugin";
|
|
15
|
+
import {SdCliViteReactSwcPlugin} from "../utils/SdCliViteReactSwcPlugin";
|
|
16
|
+
import {SdCliViteExternalPlugin} from "../utils/SdCliViteExternalPlugin";
|
|
17
|
+
import {SdCliViteElectronMainPlugin} from "../utils/SdCliViteElectronMainPlugin";
|
|
12
18
|
|
|
13
19
|
export class SdCliClientBuilder extends EventEmitter {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
plugins: [
|
|
87
|
-
vitePluginReact(),
|
|
88
|
-
vitePluginPaths(),
|
|
89
|
-
nodePolyfills({
|
|
90
|
-
globals: {
|
|
91
|
-
Buffer: true
|
|
92
|
-
}
|
|
93
|
-
}),
|
|
94
|
-
{
|
|
95
|
-
name: "simplysm",
|
|
96
|
-
configureServer: (server: vite.ViteDevServer) => {
|
|
97
|
-
(server.watcher.options.ignored as string[]).remove("**/node_modules/**");
|
|
98
|
-
}
|
|
20
|
+
private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliClientBuilder"]);
|
|
21
|
+
|
|
22
|
+
public constructor(private readonly _pkgPath: string,
|
|
23
|
+
private readonly _pkgConf: ISdCliClientPackageConfig,
|
|
24
|
+
private readonly _builderKey: "web" | "electron",
|
|
25
|
+
private readonly _withLint: boolean) {
|
|
26
|
+
super();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public override on(event: "change", listener: () => void): this;
|
|
30
|
+
public override on(event: "complete", listener: (result: ISdCliBuilderResult) => void): this;
|
|
31
|
+
public override on(event: string | symbol, listener: (...args: any[]) => void): this {
|
|
32
|
+
super.on(event, listener);
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public async watchAsync(): Promise<number> {
|
|
37
|
+
const cachePath = path.resolve(this._pkgPath, ".cache", "dev", ...this._builderKey !== "web" ? [this._builderKey] : []);
|
|
38
|
+
|
|
39
|
+
this.emit("change");
|
|
40
|
+
|
|
41
|
+
this._debug("BUILD...");
|
|
42
|
+
const viteServerPort = this._pkgConf.builder?.[this._builderKey]?.["devServerPort"] ?? MathUtil.getRandomInt(60000, 65535);
|
|
43
|
+
const viteServer = await vite.createServer(this._getViteConfig({
|
|
44
|
+
dev: true,
|
|
45
|
+
pkgConf: this._pkgConf,
|
|
46
|
+
cachePath: cachePath,
|
|
47
|
+
port: viteServerPort,
|
|
48
|
+
}));
|
|
49
|
+
await viteServer.listen(viteServerPort);
|
|
50
|
+
|
|
51
|
+
this._debug("CHECK...");
|
|
52
|
+
const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, () => ({emitJs: false}));
|
|
53
|
+
const checkResult = await sdTsProgram.buildAsync();
|
|
54
|
+
|
|
55
|
+
this._debug("LINT...");
|
|
56
|
+
const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
|
|
57
|
+
|
|
58
|
+
this._debug("WATCH...");
|
|
59
|
+
const fnQ = new FunctionQueue();
|
|
60
|
+
SdFsWatcher
|
|
61
|
+
.watch([
|
|
62
|
+
...sdTsProgram.builderProgram!.getSourceFiles().map((item) => item.fileName),
|
|
63
|
+
path.resolve(this._pkgPath, "src/**/*.{ts,tsx}")
|
|
64
|
+
])
|
|
65
|
+
.onChange({
|
|
66
|
+
delay: 100
|
|
67
|
+
}, () => {
|
|
68
|
+
fnQ.runLast(async () => {
|
|
69
|
+
this.emit("change");
|
|
70
|
+
|
|
71
|
+
this._debug(`CHECK...`);
|
|
72
|
+
const watchCheckResult = await sdTsProgram.buildAsync();
|
|
73
|
+
|
|
74
|
+
this._debug(`LINT...`);
|
|
75
|
+
const watchLintResults = !this._withLint ? [] : await SdLinter.lintAsync(watchCheckResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
|
|
76
|
+
|
|
77
|
+
this._debug(`빌드 완료`);
|
|
78
|
+
this.emit("complete", {
|
|
79
|
+
port: viteServerPort,
|
|
80
|
+
affectedFilePaths: watchCheckResult.affectedFilePaths,
|
|
81
|
+
buildResults: [...watchCheckResult.results, ...watchLintResults]
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
if (this._pkgConf.server !== undefined) {
|
|
87
|
+
this._debug("GEN .config...");
|
|
88
|
+
const confDistPath = path.resolve(this._pkgPath, "../../packages", this._pkgConf.server, "dist/www", path.basename(this._pkgPath), ".config.json");
|
|
89
|
+
await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
|
|
99
90
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this._debug("CHECK...");
|
|
105
|
-
const checkResult = await sdTsProgram.buildAsync();
|
|
106
|
-
|
|
107
|
-
this._debug("LINT...");
|
|
108
|
-
const lintResults = await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
|
|
109
|
-
|
|
110
|
-
this._debug("WATCH...");
|
|
111
|
-
const fnQ = new FunctionQueue();
|
|
112
|
-
SdFsWatcher
|
|
113
|
-
.watch([
|
|
114
|
-
...sdTsProgram.builderProgram!.getSourceFiles().map((item) => item.fileName),
|
|
115
|
-
path.resolve(this._pkgPath, "src/**/*.{ts,tsx}")
|
|
116
|
-
])
|
|
117
|
-
.onChange({
|
|
118
|
-
delay: 100
|
|
119
|
-
}, () => {
|
|
120
|
-
fnQ.runLast(async () => {
|
|
121
|
-
this.emit("change");
|
|
122
|
-
|
|
123
|
-
this._debug(`CHECK...`);
|
|
124
|
-
const watchCheckResult = await sdTsProgram.buildAsync();
|
|
125
|
-
|
|
126
|
-
this._debug(`LINT...`);
|
|
127
|
-
const watchLintResults = await SdLinter.lintAsync(watchCheckResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
|
|
128
|
-
|
|
129
|
-
this._debug(`빌드 완료`);
|
|
130
|
-
this.emit("complete", {
|
|
91
|
+
|
|
92
|
+
this._debug(`빌드 완료`);
|
|
93
|
+
this.emit("complete", {
|
|
131
94
|
port: viteServerPort,
|
|
132
|
-
affectedFilePaths:
|
|
133
|
-
buildResults: [...
|
|
134
|
-
});
|
|
95
|
+
affectedFilePaths: checkResult.affectedFilePaths,
|
|
96
|
+
buildResults: [...checkResult.results, ...lintResults]
|
|
135
97
|
});
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
this._debug(`빌드 완료`);
|
|
139
|
-
this.emit("complete", {
|
|
140
|
-
port: viteServerPort,
|
|
141
|
-
affectedFilePaths: checkResult.affectedFilePaths,
|
|
142
|
-
buildResults: [...checkResult.results, ...lintResults]
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
return viteServerPort;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
public async buildAsync(): Promise<ISdCliBuilderResult> {
|
|
149
|
-
this._debug("빌드 준비...");
|
|
150
|
-
const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, false, false);
|
|
151
|
-
const pkgNpmConfig: INpmConfig = await FsUtil.readJsonAsync(path.resolve(this._pkgPath, "package.json"));
|
|
152
|
-
|
|
153
|
-
this._debug("dist 초기화...");
|
|
154
|
-
await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
|
|
155
|
-
|
|
156
|
-
this._debug("BUILD...");
|
|
157
|
-
const buildResults: ISdCliPackageBuildResult[] = [];
|
|
158
|
-
try {
|
|
159
|
-
await vite.build({
|
|
160
|
-
mode: "production",
|
|
161
|
-
root: path.resolve(this._pkgPath, "src"),
|
|
162
|
-
cacheDir: path.resolve(this._pkgPath, ".cache", "vite"),
|
|
163
|
-
base: "/" + path.basename(this._pkgPath) + "/",
|
|
164
|
-
define: {
|
|
165
|
-
"import.meta.env.SD_VERSION": JSON.stringify(pkgNpmConfig.version)
|
|
166
|
-
},
|
|
167
|
-
optimizeDeps: {
|
|
168
|
-
force: true
|
|
169
|
-
},
|
|
170
|
-
resolve: {
|
|
171
|
-
preserveSymlinks: true
|
|
172
|
-
},
|
|
173
|
-
build: {
|
|
174
|
-
outDir: path.resolve(this._pkgPath, "dist"),
|
|
175
|
-
},
|
|
176
|
-
customLogger: {
|
|
177
|
-
...vite.createLogger(),
|
|
178
|
-
info: (msg) => {
|
|
179
|
-
this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
|
|
180
|
-
},
|
|
181
|
-
warn: (msg) => {
|
|
182
|
-
this._logger.warn(`[${path.basename(this._pkgPath)}] ${msg}`);
|
|
183
|
-
},
|
|
184
|
-
error: (msg) => {
|
|
185
|
-
this._logger.error(`[${path.basename(this._pkgPath)}] ${msg}`);
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
plugins: [
|
|
189
|
-
vitePluginReact(),
|
|
190
|
-
vitePluginPaths(),
|
|
191
|
-
nodePolyfills(),
|
|
192
|
-
],
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
catch (err) {
|
|
196
|
-
if ("errors" in err && err.errors instanceof Array) {
|
|
197
|
-
buildResults.push(...err.errors.map((item) => ({
|
|
198
|
-
filePath: item.location.file,
|
|
199
|
-
line: item.location.line,
|
|
200
|
-
char: item.location.column,
|
|
201
|
-
code: undefined,
|
|
202
|
-
severity: "error" as const,
|
|
203
|
-
message: item.text
|
|
204
|
-
})));
|
|
205
|
-
}
|
|
206
|
-
if ("warnings" in err && err.warnings instanceof Array) {
|
|
207
|
-
buildResults.push(...err.warnings.map((item) => ({
|
|
208
|
-
filePath: item.location.file,
|
|
209
|
-
line: item.location.line,
|
|
210
|
-
char: item.location.column,
|
|
211
|
-
code: undefined,
|
|
212
|
-
severity: "warning" as const,
|
|
213
|
-
message: item.text
|
|
214
|
-
})));
|
|
215
|
-
}
|
|
98
|
+
|
|
99
|
+
return viteServerPort;
|
|
216
100
|
}
|
|
217
101
|
|
|
218
|
-
|
|
219
|
-
|
|
102
|
+
public async buildAsync(): Promise<ISdCliBuilderResult> {
|
|
103
|
+
this._debug("dist 초기화...");
|
|
104
|
+
const cachePath = path.resolve(this._pkgPath, ".cache", "prod", ...this._builderKey !== "web" ? [this._builderKey] : []);
|
|
105
|
+
const distPath = path.resolve(this._pkgPath, "dist", ...this._builderKey !== "web" ? [this._builderKey] : []);
|
|
106
|
+
await FsUtil.removeAsync(cachePath);
|
|
107
|
+
await FsUtil.removeAsync(distPath);
|
|
108
|
+
|
|
109
|
+
this._debug("BUILD...");
|
|
110
|
+
const buildResults: ISdCliPackageBuildResult[] = [];
|
|
111
|
+
try {
|
|
112
|
+
await vite.build(this._getViteConfig({
|
|
113
|
+
dev: false,
|
|
114
|
+
pkgConf: this._pkgConf,
|
|
115
|
+
cachePath: cachePath,
|
|
116
|
+
distPath: distPath,
|
|
117
|
+
}));
|
|
118
|
+
} catch (err) {
|
|
119
|
+
if ("errors" in err && err.errors instanceof Array) {
|
|
120
|
+
buildResults.push(...err.errors.map((item: any) => ({
|
|
121
|
+
filePath: item.location.file,
|
|
122
|
+
line: item.location.line,
|
|
123
|
+
char: item.location.column,
|
|
124
|
+
code: undefined,
|
|
125
|
+
severity: "error" as const,
|
|
126
|
+
message: item.text
|
|
127
|
+
})));
|
|
128
|
+
}
|
|
129
|
+
if ("warnings" in err && err.warnings instanceof Array) {
|
|
130
|
+
buildResults.push(...err.warnings.map((item: any) => ({
|
|
131
|
+
filePath: item.location.file,
|
|
132
|
+
line: item.location.line,
|
|
133
|
+
char: item.location.column,
|
|
134
|
+
code: undefined,
|
|
135
|
+
severity: "warning" as const,
|
|
136
|
+
message: item.text
|
|
137
|
+
})));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
this._debug("CHECK...");
|
|
142
|
+
const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, () => ({emitJs: false}));
|
|
143
|
+
const checkResult = await sdTsProgram.buildAsync();
|
|
220
144
|
|
|
221
|
-
|
|
222
|
-
|
|
145
|
+
this._debug("LINT...");
|
|
146
|
+
const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
|
|
223
147
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
148
|
+
if (this._pkgConf.server !== undefined) {
|
|
149
|
+
this._debug("GEN .config...");
|
|
150
|
+
const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
|
|
151
|
+
await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
|
|
152
|
+
}
|
|
230
153
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
154
|
+
this._debug(`빌드 완료`);
|
|
155
|
+
return {
|
|
156
|
+
affectedFilePaths: checkResult.affectedFilePaths,
|
|
157
|
+
buildResults: [...buildResults, ...checkResult.results, ...lintResults]
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
private _getViteConfig(opt: {
|
|
162
|
+
dev: boolean,
|
|
163
|
+
cachePath: string,
|
|
164
|
+
distPath?: string,
|
|
165
|
+
port?: number,
|
|
166
|
+
pkgConf: ISdCliClientPackageConfig
|
|
167
|
+
}): InlineConfig {
|
|
168
|
+
const pkgNpmConfig: INpmConfig = FsUtil.readJson(path.resolve(this._pkgPath, "package.json"));
|
|
169
|
+
|
|
170
|
+
const basePath = (!opt.dev || this._pkgConf.server !== undefined) ? ("/" + path.basename(this._pkgPath) + "/") : "/";
|
|
171
|
+
|
|
172
|
+
const define = {
|
|
173
|
+
"import.meta.env.SD_ELECTRON_SERVER_URL": JSON.stringify(opt.dev ? `http://localhost:${opt.port}/` : "./index.html"),
|
|
174
|
+
"import.meta.env.SD_VERSION": JSON.stringify(pkgNpmConfig.version),
|
|
175
|
+
...this._pkgConf.env
|
|
176
|
+
? Object.keys(this._pkgConf.env)
|
|
177
|
+
.toObject(
|
|
178
|
+
(key) => "import.meta.env." + key,
|
|
179
|
+
(key) => JSON.stringify(this._pkgConf.env![key])
|
|
180
|
+
)
|
|
181
|
+
: {}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
return defineConfig({
|
|
185
|
+
mode: opt.dev ? "development" : "production",
|
|
186
|
+
root: path.resolve(this._pkgPath, "src"),
|
|
187
|
+
cacheDir: path.resolve(opt.cachePath, "vite"),
|
|
188
|
+
base: basePath,
|
|
189
|
+
define: define,
|
|
190
|
+
publicDir: false,
|
|
191
|
+
...opt.dev ? {
|
|
192
|
+
server: {
|
|
193
|
+
port: opt.port,
|
|
194
|
+
hmr: {
|
|
195
|
+
port: opt.port
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
} : {},
|
|
199
|
+
...!opt.dev ? {
|
|
200
|
+
build: {
|
|
201
|
+
outDir: this._builderKey === "electron" ? path.resolve(opt.cachePath, "src") : opt.distPath,
|
|
202
|
+
},
|
|
203
|
+
} : {},
|
|
204
|
+
plugins: [
|
|
205
|
+
SdCliViteReactSwcPlugin(),
|
|
206
|
+
SdCliViteLoggerPlugin({
|
|
207
|
+
logger: this._logger,
|
|
208
|
+
name: path.basename(this._pkgPath)
|
|
209
|
+
}),
|
|
210
|
+
vitePluginPaths(),
|
|
211
|
+
...opt.dev ? [
|
|
212
|
+
SdCliViteServeWithResolutionsPlugin(),
|
|
213
|
+
] : [],
|
|
214
|
+
...!opt.dev ? [
|
|
215
|
+
VitePWA({registerType: 'autoUpdate'}),
|
|
216
|
+
] : [],
|
|
217
|
+
...this._builderKey === "web" ? [
|
|
218
|
+
SdCliViteNodeGlobalPlugin()
|
|
219
|
+
] : [],
|
|
220
|
+
...this._builderKey === "electron" ? [
|
|
221
|
+
SdCliViteElectronMainPlugin({
|
|
222
|
+
entry: path.resolve(this._pkgPath, "src/electron-main.ts"),
|
|
223
|
+
distPath: path.resolve(opt.cachePath, "src"),
|
|
224
|
+
cachePath: path.resolve(opt.cachePath, "electron-main")
|
|
225
|
+
}),
|
|
226
|
+
SdCliViteExternalPlugin({
|
|
227
|
+
cachePath: path.resolve(opt.cachePath, "external"),
|
|
228
|
+
nodeBuiltinModules: true,
|
|
229
|
+
includes: opt.pkgConf.builder?.electron?.reinstallDependencies
|
|
230
|
+
})
|
|
231
|
+
] : [],
|
|
232
|
+
],
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
private _debug(msg: string): void {
|
|
237
|
+
this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
|
|
238
|
+
}
|
|
239
|
+
}
|