@simplysm/sd-cli 10.0.39 → 10.0.45
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/SdCliIndexFileGenerator.d.ts +5 -0
- package/dist/build-tools/SdCliIndexFileGenerator.js +51 -0
- package/dist/build-tools/SdCliIndexFileGenerator.js.map +1 -0
- package/dist/{SdLinter.d.ts → build-tools/SdLinter.d.ts} +1 -1
- package/dist/{SdLinter.js → build-tools/SdLinter.js} +2 -1
- package/dist/build-tools/SdLinter.js.map +1 -0
- package/dist/{SdTsIncrementalBuilder.d.ts → build-tools/SdTsIncrementalBuilder.d.ts} +1 -1
- package/dist/{SdTsIncrementalBuilder.js → build-tools/SdTsIncrementalBuilder.js} +1 -1
- package/dist/build-tools/SdTsIncrementalBuilder.js.map +1 -0
- package/dist/builders/SdCliClientBuilder.js +84 -8
- package/dist/builders/SdCliClientBuilder.js.map +1 -1
- package/dist/builders/SdCliJsLibLinter.js +1 -1
- package/dist/builders/SdCliJsLibLinter.js.map +1 -1
- package/dist/builders/SdCliServerBuilder.js +22 -5
- package/dist/builders/SdCliServerBuilder.js.map +1 -1
- package/dist/builders/SdCliTsLibBuilder.js +6 -5
- package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
- package/dist/commons.d.ts +18 -7
- package/dist/entry/SdCliElectron.d.ts +5 -0
- package/dist/entry/SdCliElectron.js +59 -1
- package/dist/entry/SdCliElectron.js.map +1 -1
- package/dist/entry/SdCliProject.js +75 -14
- package/dist/entry/SdCliProject.js.map +1 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -1
- package/dist/sd-cli.js +26 -21
- package/dist/sd-cli.js.map +1 -1
- package/dist/utils/SdCliBuildResultUtil.js +3 -2
- package/dist/utils/SdCliBuildResultUtil.js.map +1 -1
- package/dist/utils/SdCliViteElectronMainPlugin.js +24 -7
- package/dist/utils/SdCliViteElectronMainPlugin.js.map +1 -1
- package/dist/utils/SdCliViteExternalPlugin.d.ts +1 -0
- package/dist/utils/SdCliViteExternalPlugin.js +9 -6
- package/dist/utils/SdCliViteExternalPlugin.js.map +1 -1
- package/dist/utils/SdCliViteNodeGlobalPlugin.js +2 -2
- package/dist/utils/SdCliViteNodeGlobalPlugin.js.map +1 -1
- package/dist/utils/SdCliViteReactSwcPlugin.js +2 -4
- package/dist/utils/SdCliViteReactSwcPlugin.js.map +1 -1
- package/dist/utils/sdCliTsDefineTransformer.js.map +1 -1
- package/package.json +15 -14
- package/src/build-tools/SdCliIndexFileGenerator.ts +62 -0
- package/src/{SdLinter.ts → build-tools/SdLinter.ts} +3 -2
- package/src/{SdTsIncrementalBuilder.ts → build-tools/SdTsIncrementalBuilder.ts} +2 -2
- package/src/builders/SdCliClientBuilder.ts +298 -203
- package/src/builders/SdCliJsLibLinter.ts +1 -1
- package/src/builders/SdCliServerBuilder.ts +325 -307
- package/src/builders/SdCliTsLibBuilder.ts +135 -133
- package/src/commons.ts +73 -61
- package/src/entry/SdCliElectron.ts +124 -48
- package/src/entry/SdCliProject.ts +526 -451
- package/src/index.ts +19 -1
- package/src/sd-cli.ts +190 -179
- package/src/utils/SdCliBuildResultUtil.ts +4 -3
- package/src/utils/SdCliViteElectronMainPlugin.ts +25 -7
- package/src/utils/SdCliViteExternalPlugin.ts +12 -7
- package/src/utils/SdCliViteNodeGlobalPlugin.ts +5 -5
- package/src/utils/SdCliViteReactSwcPlugin.ts +6 -8
- package/src/utils/sdCliTsDefineTransformer.ts +23 -23
- package/tsconfig.json +7 -1
- package/dist/SdLinter.js.map +0 -1
- package/dist/SdTsIncrementalBuilder.js.map +0 -1
- package/dist/entry/SdCliLocalUpdate.d.ts +0 -12
- package/dist/entry/SdCliLocalUpdate.js +0 -94
- package/dist/entry/SdCliLocalUpdate.js.map +0 -1
- package/src/entry/SdCliLocalUpdate.ts +0 -125
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {EventEmitter} from "events";
|
|
2
|
-
import {FsUtil, Logger, SdFsWatcher} from "@simplysm/sd-core-node";
|
|
2
|
+
import {FsUtil, Logger, SdFsWatcher, SdProcess} from "@simplysm/sd-core-node";
|
|
3
3
|
import {INpmConfig, ISdCliBuilderResult, ISdCliClientPackageConfig, ISdCliPackageBuildResult} from "../commons";
|
|
4
4
|
import {FunctionQueue, MathUtil} from "@simplysm/sd-core-common";
|
|
5
5
|
import * as vite from "vite";
|
|
6
6
|
import {defineConfig, InlineConfig} from "vite";
|
|
7
7
|
import vitePluginPaths from "vite-tsconfig-paths";
|
|
8
8
|
import path from "path";
|
|
9
|
-
import {SdTsIncrementalBuilder} from "../SdTsIncrementalBuilder";
|
|
10
|
-
import {SdLinter} from "../SdLinter";
|
|
9
|
+
import {SdTsIncrementalBuilder} from "../build-tools/SdTsIncrementalBuilder";
|
|
10
|
+
import {SdLinter} from "../build-tools/SdLinter";
|
|
11
11
|
import {VitePWA} from 'vite-plugin-pwa';
|
|
12
12
|
import {SdCliViteNodeGlobalPlugin} from "../utils/SdCliViteNodeGlobalPlugin";
|
|
13
13
|
import {SdCliViteServeWithResolutionsPlugin} from "../utils/SdCliViteWatchWithResolutionsPlugin";
|
|
@@ -15,225 +15,320 @@ import {SdCliViteLoggerPlugin} from "../utils/SdCliViteLoggerPlugin";
|
|
|
15
15
|
import {SdCliViteReactSwcPlugin} from "../utils/SdCliViteReactSwcPlugin";
|
|
16
16
|
import {SdCliViteExternalPlugin} from "../utils/SdCliViteExternalPlugin";
|
|
17
17
|
import {SdCliViteElectronMainPlugin} from "../utils/SdCliViteElectronMainPlugin";
|
|
18
|
+
import electronBuilder from "electron-builder";
|
|
18
19
|
|
|
19
20
|
export class SdCliClientBuilder extends EventEmitter {
|
|
20
|
-
|
|
21
|
+
private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliClientBuilder"]);
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
public constructor(private readonly _pkgPath: string,
|
|
24
|
+
private readonly _pkgConf: ISdCliClientPackageConfig,
|
|
25
|
+
private readonly _builderKey: "web" | "electron",
|
|
26
|
+
private readonly _withLint: boolean) {
|
|
27
|
+
super();
|
|
28
|
+
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
public override on(event: "change", listener: () => void): this;
|
|
31
|
+
public override on(event: "complete", listener: (result: ISdCliBuilderResult) => void): this;
|
|
32
|
+
public override on(event: string | symbol, listener: (...args: any[]) => void): this {
|
|
33
|
+
super.on(event, listener);
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
public async watchAsync(): Promise<number> {
|
|
38
|
+
const cachePath = path.resolve(this._pkgPath, ".cache", "dev", ...this._builderKey !== "web" ? [this._builderKey] : []);
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
this.emit("change");
|
|
40
41
|
|
|
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
|
-
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));
|
|
90
|
-
}
|
|
42
|
+
this._debug("BUILD...");
|
|
43
|
+
const viteServerPort = this._pkgConf.builder?.[this._builderKey]?.["devServerPort"] ?? MathUtil.getRandomInt(60000, 65535);
|
|
44
|
+
const viteServer = await vite.createServer(this._getViteConfig({
|
|
45
|
+
dev: true,
|
|
46
|
+
pkgConf: this._pkgConf,
|
|
47
|
+
cachePath: cachePath,
|
|
48
|
+
port: viteServerPort,
|
|
49
|
+
}));
|
|
50
|
+
await viteServer.listen(viteServerPort);
|
|
51
|
+
|
|
52
|
+
this._debug("CHECK...");
|
|
53
|
+
const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, () => ({emitJs: false}));
|
|
54
|
+
const checkResult = await sdTsProgram.buildAsync();
|
|
55
|
+
|
|
56
|
+
this._debug("LINT...");
|
|
57
|
+
const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
|
|
58
|
+
|
|
59
|
+
this._debug("WATCH...");
|
|
60
|
+
const fnQ = new FunctionQueue();
|
|
61
|
+
SdFsWatcher
|
|
62
|
+
.watch([
|
|
63
|
+
...sdTsProgram.builderProgram!.getSourceFiles().map((item) => item.fileName),
|
|
64
|
+
path.resolve(this._pkgPath, "src/**/*.{ts,tsx}")
|
|
65
|
+
])
|
|
66
|
+
.onChange({
|
|
67
|
+
delay: 100
|
|
68
|
+
}, () => {
|
|
69
|
+
fnQ.runLast(async () => {
|
|
70
|
+
this.emit("change");
|
|
71
|
+
|
|
72
|
+
this._debug(`CHECK...`);
|
|
73
|
+
const watchCheckResult = await sdTsProgram.buildAsync();
|
|
74
|
+
|
|
75
|
+
this._debug(`LINT...`);
|
|
76
|
+
const watchLintResults = !this._withLint ? [] : await SdLinter.lintAsync(watchCheckResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
|
|
91
77
|
|
|
92
|
-
|
|
93
|
-
|
|
78
|
+
this._debug(`빌드 완료`);
|
|
79
|
+
this.emit("complete", {
|
|
94
80
|
port: viteServerPort,
|
|
95
|
-
affectedFilePaths:
|
|
96
|
-
buildResults: [...
|
|
81
|
+
affectedFilePaths: watchCheckResult.affectedFilePaths,
|
|
82
|
+
buildResults: [...watchCheckResult.results, ...watchLintResults]
|
|
83
|
+
});
|
|
97
84
|
});
|
|
85
|
+
});
|
|
98
86
|
|
|
99
|
-
|
|
87
|
+
if (this._pkgConf.server !== undefined) {
|
|
88
|
+
this._debug("GEN .config...");
|
|
89
|
+
const confDistPath = path.resolve(this._pkgPath, "../../packages", this._pkgConf.server, "dist/www", path.basename(this._pkgPath), ".config.json");
|
|
90
|
+
await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
|
|
100
91
|
}
|
|
101
92
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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();
|
|
93
|
+
this._debug(`빌드 완료`);
|
|
94
|
+
this.emit("complete", {
|
|
95
|
+
port: viteServerPort,
|
|
96
|
+
affectedFilePaths: checkResult.affectedFilePaths,
|
|
97
|
+
buildResults: [...checkResult.results, ...lintResults]
|
|
98
|
+
});
|
|
144
99
|
|
|
145
|
-
|
|
146
|
-
|
|
100
|
+
return viteServerPort;
|
|
101
|
+
}
|
|
147
102
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
103
|
+
public async buildAsync(): Promise<ISdCliBuilderResult> {
|
|
104
|
+
this._debug("dist 초기화...");
|
|
105
|
+
const cachePath = path.resolve(this._pkgPath, ".cache", "prod", ...this._builderKey !== "web" ? [this._builderKey] : []);
|
|
106
|
+
const distPath = path.resolve(this._pkgPath, "dist", ...this._builderKey !== "web" ? [this._builderKey] : []);
|
|
107
|
+
await FsUtil.removeAsync(cachePath);
|
|
108
|
+
await FsUtil.removeAsync(distPath);
|
|
153
109
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
110
|
+
this._debug("BUILD...");
|
|
111
|
+
const buildResults: ISdCliPackageBuildResult[] = [];
|
|
112
|
+
try {
|
|
113
|
+
await vite.build(this._getViteConfig({
|
|
114
|
+
dev: false,
|
|
115
|
+
pkgConf: this._pkgConf,
|
|
116
|
+
cachePath: cachePath,
|
|
117
|
+
distPath: distPath,
|
|
118
|
+
}));
|
|
119
|
+
} catch (err) {
|
|
120
|
+
if ("errors" in err && err.errors instanceof Array) {
|
|
121
|
+
buildResults.push(...err.errors.map((item: any) => ({
|
|
122
|
+
filePath: item.location.file,
|
|
123
|
+
line: item.location.line,
|
|
124
|
+
char: item.location.column,
|
|
125
|
+
code: undefined,
|
|
126
|
+
severity: "error" as const,
|
|
127
|
+
message: item.text
|
|
128
|
+
})));
|
|
129
|
+
}
|
|
130
|
+
if ("warnings" in err && err.warnings instanceof Array) {
|
|
131
|
+
buildResults.push(...err.warnings.map((item: any) => ({
|
|
132
|
+
filePath: item.location.file,
|
|
133
|
+
line: item.location.line,
|
|
134
|
+
char: item.location.column,
|
|
135
|
+
code: undefined,
|
|
136
|
+
severity: "warning" as const,
|
|
137
|
+
message: item.text
|
|
138
|
+
})));
|
|
139
|
+
}
|
|
159
140
|
}
|
|
160
141
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
});
|
|
142
|
+
this._debug("CHECK...");
|
|
143
|
+
const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, () => ({emitJs: false}));
|
|
144
|
+
const checkResult = await sdTsProgram.buildAsync();
|
|
145
|
+
|
|
146
|
+
this._debug("LINT...");
|
|
147
|
+
const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
|
|
148
|
+
|
|
149
|
+
if (this._pkgConf.server !== undefined) {
|
|
150
|
+
const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
|
|
151
|
+
this._debug("GEN .config...");
|
|
152
|
+
await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
|
|
234
153
|
}
|
|
235
154
|
|
|
236
|
-
|
|
237
|
-
|
|
155
|
+
if (this._builderKey === "electron") {
|
|
156
|
+
const electronSrcPath = path.resolve(this._pkgPath, ".cache/prod/electron/src");
|
|
157
|
+
const electronDistPath = path.resolve(this._pkgPath, ".cache/prod/electron/dist");
|
|
158
|
+
const pkgNpmConfig = (await FsUtil.readJsonAsync(path.resolve(this._pkgPath, `package.json`))) as INpmConfig;
|
|
159
|
+
|
|
160
|
+
this._debug("package.json 파일 쓰기...");
|
|
161
|
+
const externalPkgNames = this._pkgConf.builder!.electron!.reinstallDependencies ?? [];
|
|
162
|
+
|
|
163
|
+
await FsUtil.writeJsonAsync(path.resolve(electronSrcPath, `package.json`), {
|
|
164
|
+
name: pkgNpmConfig.name,
|
|
165
|
+
version: pkgNpmConfig.version,
|
|
166
|
+
description: pkgNpmConfig.description,
|
|
167
|
+
main: "electron-main.js",
|
|
168
|
+
...this._pkgConf.builder!.electron!.postInstallScript !== undefined ? {
|
|
169
|
+
scripts: {
|
|
170
|
+
"postinstall": this._pkgConf.builder!.electron!.postInstallScript
|
|
171
|
+
},
|
|
172
|
+
} : {},
|
|
173
|
+
dependencies: externalPkgNames.toObject((item) => item, (item) => pkgNpmConfig.dependencies![item] ?? "*")
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
this._debug("npm install...");
|
|
177
|
+
await SdProcess.spawnAsync(`npm install`, {cwd: electronSrcPath}, true);
|
|
178
|
+
|
|
179
|
+
for (const externalPkgName of externalPkgNames) {
|
|
180
|
+
if (FsUtil.exists(path.resolve(electronSrcPath, "node_modules", externalPkgName, "binding.gyp"))) {
|
|
181
|
+
this._debug(`electron rebuild (${externalPkgName})...`);
|
|
182
|
+
await SdProcess.spawnAsync(`electron-rebuild -m ./node_modules/${externalPkgName}`, {cwd: electronSrcPath}, true);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
await electronBuilder.build({
|
|
187
|
+
targets: electronBuilder.Platform.WINDOWS.createTarget(),
|
|
188
|
+
config: {
|
|
189
|
+
appId: this._pkgConf.builder!.electron!.appId,
|
|
190
|
+
productName: pkgNpmConfig.description,
|
|
191
|
+
// asar: false,
|
|
192
|
+
win: {
|
|
193
|
+
target: "nsis"
|
|
194
|
+
},
|
|
195
|
+
nsis: {},
|
|
196
|
+
directories: {
|
|
197
|
+
app: electronSrcPath,
|
|
198
|
+
output: electronDistPath
|
|
199
|
+
},
|
|
200
|
+
...this._pkgConf.builder!.electron!.installerIcon !== undefined ? {
|
|
201
|
+
icon: path.resolve(this._pkgPath, "src", this._pkgConf.builder!.electron!.installerIcon)
|
|
202
|
+
} : {},
|
|
203
|
+
removePackageScripts: false
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
await FsUtil.copyAsync(
|
|
208
|
+
path.resolve(electronDistPath, `${pkgNpmConfig.description} Setup ${pkgNpmConfig.version}.exe`),
|
|
209
|
+
path.resolve(distPath, `electron/${pkgNpmConfig.description}-latest.exe`)
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
await FsUtil.copyAsync(
|
|
213
|
+
path.resolve(electronDistPath, `${pkgNpmConfig.description} Setup ${pkgNpmConfig.version}.exe`),
|
|
214
|
+
path.resolve(distPath, `electron/updates/${pkgNpmConfig.version}.exe`)
|
|
215
|
+
);
|
|
238
216
|
}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
this._debug(`빌드 완료`);
|
|
220
|
+
return {
|
|
221
|
+
affectedFilePaths: checkResult.affectedFilePaths,
|
|
222
|
+
buildResults: [...buildResults, ...checkResult.results, ...lintResults]
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
private _getViteConfig(opt: {
|
|
227
|
+
dev: boolean,
|
|
228
|
+
cachePath: string,
|
|
229
|
+
distPath?: string,
|
|
230
|
+
port?: number,
|
|
231
|
+
pkgConf: ISdCliClientPackageConfig
|
|
232
|
+
}): InlineConfig {
|
|
233
|
+
const pkgNpmConfig: INpmConfig = FsUtil.readJson(path.resolve(this._pkgPath, "package.json"));
|
|
234
|
+
|
|
235
|
+
const basePath = this._builderKey === "electron" ? "" : (!opt.dev || this._pkgConf.server !== undefined) ? ("/" + path.basename(this._pkgPath) + "/") : "/";
|
|
236
|
+
|
|
237
|
+
const serverHost = this._pkgConf.builder?.[this._builderKey]?.devServerHost ?? "localhost";
|
|
238
|
+
|
|
239
|
+
const define = {
|
|
240
|
+
...opt.dev ? {
|
|
241
|
+
"import.meta.env.SD_SERVER_URL": JSON.stringify(`http://${serverHost}:${opt.port}` + basePath)
|
|
242
|
+
} : {},
|
|
243
|
+
"import.meta.env.SD_VERSION": JSON.stringify(pkgNpmConfig.version),
|
|
244
|
+
...this._pkgConf.env
|
|
245
|
+
? Object.keys(this._pkgConf.env)
|
|
246
|
+
.toObject(
|
|
247
|
+
(key) => "import.meta.env." + key,
|
|
248
|
+
(key) => JSON.stringify(this._pkgConf.env![key])
|
|
249
|
+
)
|
|
250
|
+
: {},
|
|
251
|
+
...this._pkgConf.builder?.[this._builderKey]?.env
|
|
252
|
+
? Object.keys(this._pkgConf.builder[this._builderKey]!.env!)
|
|
253
|
+
.toObject(
|
|
254
|
+
(key) => "import.meta.env." + key,
|
|
255
|
+
(key) => JSON.stringify(this._pkgConf.builder![this._builderKey]!.env![key])
|
|
256
|
+
)
|
|
257
|
+
: {}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
return defineConfig({
|
|
261
|
+
mode: opt.dev ? "development" : "production",
|
|
262
|
+
root: path.resolve(this._pkgPath, "src"),
|
|
263
|
+
cacheDir: path.resolve(opt.cachePath, "vite"),
|
|
264
|
+
base: basePath,
|
|
265
|
+
assetsInclude: [
|
|
266
|
+
"**/*.xlsx",
|
|
267
|
+
"**/*.xls",
|
|
268
|
+
"**/*.docx",
|
|
269
|
+
"**/*.doc",
|
|
270
|
+
"**/*.pptx",
|
|
271
|
+
"**/*.ppt",
|
|
272
|
+
"**/*.woff",
|
|
273
|
+
"**/*.woff2",
|
|
274
|
+
"**/*.ttf",
|
|
275
|
+
"**/*.eot",
|
|
276
|
+
"**/*.otf",
|
|
277
|
+
"**/*.csv",
|
|
278
|
+
"**/*.zip",
|
|
279
|
+
"**/*.pfx",
|
|
280
|
+
"**/*.pkl"
|
|
281
|
+
],
|
|
282
|
+
define: define,
|
|
283
|
+
...opt.dev ? {
|
|
284
|
+
server: {
|
|
285
|
+
host: serverHost,
|
|
286
|
+
port: opt.port,
|
|
287
|
+
hmr: {
|
|
288
|
+
host: serverHost,
|
|
289
|
+
port: opt.port
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
} : {},
|
|
293
|
+
...!opt.dev ? {
|
|
294
|
+
build: {
|
|
295
|
+
outDir: this._builderKey === "electron" ? path.resolve(opt.cachePath, "src") : opt.distPath,
|
|
296
|
+
},
|
|
297
|
+
} : {},
|
|
298
|
+
plugins: [
|
|
299
|
+
SdCliViteReactSwcPlugin(),
|
|
300
|
+
SdCliViteLoggerPlugin({
|
|
301
|
+
logger: this._logger,
|
|
302
|
+
name: path.basename(this._pkgPath)
|
|
303
|
+
}),
|
|
304
|
+
vitePluginPaths(),
|
|
305
|
+
...opt.dev ? [
|
|
306
|
+
SdCliViteServeWithResolutionsPlugin(),
|
|
307
|
+
] : [],
|
|
308
|
+
...!opt.dev && this._builderKey === "web" ? [
|
|
309
|
+
VitePWA({registerType: 'autoUpdate'}),
|
|
310
|
+
] : [],
|
|
311
|
+
...this._builderKey === "web" ? [
|
|
312
|
+
SdCliViteNodeGlobalPlugin()
|
|
313
|
+
] : [],
|
|
314
|
+
...this._builderKey === "electron" ? [
|
|
315
|
+
SdCliViteElectronMainPlugin({
|
|
316
|
+
entry: path.resolve(this._pkgPath, "src/electron-main.ts"),
|
|
317
|
+
distPath: path.resolve(opt.cachePath, "src"),
|
|
318
|
+
cachePath: path.resolve(opt.cachePath, "electron-main")
|
|
319
|
+
}),
|
|
320
|
+
SdCliViteExternalPlugin({
|
|
321
|
+
target: "browser",
|
|
322
|
+
cachePath: path.resolve(opt.cachePath, "external"),
|
|
323
|
+
nodeBuiltinModules: true,
|
|
324
|
+
includes: opt.pkgConf.builder?.electron?.reinstallDependencies
|
|
325
|
+
})
|
|
326
|
+
] : [],
|
|
327
|
+
],
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
private _debug(msg: string): void {
|
|
332
|
+
this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
|
|
333
|
+
}
|
|
239
334
|
}
|
|
@@ -2,7 +2,7 @@ import { FsUtil, Logger, SdFsWatcher } from "@simplysm/sd-core-node";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { ISdCliBuilderResult } from "../commons";
|
|
4
4
|
import { EventEmitter } from "events";
|
|
5
|
-
import { SdLinter } from "../SdLinter";
|
|
5
|
+
import { SdLinter } from "../build-tools/SdLinter";
|
|
6
6
|
|
|
7
7
|
export class SdCliJsLibLinter extends EventEmitter {
|
|
8
8
|
private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliJsLibLinter"]);
|