@simplysm/sd-cli 10.0.40 → 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 -19
- 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/SdCliViteReactSwcPlugin.js +2 -4
- package/dist/utils/SdCliViteReactSwcPlugin.js.map +1 -1
- package/dist/utils/sdCliTsDefineTransformer.js.map +1 -1
- package/package.json +12 -11
- 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 +524 -455
- 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/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
|
@@ -3,164 +3,166 @@ import path from "path";
|
|
|
3
3
|
import {ISdCliBuilderResult, ISdCliLibPackageConfig, ISdCliPackageBuildResult} from "../commons";
|
|
4
4
|
import {EventEmitter} from "events";
|
|
5
5
|
import {FunctionQueue, Uuid} from "@simplysm/sd-core-common";
|
|
6
|
-
import {SdTsIncrementalBuilder} from "../SdTsIncrementalBuilder";
|
|
7
|
-
import {SdLinter} from "../SdLinter";
|
|
6
|
+
import {SdTsIncrementalBuilder} from "../build-tools/SdTsIncrementalBuilder";
|
|
7
|
+
import {SdLinter} from "../build-tools/SdLinter";
|
|
8
8
|
import {pathToFileURL} from "url";
|
|
9
9
|
import less from "less";
|
|
10
10
|
import ts from "typescript";
|
|
11
11
|
import transformKeys from "ts-transformer-keys/transformer";
|
|
12
12
|
|
|
13
13
|
export class SdCliTsLibBuilder extends EventEmitter {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliTsLibBuilder"]);
|
|
15
|
+
|
|
16
|
+
public constructor(private readonly _pkgPath: string,
|
|
17
|
+
private readonly _pkgConf: ISdCliLibPackageConfig,
|
|
18
|
+
private readonly _withLint: boolean) {
|
|
19
|
+
super();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public override on(event: "change", listener: () => void): this;
|
|
23
|
+
public override on(event: "complete", listener: (result: ISdCliBuilderResult) => void): this;
|
|
24
|
+
public override on(event: string | symbol, listener: (...args: any[]) => void): this {
|
|
25
|
+
super.on(event, listener);
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public async buildAsync(): Promise<ISdCliBuilderResult> {
|
|
30
|
+
this._debug("빌드 준비...");
|
|
31
|
+
const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, (opt) => ({
|
|
32
|
+
emitJs: true,
|
|
33
|
+
transforms: opt.jsx === ts.JsxEmit.ReactJSX ? [{fn: transformKeys, args: undefined}] : undefined
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
this._debug("dist 초기화...");
|
|
37
|
+
await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
|
|
38
|
+
|
|
39
|
+
this._debug("BUILD...");
|
|
40
|
+
const buildResult = await sdTsProgram.buildAsync();
|
|
41
|
+
|
|
42
|
+
this._debug("LINT...");
|
|
43
|
+
const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(buildResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
|
|
44
|
+
|
|
45
|
+
let styleResult: ISdCliPackageBuildResult | undefined;
|
|
46
|
+
if (this._pkgConf.style !== undefined) {
|
|
47
|
+
this._debug("STYLE...");
|
|
48
|
+
styleResult = await this._genStyleAsync();
|
|
20
49
|
}
|
|
21
50
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
51
|
+
this._debug("COPY...");
|
|
52
|
+
await FsUtil.copyAsync(
|
|
53
|
+
path.resolve(this._pkgPath, "src/assets"),
|
|
54
|
+
path.resolve(this._pkgPath, "dist/assets")
|
|
55
|
+
);
|
|
28
56
|
|
|
29
|
-
public async buildAsync(): Promise<ISdCliBuilderResult> {
|
|
30
|
-
this._debug("빌드 준비...");
|
|
31
|
-
const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, (opt) => ({
|
|
32
|
-
emitJs: true,
|
|
33
|
-
transforms: opt.jsx === ts.JsxEmit.ReactJSX ? [{fn: transformKeys, args: undefined}] : undefined
|
|
34
|
-
}));
|
|
35
57
|
|
|
36
|
-
|
|
37
|
-
|
|
58
|
+
this._debug(`빌드 완료`);
|
|
59
|
+
return {
|
|
60
|
+
affectedFilePaths: buildResult.affectedFilePaths,
|
|
61
|
+
buildResults: [...buildResult.results, ...lintResults, ...styleResult ? [styleResult] : []]
|
|
62
|
+
};
|
|
63
|
+
}
|
|
38
64
|
|
|
39
|
-
|
|
40
|
-
|
|
65
|
+
public async watchAsync(): Promise<void> {
|
|
66
|
+
this._debug("빌드 준비...");
|
|
67
|
+
const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, (opt) => ({
|
|
68
|
+
emitJs: true,
|
|
69
|
+
// compilerOptions: opt.jsx === ts.JsxEmit.ReactJSX ? {jsx: ts.JsxEmit.ReactJSXDev} : undefined,
|
|
70
|
+
transforms: opt.jsx === ts.JsxEmit.ReactJSX ? [{fn: transformKeys, args: undefined},] : undefined
|
|
71
|
+
}));
|
|
41
72
|
|
|
42
|
-
|
|
43
|
-
|
|
73
|
+
this._debug("dist 초기화...");
|
|
74
|
+
await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
|
|
44
75
|
|
|
45
|
-
|
|
46
|
-
if (this._pkgConf.style !== undefined) {
|
|
47
|
-
this._debug("STYLE...");
|
|
48
|
-
styleResult = await this._genStyleAsync();
|
|
49
|
-
}
|
|
76
|
+
this.emit("change");
|
|
50
77
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
path.resolve(this._pkgPath, "src/assets"),
|
|
54
|
-
path.resolve(this._pkgPath, "dist/assets")
|
|
55
|
-
);
|
|
78
|
+
this._debug("BUILD...");
|
|
79
|
+
const buildResult = await sdTsProgram.buildAsync();
|
|
56
80
|
|
|
81
|
+
this._debug("LINT...");
|
|
82
|
+
const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(buildResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
|
|
57
83
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
};
|
|
84
|
+
let styleResult: ISdCliPackageBuildResult | undefined;
|
|
85
|
+
if (this._pkgConf.style !== undefined) {
|
|
86
|
+
this._debug("STYLE...");
|
|
87
|
+
styleResult = await this._genStyleAsync();
|
|
63
88
|
}
|
|
64
89
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
this._debug("COPY...");
|
|
91
|
+
await FsUtil.copyAsync(
|
|
92
|
+
path.resolve(this._pkgPath, "src/assets"),
|
|
93
|
+
path.resolve(this._pkgPath, "dist/assets")
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
this._debug(`빌드 완료`);
|
|
97
|
+
this.emit("complete", {
|
|
98
|
+
affectedFilePaths: buildResult.affectedFilePaths,
|
|
99
|
+
buildResults: [...buildResult.results, ...lintResults, ...styleResult ? [styleResult] : []]
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
this._debug("WATCH...");
|
|
103
|
+
const fnQ = new FunctionQueue();
|
|
104
|
+
SdFsWatcher
|
|
105
|
+
.watch([
|
|
106
|
+
...sdTsProgram.builderProgram!.getSourceFiles().map((item) => item.fileName),
|
|
107
|
+
path.resolve(this._pkgPath, "src/**/*.{ts,tsx}")
|
|
108
|
+
])
|
|
109
|
+
.onChange({
|
|
110
|
+
delay: 100
|
|
111
|
+
}, () => {
|
|
112
|
+
fnQ.runLast(async () => {
|
|
113
|
+
this.emit("change");
|
|
114
|
+
|
|
115
|
+
this._debug(`BUILD...`);
|
|
116
|
+
const watchBuildResult = await sdTsProgram.buildAsync();
|
|
117
|
+
|
|
118
|
+
this._debug(`LINT...`);
|
|
119
|
+
const watchLintResults = !this._withLint ? [] : await SdLinter.lintAsync(watchBuildResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
|
|
120
|
+
|
|
121
|
+
let watchStyleResult: ISdCliPackageBuildResult | undefined;
|
|
122
|
+
if (this._pkgConf.style !== undefined && watchBuildResult.affectedFilePaths.some((item) => item.endsWith(this._pkgConf.style!))) {
|
|
86
123
|
this._debug("STYLE...");
|
|
87
|
-
|
|
88
|
-
|
|
124
|
+
watchStyleResult = await this._genStyleAsync();
|
|
125
|
+
}
|
|
89
126
|
|
|
90
|
-
|
|
91
|
-
|
|
127
|
+
this._debug("COPY...");
|
|
128
|
+
await FsUtil.copyAsync(
|
|
92
129
|
path.resolve(this._pkgPath, "src/assets"),
|
|
93
130
|
path.resolve(this._pkgPath, "dist/assets")
|
|
94
|
-
|
|
131
|
+
);
|
|
95
132
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
affectedFilePaths:
|
|
99
|
-
buildResults: [...
|
|
133
|
+
this._debug(`빌드 완료`);
|
|
134
|
+
this.emit("complete", {
|
|
135
|
+
affectedFilePaths: watchBuildResult.affectedFilePaths,
|
|
136
|
+
buildResults: [...watchBuildResult.results, ...watchLintResults, ...watchStyleResult ? [watchStyleResult] : []]
|
|
137
|
+
});
|
|
100
138
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
this._debug(`BUILD...`);
|
|
116
|
-
const watchBuildResult = await sdTsProgram.buildAsync();
|
|
117
|
-
|
|
118
|
-
this._debug(`LINT...`);
|
|
119
|
-
const watchLintResults = !this._withLint ? [] : await SdLinter.lintAsync(watchBuildResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
|
|
120
|
-
|
|
121
|
-
let watchStyleResult: ISdCliPackageBuildResult | undefined;
|
|
122
|
-
if (this._pkgConf.style !== undefined && watchBuildResult.affectedFilePaths.some((item) => item.endsWith(this._pkgConf.style!))) {
|
|
123
|
-
this._debug("STYLE...");
|
|
124
|
-
watchStyleResult = await this._genStyleAsync();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
this._debug("COPY...");
|
|
128
|
-
await FsUtil.copyAsync(
|
|
129
|
-
path.resolve(this._pkgPath, "src/assets"),
|
|
130
|
-
path.resolve(this._pkgPath, "dist/assets")
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
this._debug(`빌드 완료`);
|
|
134
|
-
this.emit("complete", {
|
|
135
|
-
affectedFilePaths: watchBuildResult.affectedFilePaths,
|
|
136
|
-
buildResults: [...watchBuildResult.results, ...watchLintResults, ...watchStyleResult ? [watchStyleResult] : []]
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private _debug(msg: string): void {
|
|
143
|
+
this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private async _genStyleAsync(): Promise<ISdCliPackageBuildResult | undefined> {
|
|
147
|
+
const srcFilePath = path.resolve(this._pkgPath, "dist", this._pkgConf.style! + ".js");
|
|
148
|
+
try {
|
|
149
|
+
const styleImport = await import(pathToFileURL(srcFilePath).href + "?token=" + Uuid.new().toString());
|
|
150
|
+
const styleText = (styleImport.default as (string | Function)[]).map((item) => typeof item === "function" ? item({}) : item).join("");
|
|
151
|
+
const styleRendered = await less.render(styleText);
|
|
152
|
+
await FsUtil.writeFileAsync(path.resolve(this._pkgPath, "style.css"), styleRendered.css);
|
|
140
153
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
154
|
+
catch (err) {
|
|
155
|
+
return {
|
|
156
|
+
code: undefined,
|
|
157
|
+
message: err.message,
|
|
158
|
+
severity: "error",
|
|
159
|
+
char: undefined,
|
|
160
|
+
line: undefined,
|
|
161
|
+
filePath: srcFilePath,
|
|
162
|
+
type: "style"
|
|
163
|
+
};
|
|
144
164
|
}
|
|
145
165
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
try {
|
|
149
|
-
const styleImport = await import(pathToFileURL(srcFilePath).href + "?token=" + Uuid.new().toString());
|
|
150
|
-
const styleText = styleImport.default.join("");
|
|
151
|
-
const styleRendered = await less.render(styleText);
|
|
152
|
-
await FsUtil.writeFileAsync(path.resolve(this._pkgPath, "style.css"), styleRendered.css);
|
|
153
|
-
} catch (err) {
|
|
154
|
-
return {
|
|
155
|
-
code: undefined,
|
|
156
|
-
message: err.message,
|
|
157
|
-
severity: "error",
|
|
158
|
-
char: undefined,
|
|
159
|
-
line: undefined,
|
|
160
|
-
filePath: srcFilePath
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
166
168
|
}
|
package/src/commons.ts
CHANGED
|
@@ -1,96 +1,108 @@
|
|
|
1
1
|
export interface INpmConfig {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
name: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
version: string;
|
|
5
|
+
workspaces?: string[];
|
|
6
|
+
|
|
7
|
+
dependencies?: Record<string, string>;
|
|
8
|
+
optionalDependencies?: Record<string, string>;
|
|
9
|
+
devDependencies?: Record<string, string>;
|
|
10
|
+
peerDependencies?: Record<string, string>;
|
|
11
|
+
peerDependenciesMeta?: Record<string, {
|
|
12
|
+
optional?: boolean
|
|
13
|
+
}>;
|
|
14
|
+
|
|
15
|
+
resolutions?: Record<string, string>;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export interface ISdCliBuildClusterReqMessage {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
cmd: "watch" | "build";
|
|
20
|
+
pkgPath: string;
|
|
21
|
+
pkgConf: TSdCliPackageConfig;
|
|
22
|
+
builderKey?: "web" | "electron";
|
|
23
|
+
withLint: boolean;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export interface ISdCliBuildClusterResMessage {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
req: ISdCliBuildClusterReqMessage;
|
|
28
|
+
type: "change" | "complete" | "ready";
|
|
29
|
+
result?: ISdCliBuilderResult;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export interface ISdCliBuilderResult {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
port?: number;
|
|
34
|
+
affectedFilePaths: string[];
|
|
35
|
+
buildResults: ISdCliPackageBuildResult[];
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export interface ISdCliPackageBuildResult {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
filePath: string | undefined;
|
|
40
|
+
line: number | undefined;
|
|
41
|
+
char: number | undefined;
|
|
42
|
+
code: string | undefined;
|
|
43
|
+
severity: "error" | "warning" | "suggestion" | "message";
|
|
44
|
+
message: string;
|
|
45
|
+
type: "build" | "lint" | "style" | undefined;
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
export
|
|
48
|
-
|
|
49
|
-
localUpdates?: Record<string, string>;
|
|
50
|
-
}
|
|
51
|
-
export type TSdCliConfigFn = (isDev: boolean, opts?: string[]) => ISdCliConfig;
|
|
48
|
+
export type TSdCliConfig = Record<string, TSdCliPackageConfig | undefined>;
|
|
49
|
+
export type TSdCliConfigFn = (isDev: boolean, opts?: string[]) => TSdCliConfig;
|
|
52
50
|
|
|
53
51
|
export type TSdCliPackageConfig = ISdCliLibPackageConfig | ISdCliServerPackageConfig | ISdCliClientPackageConfig;
|
|
54
52
|
|
|
55
53
|
export interface ISdCliLibPackageConfig {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
type: "library";
|
|
55
|
+
style?: string;
|
|
56
|
+
publish?: "npm";
|
|
57
|
+
polyfills?: string[];
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
export interface ISdCliServerPackageConfig {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
type: "server";
|
|
62
|
+
externals?: string[];
|
|
63
|
+
publish?: ISdCliLocalDirectoryPublishConfig | ISdCliFtpPublishConfig;
|
|
64
|
+
configs?: Record<string, any>;
|
|
66
65
|
}
|
|
67
66
|
|
|
68
67
|
export interface ISdCliClientPackageConfig {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
68
|
+
type: "client";
|
|
69
|
+
server?: string;
|
|
70
|
+
publish?: ISdCliLocalDirectoryPublishConfig | ISdCliFtpPublishConfig;
|
|
71
|
+
env?: Record<string, string>;
|
|
72
|
+
configs?: Record<string, any>;
|
|
73
|
+
|
|
74
|
+
builder?: {
|
|
75
|
+
web?: ISdCliClientBuilderWebConfig;
|
|
76
|
+
electron?: ISdCliClientBuilderElectronConfig;
|
|
77
|
+
}
|
|
79
78
|
}
|
|
80
79
|
|
|
81
80
|
export interface ISdCliLocalDirectoryPublishConfig {
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
type: "local-directory";
|
|
82
|
+
path: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface ISdCliFtpPublishConfig {
|
|
86
|
+
type: "ftp" | "ftps" | "sftp";
|
|
87
|
+
host: string;
|
|
88
|
+
port?: number;
|
|
89
|
+
path?: string;
|
|
90
|
+
user?: string;
|
|
91
|
+
pass?: string;
|
|
84
92
|
}
|
|
85
93
|
|
|
86
94
|
export interface ISdCliClientBuilderElectronConfig {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
appId: string;
|
|
96
|
+
installerIcon?: string;
|
|
97
|
+
postInstallScript?: string;
|
|
98
|
+
devServerHost?: string;
|
|
99
|
+
devServerPort?: number;
|
|
100
|
+
reinstallDependencies?: string[];
|
|
101
|
+
env?: Record<string, string>;
|
|
92
102
|
}
|
|
93
103
|
|
|
94
104
|
export interface ISdCliClientBuilderWebConfig {
|
|
95
|
-
|
|
105
|
+
devServerHost?: string;
|
|
106
|
+
devServerPort?: number;
|
|
107
|
+
env?: Record<string, string>;
|
|
96
108
|
}
|
|
@@ -1,55 +1,131 @@
|
|
|
1
1
|
import {FsUtil, Logger, SdProcess} from "@simplysm/sd-core-node";
|
|
2
2
|
import {pathToFileURL} from "url";
|
|
3
3
|
import path from "path";
|
|
4
|
-
import {INpmConfig,
|
|
4
|
+
import {INpmConfig, TSdCliConfig} from "../commons";
|
|
5
|
+
import electronBuilder from "electron-builder";
|
|
5
6
|
|
|
6
7
|
export class SdCliElectron {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
8
|
+
public static async runAsync(opt: {
|
|
9
|
+
confFileRelPath: string;
|
|
10
|
+
optNames: string[];
|
|
11
|
+
pkgName: string;
|
|
12
|
+
}): Promise<void> {
|
|
13
|
+
const logger = Logger.get(["simplysm", "sd-cli", "SdCliElectron", "runAsync"]);
|
|
14
|
+
|
|
15
|
+
const pkgPath = path.resolve(process.cwd(), `packages/${opt.pkgName}`);
|
|
16
|
+
const electronPath = path.resolve(pkgPath, ".cache/dev/electron/src");
|
|
17
|
+
|
|
18
|
+
logger.log("설정 가져오기...");
|
|
19
|
+
const projConf = (await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)).default(true, opt.optNames) as TSdCliConfig;
|
|
20
|
+
const pkgConf = projConf[opt.pkgName];
|
|
21
|
+
if (pkgConf?.type !== "client" || pkgConf.builder?.electron === undefined) {
|
|
22
|
+
throw new Error();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
logger.log("package.json 파일 쓰기...");
|
|
26
|
+
const npmConfig = (await FsUtil.readJsonAsync(path.resolve(pkgPath, `package.json`))) as INpmConfig;
|
|
27
|
+
|
|
28
|
+
const externalPkgNames = pkgConf.builder.electron.reinstallDependencies ?? [];
|
|
29
|
+
|
|
30
|
+
await FsUtil.writeJsonAsync(path.resolve(electronPath, `package.json`), {
|
|
31
|
+
name: npmConfig.name,
|
|
32
|
+
version: npmConfig.version,
|
|
33
|
+
description: npmConfig.description,
|
|
34
|
+
main: "electron-main.js",
|
|
35
|
+
...pkgConf.builder.electron.postInstallScript !== undefined ? {
|
|
36
|
+
scripts: {
|
|
37
|
+
"postinstall": pkgConf.builder.electron.postInstallScript
|
|
38
|
+
},
|
|
39
|
+
} : {},
|
|
40
|
+
dependencies: externalPkgNames.toObject((item) => item, (item) => npmConfig.dependencies![item])
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
logger.log("npm install...");
|
|
44
|
+
await SdProcess.spawnAsync(`npm install`, {cwd: electronPath}, true);
|
|
45
|
+
|
|
46
|
+
for (const externalPkgName of externalPkgNames) {
|
|
47
|
+
if (FsUtil.exists(path.resolve(electronPath, "node_modules", externalPkgName, "binding.gyp"))) {
|
|
48
|
+
logger.log(`electron rebuild (${externalPkgName})...`);
|
|
49
|
+
await SdProcess.spawnAsync(`electron-rebuild -m ./node_modules/${externalPkgName}`, {cwd: electronPath}, true);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
logger.log("electron...");
|
|
54
|
+
await SdProcess.spawnAsync(`electron .`, {cwd: electronPath}, true);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public static async buildForDevAsync(opt: {
|
|
58
|
+
confFileRelPath: string;
|
|
59
|
+
optNames: string[];
|
|
60
|
+
pkgName: string;
|
|
61
|
+
}): Promise<void> {
|
|
62
|
+
const logger = Logger.get(["simplysm", "sd-cli", "SdCliElectron", "buildForDevAsync"]);
|
|
63
|
+
|
|
64
|
+
const pkgPath = path.resolve(process.cwd(), `packages/${opt.pkgName}`);
|
|
65
|
+
const electronPath = path.resolve(pkgPath, ".cache/dev/electron/src");
|
|
66
|
+
const electronDistPath = path.resolve(pkgPath, ".cache/dev/electron/dist");
|
|
67
|
+
|
|
68
|
+
logger.log("설정 가져오기...");
|
|
69
|
+
const projConf = (await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)).default(true, opt.optNames) as TSdCliConfig;
|
|
70
|
+
const pkgConf = projConf[opt.pkgName];
|
|
71
|
+
if (pkgConf?.type !== "client" || pkgConf.builder?.electron === undefined) {
|
|
72
|
+
throw new Error();
|
|
54
73
|
}
|
|
74
|
+
|
|
75
|
+
logger.log("package.json 파일 쓰기...");
|
|
76
|
+
const npmConfig = (await FsUtil.readJsonAsync(path.resolve(pkgPath, `package.json`))) as INpmConfig;
|
|
77
|
+
|
|
78
|
+
const externalPkgNames = pkgConf.builder.electron.reinstallDependencies ?? [];
|
|
79
|
+
|
|
80
|
+
await FsUtil.writeJsonAsync(path.resolve(electronPath, `package.json`), {
|
|
81
|
+
name: npmConfig.name,
|
|
82
|
+
version: npmConfig.version,
|
|
83
|
+
description: npmConfig.description,
|
|
84
|
+
main: "electron-main.js",
|
|
85
|
+
...pkgConf.builder.electron.postInstallScript !== undefined ? {
|
|
86
|
+
scripts: {
|
|
87
|
+
"postinstall": pkgConf.builder.electron.postInstallScript
|
|
88
|
+
},
|
|
89
|
+
} : {},
|
|
90
|
+
dependencies: externalPkgNames.toObject((item) => item, (item) => npmConfig.dependencies![item])
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
logger.log("npm install...");
|
|
94
|
+
await SdProcess.spawnAsync(`npm install`, {cwd: electronPath}, true);
|
|
95
|
+
|
|
96
|
+
for (const externalPkgName of externalPkgNames) {
|
|
97
|
+
if (FsUtil.exists(path.resolve(electronPath, "node_modules", externalPkgName, "binding.gyp"))) {
|
|
98
|
+
logger.log(`electron rebuild (${externalPkgName})...`);
|
|
99
|
+
await SdProcess.spawnAsync(`electron-rebuild -m ./node_modules/${externalPkgName}`, {cwd: electronPath}, true);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
logger.log("build...");
|
|
104
|
+
|
|
105
|
+
await electronBuilder.build({
|
|
106
|
+
targets: electronBuilder.Platform.WINDOWS.createTarget(),
|
|
107
|
+
config: {
|
|
108
|
+
appId: pkgConf.builder.electron.appId,
|
|
109
|
+
productName: npmConfig.description,
|
|
110
|
+
// asar: false,
|
|
111
|
+
win: {
|
|
112
|
+
target: "nsis"
|
|
113
|
+
},
|
|
114
|
+
nsis: {},
|
|
115
|
+
directories: {
|
|
116
|
+
app: electronPath,
|
|
117
|
+
output: electronDistPath
|
|
118
|
+
},
|
|
119
|
+
...pkgConf.builder.electron.installerIcon !== undefined ? {
|
|
120
|
+
icon: path.resolve(pkgPath, "src", pkgConf.builder.electron.installerIcon)
|
|
121
|
+
} : {},
|
|
122
|
+
removePackageScripts: false
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
await FsUtil.copyAsync(
|
|
127
|
+
path.resolve(electronDistPath, `${npmConfig.description} Setup ${npmConfig.version}.exe`),
|
|
128
|
+
path.resolve(pkgPath, `dist/electron/${npmConfig.description}-dev.exe`)
|
|
129
|
+
);
|
|
130
|
+
}
|
|
55
131
|
}
|