@simplysm/sd-cli 10.0.66 → 11.0.4
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-cluster.js +16 -15
- package/dist/build-cluster.js.map +1 -1
- package/dist/build-tools/SdNgBundler.d.ts +20 -0
- package/dist/build-tools/SdNgBundler.js +312 -0
- package/dist/build-tools/SdNgBundler.js.map +1 -0
- package/dist/build-tools/SdTsBundler.d.ts +15 -0
- package/dist/build-tools/SdTsBundler.js +96 -0
- package/dist/build-tools/SdTsBundler.js.map +1 -0
- package/dist/build-tools/SdTsCompiler.d.ts +28 -0
- package/dist/build-tools/SdTsCompiler.js +212 -0
- package/dist/build-tools/SdTsCompiler.js.map +1 -0
- package/dist/builders/SdCliClientBuilder.d.ts +5 -7
- package/dist/builders/SdCliClientBuilder.js +75 -267
- package/dist/builders/SdCliClientBuilder.js.map +1 -1
- package/dist/builders/SdCliServerBuilder.d.ts +4 -3
- package/dist/builders/SdCliServerBuilder.js +82 -218
- package/dist/builders/SdCliServerBuilder.js.map +1 -1
- package/dist/builders/SdCliTsLibBuilder.d.ts +3 -4
- package/dist/builders/SdCliTsLibBuilder.js +37 -87
- package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
- package/dist/commons.d.ts +11 -5
- package/dist/entry/SdCliProject.js +22 -18
- package/dist/entry/SdCliProject.js.map +1 -1
- package/dist/index.d.ts +3 -11
- package/dist/index.js +3 -11
- package/dist/index.js.map +1 -1
- package/dist/sd-cli.js +0 -19
- package/dist/sd-cli.js.map +1 -1
- package/dist/server-worker.js +3 -0
- package/dist/server-worker.js.map +1 -1
- package/package.json +17 -19
- package/src/build-cluster.ts +16 -15
- package/src/build-tools/SdNgBundler.ts +381 -0
- package/src/build-tools/SdTsBundler.ts +106 -0
- package/src/build-tools/SdTsCompiler.ts +304 -0
- package/src/builders/SdCliClientBuilder.ts +93 -312
- package/src/builders/SdCliServerBuilder.ts +99 -242
- package/src/builders/SdCliTsLibBuilder.ts +41 -111
- package/src/commons.ts +11 -5
- package/src/entry/SdCliElectron.ts +3 -3
- package/src/entry/SdCliLocalUpdate.ts +3 -3
- package/src/entry/SdCliProject.ts +33 -26
- package/src/index.ts +3 -11
- package/src/sd-cli.ts +0 -23
- package/src/server-worker.ts +3 -0
- package/dist/build-tools/SdTsIncrementalBuilder.d.ts +0 -29
- package/dist/build-tools/SdTsIncrementalBuilder.js +0 -75
- package/dist/build-tools/SdTsIncrementalBuilder.js.map +0 -1
- package/dist/entry/SdCliPwaAssets.d.ts +0 -6
- package/dist/entry/SdCliPwaAssets.js +0 -39
- package/dist/entry/SdCliPwaAssets.js.map +0 -1
- package/dist/utils/SdCliViteElectronMainPlugin.d.ts +0 -6
- package/dist/utils/SdCliViteElectronMainPlugin.js +0 -96
- package/dist/utils/SdCliViteElectronMainPlugin.js.map +0 -1
- package/dist/utils/SdCliViteExternalPlugin.d.ts +0 -6
- package/dist/utils/SdCliViteExternalPlugin.js +0 -85
- package/dist/utils/SdCliViteExternalPlugin.js.map +0 -1
- package/dist/utils/SdCliViteLazyImportPlugin.d.ts +0 -2
- package/dist/utils/SdCliViteLazyImportPlugin.js +0 -23
- package/dist/utils/SdCliViteLazyImportPlugin.js.map +0 -1
- package/dist/utils/SdCliViteLoggerPlugin.d.ts +0 -6
- package/dist/utils/SdCliViteLoggerPlugin.js +0 -24
- package/dist/utils/SdCliViteLoggerPlugin.js.map +0 -1
- package/dist/utils/SdCliViteNodeGlobalPlugin.d.ts +0 -2
- package/dist/utils/SdCliViteNodeGlobalPlugin.js +0 -29
- package/dist/utils/SdCliViteNodeGlobalPlugin.js.map +0 -1
- package/dist/utils/SdCliViteReactSwcPlugin.d.ts +0 -2
- package/dist/utils/SdCliViteReactSwcPlugin.js +0 -139
- package/dist/utils/SdCliViteReactSwcPlugin.js.map +0 -1
- package/dist/utils/SdCliViteServeOptimizeExcludePlugin.d.ts +0 -2
- package/dist/utils/SdCliViteServeOptimizeExcludePlugin.js +0 -36
- package/dist/utils/SdCliViteServeOptimizeExcludePlugin.js.map +0 -1
- package/dist/utils/getElectronReactExternals.d.ts +0 -1
- package/dist/utils/getElectronReactExternals.js +0 -17
- package/dist/utils/getElectronReactExternals.js.map +0 -1
- package/dist/utils/sdCliTsDefineTransformer.d.ts +0 -4
- package/dist/utils/sdCliTsDefineTransformer.js +0 -26
- package/dist/utils/sdCliTsDefineTransformer.js.map +0 -1
- package/src/build-tools/SdTsIncrementalBuilder.ts +0 -125
- package/src/entry/SdCliPwaAssets.ts +0 -50
- package/src/utils/SdCliViteElectronMainPlugin.ts +0 -102
- package/src/utils/SdCliViteExternalPlugin.ts +0 -98
- package/src/utils/SdCliViteLazyImportPlugin.ts +0 -26
- package/src/utils/SdCliViteLoggerPlugin.ts +0 -29
- package/src/utils/SdCliViteNodeGlobalPlugin.ts +0 -31
- package/src/utils/SdCliViteReactSwcPlugin.ts +0 -153
- package/src/utils/SdCliViteServeOptimizeExcludePlugin.ts +0 -42
- package/src/utils/getElectronReactExternals.ts +0 -19
- package/src/utils/sdCliTsDefineTransformer.ts +0 -33
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { SdCliBuildResultUtil } from "../utils/SdCliBuildResultUtil";
|
|
4
|
+
import { FsUtil, Logger, PathUtil } from "@simplysm/sd-core-node";
|
|
5
|
+
import { NgtscProgram } from "@angular/compiler-cli";
|
|
6
|
+
import { createHash } from "crypto";
|
|
7
|
+
import { fileURLToPath, pathToFileURL } from "url";
|
|
8
|
+
import * as sass from "sass";
|
|
9
|
+
export class SdTsCompiler {
|
|
10
|
+
get program() {
|
|
11
|
+
if (!this._program) {
|
|
12
|
+
throw new Error("TS 프로그램 NULL");
|
|
13
|
+
}
|
|
14
|
+
return this._program;
|
|
15
|
+
}
|
|
16
|
+
constructor(_opt) {
|
|
17
|
+
this._opt = _opt;
|
|
18
|
+
this._logger = Logger.get(["simplysm", "sd-cli", "SdTsCompiler"]);
|
|
19
|
+
this._writeFileCache = new Map();
|
|
20
|
+
this._styleDepsCache = new Map();
|
|
21
|
+
this._markedChanges = [];
|
|
22
|
+
//-- tsconfig
|
|
23
|
+
const tsConfigFilePath = path.resolve(_opt.pkgPath, "tsconfig.json");
|
|
24
|
+
const tsConfig = FsUtil.readJson(tsConfigFilePath);
|
|
25
|
+
this._parsedTsConfig = ts.parseJsonConfigFileContent(tsConfig, ts.sys, _opt.pkgPath, {
|
|
26
|
+
...tsConfig.angularCompilerOptions ?? {},
|
|
27
|
+
..._opt.emitDts !== undefined ? { declaration: _opt.emitDts } : {}
|
|
28
|
+
});
|
|
29
|
+
//-- vars
|
|
30
|
+
this._isForAngular = Boolean(tsConfig.angularCompilerOptions);
|
|
31
|
+
//-- host
|
|
32
|
+
this._compilerHost = ts.createIncrementalCompilerHost(this._parsedTsConfig.options);
|
|
33
|
+
if (tsConfig.angularCompilerOptions) {
|
|
34
|
+
this._compilerHost["readResource"] = (fileName) => {
|
|
35
|
+
return this._compilerHost.readFile(fileName);
|
|
36
|
+
};
|
|
37
|
+
this._compilerHost["transformResource"] = async (data, context) => {
|
|
38
|
+
if (context.resourceFile != null || context.type !== "style") {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const scssResult = await sass.compileStringAsync(data, {
|
|
43
|
+
url: new URL(context.containingFile + ".scss"),
|
|
44
|
+
importer: {
|
|
45
|
+
findFileUrl: (url) => pathToFileURL(url)
|
|
46
|
+
},
|
|
47
|
+
logger: sass.Logger.silent
|
|
48
|
+
});
|
|
49
|
+
const styleContent = scssResult.css.toString();
|
|
50
|
+
const deps = scssResult.loadedUrls.slice(1).map((item) => path.resolve(fileURLToPath(item.href)));
|
|
51
|
+
for (const dep of deps) {
|
|
52
|
+
const depCache = this._styleDepsCache.getOrCreate(dep, new Set());
|
|
53
|
+
depCache.add(path.resolve(context.containingFile));
|
|
54
|
+
}
|
|
55
|
+
return { content: styleContent };
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
this._logger.error("scss 파싱 에러", err);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
markChanges(changes) {
|
|
65
|
+
this._markedChanges.push(...changes);
|
|
66
|
+
}
|
|
67
|
+
async buildAsync() {
|
|
68
|
+
const markedChanges = this._markedChanges;
|
|
69
|
+
this._markedChanges = [];
|
|
70
|
+
const distPath = path.resolve(this._opt.pkgPath, "dist");
|
|
71
|
+
const srcFilePaths = await FsUtil.globAsync(path.resolve(this._opt.pkgPath, "src/**/*.{ts,tsx}"));
|
|
72
|
+
const srcFilePathSet = new Set(srcFilePaths);
|
|
73
|
+
if (this._isForAngular) {
|
|
74
|
+
this._ngProgram = new NgtscProgram(srcFilePaths, this._parsedTsConfig.options, this._compilerHost, this._ngProgram);
|
|
75
|
+
this._program = this._ngProgram.getTsProgram();
|
|
76
|
+
const baseGetSourceFiles = this._program.getSourceFiles;
|
|
77
|
+
this._program.getSourceFiles = function (...parameters) {
|
|
78
|
+
const files = baseGetSourceFiles(...parameters);
|
|
79
|
+
for (const file of files) {
|
|
80
|
+
if (file.version === undefined) {
|
|
81
|
+
file.version = createHash("sha256").update(file.text).digest("hex");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return files;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this._program = ts.createProgram(srcFilePaths, this._parsedTsConfig.options, this._compilerHost, this._program);
|
|
89
|
+
}
|
|
90
|
+
this._builder = ts.createSemanticDiagnosticsBuilderProgram(this._program, this._compilerHost, this._builder);
|
|
91
|
+
const diagnostics = [];
|
|
92
|
+
const affectedFilePaths = [];
|
|
93
|
+
if (this._ngProgram) {
|
|
94
|
+
diagnostics.push(...this._ngProgram.compiler.getOptionDiagnostics());
|
|
95
|
+
}
|
|
96
|
+
diagnostics.push(...this._builder.getOptionsDiagnostics(), ...this._builder.getGlobalDiagnostics());
|
|
97
|
+
if (this._ngProgram) {
|
|
98
|
+
await this._ngProgram.compiler.analyzeAsync();
|
|
99
|
+
}
|
|
100
|
+
this._logger.debug(`[${path.basename(this._opt.pkgPath)}] 영향받는 파일 확인중...`);
|
|
101
|
+
while (true) {
|
|
102
|
+
let affectedSourceFile;
|
|
103
|
+
const semanticResult = this._builder.getSemanticDiagnosticsOfNextAffectedFile(undefined, (sourceFile) => {
|
|
104
|
+
//-- ngtypecheck의 org파일 포함 (ngtypecheck 파일는 무시)
|
|
105
|
+
if (this._ngProgram?.compiler.ignoreForDiagnostics.has(sourceFile) && sourceFile.fileName.endsWith(".ngtypecheck.ts")) {
|
|
106
|
+
const orgFileName = sourceFile.fileName.slice(0, -15) + ".ts";
|
|
107
|
+
const orgSourceFile = this._builder.getSourceFile(orgFileName);
|
|
108
|
+
if (orgSourceFile) {
|
|
109
|
+
affectedSourceFile = orgSourceFile;
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
//-- 소스폴더 파일 포함
|
|
114
|
+
else if (srcFilePathSet.has(path.resolve(sourceFile.fileName))) {
|
|
115
|
+
affectedSourceFile = sourceFile;
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
//-- 나머지 무시
|
|
119
|
+
else {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
if (!semanticResult || !affectedSourceFile)
|
|
124
|
+
break;
|
|
125
|
+
diagnostics.push(...semanticResult.result);
|
|
126
|
+
if ("fileName" in affectedSourceFile) {
|
|
127
|
+
affectedFilePaths.push(path.resolve(affectedSourceFile.fileName));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (this._isForAngular) {
|
|
131
|
+
for (const markedChange of markedChanges) {
|
|
132
|
+
const depsSet = this._styleDepsCache.get(markedChange);
|
|
133
|
+
if (depsSet) {
|
|
134
|
+
affectedFilePaths.push(...depsSet);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
affectedFilePaths.distinctThis();
|
|
138
|
+
}
|
|
139
|
+
const globalStyleFilePath = path.resolve(this._opt.pkgPath, "src/styles.scss");
|
|
140
|
+
if (this._opt.globalStyle && FsUtil.exists(globalStyleFilePath) && markedChanges.includes(globalStyleFilePath)) {
|
|
141
|
+
affectedFilePaths.push(globalStyleFilePath);
|
|
142
|
+
affectedFilePaths.distinctThis();
|
|
143
|
+
}
|
|
144
|
+
this._logger.debug(`[${path.basename(this._opt.pkgPath)}] 영향받는 파일 ${this._opt.emit ? "EMIT" : "CHECK"}...`);
|
|
145
|
+
for (const affectedFilePath of affectedFilePaths) {
|
|
146
|
+
if (this._opt.globalStyle && affectedFilePath === globalStyleFilePath) {
|
|
147
|
+
try {
|
|
148
|
+
const content = await FsUtil.readFileAsync(affectedFilePath);
|
|
149
|
+
const scssResult = await sass.compileStringAsync(content, {
|
|
150
|
+
url: new URL(affectedFilePath),
|
|
151
|
+
importer: {
|
|
152
|
+
findFileUrl: (url) => pathToFileURL(url)
|
|
153
|
+
},
|
|
154
|
+
logger: sass.Logger.silent
|
|
155
|
+
});
|
|
156
|
+
const deps = scssResult.loadedUrls.slice(1).map((item) => path.resolve(fileURLToPath(item.href)));
|
|
157
|
+
for (const dep of deps) {
|
|
158
|
+
const depCache = this._styleDepsCache.getOrCreate(dep, new Set());
|
|
159
|
+
depCache.add(affectedFilePath);
|
|
160
|
+
}
|
|
161
|
+
if (this._opt.emit) {
|
|
162
|
+
const outFilePath = path.resolve(this._opt.pkgPath, path.basename(affectedFilePath, path.extname(affectedFilePath)) + ".css");
|
|
163
|
+
this._writeFile(outFilePath, scssResult.css.toString());
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
this._logger.error(err);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
const affectedSourceFile = this._builder.getSourceFile(affectedFilePath);
|
|
172
|
+
if (!affectedSourceFile)
|
|
173
|
+
continue;
|
|
174
|
+
const emitResult = this._builder.emit(affectedSourceFile, (filePath, data) => {
|
|
175
|
+
let realFilePath = filePath;
|
|
176
|
+
let realData = data;
|
|
177
|
+
if (PathUtil.isChildPath(realFilePath, path.resolve(distPath, path.basename(this._opt.pkgPath), "src"))) {
|
|
178
|
+
realFilePath = path.resolve(distPath, path.relative(path.resolve(distPath, path.basename(this._opt.pkgPath), "src"), realFilePath));
|
|
179
|
+
if (filePath.endsWith(".js.map")) {
|
|
180
|
+
const sourceMapContents = JSON.parse(realData);
|
|
181
|
+
// remove "../../"
|
|
182
|
+
sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
|
|
183
|
+
realData = JSON.stringify(sourceMapContents);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
this._writeFile(realFilePath, realData);
|
|
187
|
+
}, undefined, !this._opt.emit, { ...this._ngProgram?.compiler.prepareEmit().transformers ?? {} });
|
|
188
|
+
diagnostics.push(...emitResult.diagnostics);
|
|
189
|
+
diagnostics.push(...this._builder.getSyntacticDiagnostics(affectedSourceFile));
|
|
190
|
+
if (this._ngProgram &&
|
|
191
|
+
!affectedSourceFile.isDeclarationFile &&
|
|
192
|
+
!this._ngProgram.compiler.ignoreForEmit.has(affectedSourceFile) &&
|
|
193
|
+
!this._ngProgram.compiler.incrementalCompilation.safeToSkipEmit(affectedSourceFile)) {
|
|
194
|
+
diagnostics.push(...this._ngProgram.compiler.getDiagnosticsForFile(affectedSourceFile, 1));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
this._logger.debug(`[${path.basename(this._opt.pkgPath)}] 영향받는 파일 ${this._opt.emit ? "EMIT" : "CHECK"} 완료`, affectedFilePaths);
|
|
199
|
+
const buildResults = diagnostics.map((item) => SdCliBuildResultUtil.convertFromTsDiag(item));
|
|
200
|
+
return {
|
|
201
|
+
affectedFilePaths: affectedFilePaths.filter((item) => !item.endsWith(".scss")),
|
|
202
|
+
results: buildResults
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
_writeFile(filePath, data) {
|
|
206
|
+
if (this._writeFileCache.get(filePath) !== data) {
|
|
207
|
+
this._compilerHost.writeFile(filePath, data, false);
|
|
208
|
+
}
|
|
209
|
+
this._writeFileCache.set(filePath, data);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=SdTsCompiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SdTsCompiler.js","sourceRoot":"","sources":["../../src/build-tools/SdTsCompiler.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAC,oBAAoB,EAAC,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,wBAAwB,CAAC;AAEhE,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAC,UAAU,EAAC,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,KAAK,CAAC;AACjD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,MAAM,OAAO,YAAY;IAevB,IAAW,OAAO;QAChB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;SACjC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,YAAoC,IAKnC;QALmC,SAAI,GAAJ,IAAI,CAKvC;QA1BgB,YAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC;QAG7D,oBAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;QAQ5C,oBAAe,GAAG,IAAI,GAAG,EAAuB,CAAC;QAC1D,mBAAc,GAAa,EA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AAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;QAE7F,OAAO;YACL,iBAAiB,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC9E,OAAO,EAAE,YAAY;SACtB,CAAC;IACJ,CAAC;IAEO,UAAU,CAAC,QAAgB,EAAE,IAAY;QAC/C,IAAI,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE;YAC/C,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;SACrD;QACD,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;CACF"}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from "events";
|
|
3
|
-
import { ISdCliBuilderResult,
|
|
3
|
+
import { ISdCliBuilderResult, ISdCliConfig } from "../commons";
|
|
4
4
|
export declare class SdCliClientBuilder extends EventEmitter {
|
|
5
|
+
private readonly _projConf;
|
|
5
6
|
private readonly _pkgPath;
|
|
6
|
-
private readonly _pkgConf;
|
|
7
|
-
private readonly _builderKey;
|
|
8
|
-
private readonly _withLint;
|
|
9
7
|
private readonly _logger;
|
|
10
|
-
|
|
8
|
+
private readonly _pkgConf;
|
|
9
|
+
constructor(_projConf: ISdCliConfig, _pkgPath: string);
|
|
11
10
|
on(event: "change", listener: () => void): this;
|
|
12
11
|
on(event: "complete", listener: (result: ISdCliBuilderResult) => void): this;
|
|
13
|
-
watchAsync(): Promise<number>;
|
|
14
12
|
buildAsync(): Promise<ISdCliBuilderResult>;
|
|
15
|
-
|
|
13
|
+
watchAsync(): Promise<void>;
|
|
16
14
|
private _debug;
|
|
17
15
|
}
|
|
@@ -1,298 +1,106 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
|
-
import { FsUtil, Logger, SdFsWatcher
|
|
3
|
-
import { FunctionQueue
|
|
4
|
-
import * as vite from "vite";
|
|
5
|
-
import { defineConfig } from "vite";
|
|
6
|
-
import vitePluginPaths from "vite-tsconfig-paths";
|
|
2
|
+
import { FsUtil, Logger, SdFsWatcher } from "@simplysm/sd-core-node";
|
|
3
|
+
import { FunctionQueue } from "@simplysm/sd-core-common";
|
|
7
4
|
import path from "path";
|
|
8
|
-
import {
|
|
5
|
+
import { SdTsCompiler } from "../build-tools/SdTsCompiler";
|
|
6
|
+
import { SdNgBundler } from "../build-tools/SdNgBundler";
|
|
9
7
|
import { SdLinter } from "../build-tools/SdLinter";
|
|
10
|
-
import { VitePWA } from 'vite-plugin-pwa';
|
|
11
|
-
import { SdCliViteNodeGlobalPlugin } from "../utils/SdCliViteNodeGlobalPlugin";
|
|
12
|
-
import { SdCliViteLoggerPlugin } from "../utils/SdCliViteLoggerPlugin";
|
|
13
|
-
import { SdCliViteReactSwcPlugin } from "../utils/SdCliViteReactSwcPlugin";
|
|
14
|
-
import { SdCliViteExternalPlugin } from "../utils/SdCliViteExternalPlugin";
|
|
15
|
-
import { SdCliViteElectronMainPlugin } from "../utils/SdCliViteElectronMainPlugin";
|
|
16
|
-
import electronBuilder from "electron-builder";
|
|
17
|
-
import { SdCliViteServeOptimizeExcludePlugin } from "../utils/SdCliViteServeOptimizeExcludePlugin";
|
|
18
|
-
import { SdCliViteLazyImportPlugin } from "../utils/SdCliViteLazyImportPlugin";
|
|
19
8
|
export class SdCliClientBuilder extends EventEmitter {
|
|
20
|
-
constructor(
|
|
9
|
+
constructor(_projConf, _pkgPath) {
|
|
21
10
|
super();
|
|
11
|
+
this._projConf = _projConf;
|
|
22
12
|
this._pkgPath = _pkgPath;
|
|
23
|
-
this._pkgConf = _pkgConf;
|
|
24
|
-
this._builderKey = _builderKey;
|
|
25
|
-
this._withLint = _withLint;
|
|
26
13
|
this._logger = Logger.get(["simplysm", "sd-cli", "SdCliClientBuilder"]);
|
|
14
|
+
this._pkgConf = this._projConf.packages[path.basename(_pkgPath)];
|
|
27
15
|
}
|
|
28
16
|
on(event, listener) {
|
|
29
17
|
super.on(event, listener);
|
|
30
18
|
return this;
|
|
31
19
|
}
|
|
20
|
+
async buildAsync() {
|
|
21
|
+
this._debug("dist 초기화...");
|
|
22
|
+
await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
|
|
23
|
+
this._debug("GEN .config...");
|
|
24
|
+
const confDistPath = this._pkgConf.server !== undefined
|
|
25
|
+
? path.resolve(this._pkgPath, "../../packages", this._pkgConf.server, "dist/www", path.basename(this._pkgPath), ".config.json")
|
|
26
|
+
: path.resolve(this._pkgPath, "dist");
|
|
27
|
+
await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
|
|
28
|
+
this._debug(`BUILD 준비...`);
|
|
29
|
+
const builderTypes = Object.keys(this._pkgConf.builder ?? { web: {} });
|
|
30
|
+
const builders = builderTypes.map((builderType) => new SdNgBundler({
|
|
31
|
+
dev: false,
|
|
32
|
+
builderType: builderType,
|
|
33
|
+
pkgPath: this._pkgPath
|
|
34
|
+
}));
|
|
35
|
+
const checker = new SdTsCompiler({
|
|
36
|
+
pkgPath: this._pkgPath,
|
|
37
|
+
emit: false,
|
|
38
|
+
emitDts: false,
|
|
39
|
+
globalStyle: false
|
|
40
|
+
});
|
|
41
|
+
this._debug(`BUILD...`);
|
|
42
|
+
const buildResults = (await Promise.all(builders.map((builder) => builder.bundleAsync()))).mapMany();
|
|
43
|
+
this._debug("CHECK...");
|
|
44
|
+
const checkResult = await checker.buildAsync();
|
|
45
|
+
this._debug(`LINT...`);
|
|
46
|
+
const lintResults = await SdLinter.lintAsync(checkResult.affectedFilePaths, checker.program);
|
|
47
|
+
this._debug(`빌드 완료`);
|
|
48
|
+
return {
|
|
49
|
+
affectedFilePaths: checkResult.affectedFilePaths,
|
|
50
|
+
buildResults: [...buildResults, ...checkResult.results, ...lintResults]
|
|
51
|
+
};
|
|
52
|
+
}
|
|
32
53
|
async watchAsync() {
|
|
33
|
-
|
|
34
|
-
this.
|
|
35
|
-
this._debug("
|
|
36
|
-
const
|
|
37
|
-
|
|
54
|
+
this._debug("dist 초기화...");
|
|
55
|
+
await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
|
|
56
|
+
this._debug("GEN .config...");
|
|
57
|
+
const confDistPath = this._pkgConf.server !== undefined
|
|
58
|
+
? path.resolve(this._pkgPath, "../../packages", this._pkgConf.server, "dist/www", path.basename(this._pkgPath), ".config.json")
|
|
59
|
+
: path.resolve(this._pkgPath, "dist");
|
|
60
|
+
await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
|
|
61
|
+
this._debug(`BUILD 준비...`);
|
|
62
|
+
const builderTypes = Object.keys(this._pkgConf.builder ?? { web: {} });
|
|
63
|
+
const builders = builderTypes.map((builderType) => new SdNgBundler({
|
|
38
64
|
dev: true,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
port: viteServerPort,
|
|
65
|
+
builderType: builderType,
|
|
66
|
+
pkgPath: this._pkgPath
|
|
42
67
|
}));
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
68
|
+
const checker = new SdTsCompiler({
|
|
69
|
+
pkgPath: this._pkgPath,
|
|
70
|
+
emit: false,
|
|
71
|
+
emitDts: false,
|
|
72
|
+
globalStyle: false
|
|
73
|
+
});
|
|
49
74
|
this._debug("WATCH...");
|
|
50
75
|
const fnQ = new FunctionQueue();
|
|
51
|
-
SdFsWatcher
|
|
76
|
+
const watcher = SdFsWatcher
|
|
52
77
|
.watch([
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
78
|
+
path.resolve(this._pkgPath, "src/**/*.*")
|
|
79
|
+
], {
|
|
80
|
+
ignoreInitial: false
|
|
81
|
+
})
|
|
56
82
|
.onChange({
|
|
57
83
|
delay: 100
|
|
58
|
-
}, () => {
|
|
84
|
+
}, (changeInfos) => {
|
|
85
|
+
for (const builder of builders) {
|
|
86
|
+
builder.removeCache(changeInfos.map((item) => item.path));
|
|
87
|
+
}
|
|
59
88
|
fnQ.runLast(async () => {
|
|
60
89
|
this.emit("change");
|
|
61
|
-
this._debug(`
|
|
62
|
-
const
|
|
90
|
+
this._debug(`BUILD...`);
|
|
91
|
+
const buildResults = (await Promise.all(builders.map((builder) => builder.bundleAsync()))).mapMany();
|
|
92
|
+
this._debug("CHECK...");
|
|
93
|
+
const checkResult = await checker.buildAsync();
|
|
63
94
|
this._debug(`LINT...`);
|
|
64
|
-
const
|
|
95
|
+
const lintResults = await SdLinter.lintAsync(checkResult.affectedFilePaths, checker.program);
|
|
65
96
|
this._debug(`빌드 완료`);
|
|
66
97
|
this.emit("complete", {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
buildResults: [...watchCheckResult.results, ...watchLintResults]
|
|
98
|
+
affectedFilePaths: checkResult.affectedFilePaths,
|
|
99
|
+
buildResults: [...buildResults, ...checkResult.results, ...lintResults]
|
|
70
100
|
});
|
|
101
|
+
watcher.add(checker.program.getSourceFiles().map((item) => item.fileName));
|
|
71
102
|
});
|
|
72
103
|
});
|
|
73
|
-
if (this._pkgConf.server !== undefined) {
|
|
74
|
-
this._debug("GEN .config...");
|
|
75
|
-
const confDistPath = path.resolve(this._pkgPath, "../../packages", this._pkgConf.server, "dist/www", path.basename(this._pkgPath), ".config.json");
|
|
76
|
-
await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
|
|
77
|
-
}
|
|
78
|
-
this._debug(`빌드 완료`);
|
|
79
|
-
this.emit("complete", {
|
|
80
|
-
port: viteServerPort,
|
|
81
|
-
affectedFilePaths: checkResult.affectedFilePaths,
|
|
82
|
-
buildResults: [...checkResult.results, ...lintResults]
|
|
83
|
-
});
|
|
84
|
-
return viteServerPort;
|
|
85
|
-
}
|
|
86
|
-
async buildAsync() {
|
|
87
|
-
this._debug("dist 초기화...");
|
|
88
|
-
const cachePath = path.resolve(this._pkgPath, ".cache", "prod", ...this._builderKey !== "web" ? [this._builderKey] : []);
|
|
89
|
-
const distPath = path.resolve(this._pkgPath, "dist", ...this._builderKey !== "web" ? [this._builderKey] : []);
|
|
90
|
-
await FsUtil.removeAsync(cachePath);
|
|
91
|
-
await FsUtil.removeAsync(distPath);
|
|
92
|
-
this._debug("BUILD...");
|
|
93
|
-
const buildResults = [];
|
|
94
|
-
try {
|
|
95
|
-
await vite.build(this._getViteConfig({
|
|
96
|
-
dev: false,
|
|
97
|
-
pkgConf: this._pkgConf,
|
|
98
|
-
cachePath: cachePath,
|
|
99
|
-
distPath: distPath,
|
|
100
|
-
}));
|
|
101
|
-
}
|
|
102
|
-
catch (err) {
|
|
103
|
-
if ("errors" in err && err.errors instanceof Array) {
|
|
104
|
-
buildResults.push(...err.errors.map((item) => ({
|
|
105
|
-
filePath: item.location.file,
|
|
106
|
-
line: item.location.line,
|
|
107
|
-
char: item.location.column,
|
|
108
|
-
code: undefined,
|
|
109
|
-
severity: "error",
|
|
110
|
-
message: item.text
|
|
111
|
-
})));
|
|
112
|
-
}
|
|
113
|
-
if ("warnings" in err && err.warnings instanceof Array) {
|
|
114
|
-
buildResults.push(...err.warnings.map((item) => ({
|
|
115
|
-
filePath: item.location.file,
|
|
116
|
-
line: item.location.line,
|
|
117
|
-
char: item.location.column,
|
|
118
|
-
code: undefined,
|
|
119
|
-
severity: "warning",
|
|
120
|
-
message: item.text
|
|
121
|
-
})));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
this._debug("CHECK...");
|
|
125
|
-
const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, () => ({ emitJs: false }));
|
|
126
|
-
const checkResult = await sdTsProgram.buildAsync();
|
|
127
|
-
this._debug("LINT...");
|
|
128
|
-
const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram.getProgram());
|
|
129
|
-
if (this._pkgConf.server !== undefined) {
|
|
130
|
-
const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
|
|
131
|
-
this._debug("GEN .config...");
|
|
132
|
-
await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
|
|
133
|
-
}
|
|
134
|
-
if (this._builderKey === "electron") {
|
|
135
|
-
const electronSrcPath = path.resolve(this._pkgPath, ".cache/prod/electron/src");
|
|
136
|
-
const electronDistPath = path.resolve(this._pkgPath, ".cache/prod/electron/dist");
|
|
137
|
-
const pkgNpmConfig = (await FsUtil.readJsonAsync(path.resolve(this._pkgPath, `package.json`)));
|
|
138
|
-
this._debug("package.json 파일 쓰기...");
|
|
139
|
-
const externalPkgNames = this._pkgConf.builder.electron.reinstallDependencies ?? [];
|
|
140
|
-
await FsUtil.writeJsonAsync(path.resolve(electronSrcPath, `package.json`), {
|
|
141
|
-
name: pkgNpmConfig.name,
|
|
142
|
-
version: pkgNpmConfig.version,
|
|
143
|
-
description: pkgNpmConfig.description,
|
|
144
|
-
main: "electron-main.js",
|
|
145
|
-
...this._pkgConf.builder.electron.postInstallScript !== undefined ? {
|
|
146
|
-
scripts: {
|
|
147
|
-
"postinstall": this._pkgConf.builder.electron.postInstallScript
|
|
148
|
-
},
|
|
149
|
-
} : {},
|
|
150
|
-
dependencies: externalPkgNames.toObject((item) => item, (item) => pkgNpmConfig.dependencies[item] ?? "*")
|
|
151
|
-
});
|
|
152
|
-
this._debug("npm install...");
|
|
153
|
-
await SdProcess.spawnAsync(`npm install`, { cwd: electronSrcPath }, true);
|
|
154
|
-
for (const externalPkgName of externalPkgNames) {
|
|
155
|
-
if (FsUtil.exists(path.resolve(electronSrcPath, "node_modules", externalPkgName, "binding.gyp"))) {
|
|
156
|
-
this._debug(`electron rebuild (${externalPkgName})...`);
|
|
157
|
-
await SdProcess.spawnAsync(`electron-rebuild -m ./node_modules/${externalPkgName}`, { cwd: electronSrcPath }, true);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
await electronBuilder.build({
|
|
161
|
-
targets: electronBuilder.Platform.WINDOWS.createTarget(),
|
|
162
|
-
config: {
|
|
163
|
-
appId: this._pkgConf.builder.electron.appId,
|
|
164
|
-
productName: pkgNpmConfig.description,
|
|
165
|
-
// asar: false,
|
|
166
|
-
win: {
|
|
167
|
-
target: "nsis"
|
|
168
|
-
},
|
|
169
|
-
nsis: {},
|
|
170
|
-
directories: {
|
|
171
|
-
app: electronSrcPath,
|
|
172
|
-
output: electronDistPath
|
|
173
|
-
},
|
|
174
|
-
...this._pkgConf.builder.electron.installerIcon !== undefined ? {
|
|
175
|
-
icon: path.resolve(this._pkgPath, "src", this._pkgConf.builder.electron.installerIcon)
|
|
176
|
-
} : {},
|
|
177
|
-
removePackageScripts: false
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
await FsUtil.copyAsync(path.resolve(electronDistPath, `${pkgNpmConfig.description} Setup ${pkgNpmConfig.version}.exe`), path.resolve(distPath, `electron/${pkgNpmConfig.description}-latest.exe`));
|
|
181
|
-
await FsUtil.copyAsync(path.resolve(electronDistPath, `${pkgNpmConfig.description} Setup ${pkgNpmConfig.version}.exe`), path.resolve(distPath, `electron/updates/${pkgNpmConfig.version}.exe`));
|
|
182
|
-
}
|
|
183
|
-
this._debug(`빌드 완료`);
|
|
184
|
-
return {
|
|
185
|
-
affectedFilePaths: checkResult.affectedFilePaths,
|
|
186
|
-
buildResults: [...buildResults, ...checkResult.results, ...lintResults]
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
_getViteConfig(opt) {
|
|
190
|
-
const pkgNpmConf = FsUtil.readJson(path.resolve(this._pkgPath, "package.json"));
|
|
191
|
-
const basePath = this._builderKey === "electron" ? "" : (!opt.dev || this._pkgConf.server !== undefined) ? ("/" + path.basename(this._pkgPath) + "/") : "/";
|
|
192
|
-
const serverHost = this._pkgConf.builder?.[this._builderKey]?.devServerHost ?? "localhost";
|
|
193
|
-
const define = {
|
|
194
|
-
...opt.dev ? {
|
|
195
|
-
"import.meta.env.SD_SERVER_URL": JSON.stringify(`http://${serverHost}:${opt.port}` + basePath)
|
|
196
|
-
} : {},
|
|
197
|
-
"import.meta.env.SD_VERSION": JSON.stringify(pkgNpmConf.version),
|
|
198
|
-
...this._pkgConf.env
|
|
199
|
-
? Object.keys(this._pkgConf.env)
|
|
200
|
-
.toObject((key) => "import.meta.env." + key, (key) => JSON.stringify(this._pkgConf.env[key]))
|
|
201
|
-
: {},
|
|
202
|
-
...this._pkgConf.builder?.[this._builderKey]?.env
|
|
203
|
-
? Object.keys(this._pkgConf.builder[this._builderKey].env)
|
|
204
|
-
.toObject((key) => "import.meta.env." + key, (key) => JSON.stringify(this._pkgConf.builder[this._builderKey].env[key]))
|
|
205
|
-
: {}
|
|
206
|
-
};
|
|
207
|
-
return defineConfig({
|
|
208
|
-
mode: opt.dev ? "development" : "production",
|
|
209
|
-
root: path.resolve(this._pkgPath, "src"),
|
|
210
|
-
cacheDir: path.resolve(opt.cachePath, "vite"),
|
|
211
|
-
base: basePath,
|
|
212
|
-
assetsInclude: [
|
|
213
|
-
"**/*.xlsx",
|
|
214
|
-
"**/*.xls",
|
|
215
|
-
"**/*.docx",
|
|
216
|
-
"**/*.doc",
|
|
217
|
-
"**/*.pptx",
|
|
218
|
-
"**/*.ppt",
|
|
219
|
-
"**/*.woff",
|
|
220
|
-
"**/*.woff2",
|
|
221
|
-
"**/*.ttf",
|
|
222
|
-
"**/*.eot",
|
|
223
|
-
"**/*.otf",
|
|
224
|
-
"**/*.csv",
|
|
225
|
-
"**/*.zip",
|
|
226
|
-
"**/*.pfx",
|
|
227
|
-
"**/*.pkl"
|
|
228
|
-
],
|
|
229
|
-
define: define,
|
|
230
|
-
...opt.dev ? {
|
|
231
|
-
server: {
|
|
232
|
-
host: serverHost,
|
|
233
|
-
port: opt.port,
|
|
234
|
-
hmr: {
|
|
235
|
-
host: serverHost,
|
|
236
|
-
port: opt.port
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
} : {},
|
|
240
|
-
optimizeDeps: {
|
|
241
|
-
force: true
|
|
242
|
-
},
|
|
243
|
-
...!opt.dev ? {
|
|
244
|
-
build: {
|
|
245
|
-
outDir: this._builderKey === "electron" ? path.resolve(opt.cachePath, "src") : opt.distPath,
|
|
246
|
-
rollupOptions: {
|
|
247
|
-
output: {
|
|
248
|
-
entryFileNames: `assets/[name].js`,
|
|
249
|
-
chunkFileNames: `assets/[name].js`,
|
|
250
|
-
assetFileNames: `assets/[name].[ext]`
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
} : {},
|
|
255
|
-
plugins: [
|
|
256
|
-
SdCliViteReactSwcPlugin(),
|
|
257
|
-
SdCliViteLoggerPlugin({
|
|
258
|
-
logger: this._logger,
|
|
259
|
-
name: path.basename(this._pkgPath)
|
|
260
|
-
}),
|
|
261
|
-
vitePluginPaths(),
|
|
262
|
-
...opt.dev ? [
|
|
263
|
-
SdCliViteLazyImportPlugin()
|
|
264
|
-
] : [],
|
|
265
|
-
...opt.dev ? [
|
|
266
|
-
SdCliViteServeOptimizeExcludePlugin([
|
|
267
|
-
"@simplysm/*"
|
|
268
|
-
])
|
|
269
|
-
] : [],
|
|
270
|
-
...!opt.dev && this._builderKey === "web" ? [
|
|
271
|
-
VitePWA({
|
|
272
|
-
mode: "production",
|
|
273
|
-
base: `/${path.basename(this._pkgPath)}/`,
|
|
274
|
-
includeAssets: ["favicon.ico", "assets/icons/apple-touch-icon-180x180.png", "assets/icons/maskable-icon-512x512.png"],
|
|
275
|
-
registerType: 'autoUpdate',
|
|
276
|
-
manifest: FsUtil.readJson(path.resolve(this._pkgPath, "src/manifest.json"))
|
|
277
|
-
}),
|
|
278
|
-
] : [],
|
|
279
|
-
...this._builderKey === "web" ? [
|
|
280
|
-
SdCliViteNodeGlobalPlugin()
|
|
281
|
-
] : [],
|
|
282
|
-
...this._builderKey === "electron" ? [
|
|
283
|
-
SdCliViteElectronMainPlugin({
|
|
284
|
-
entry: path.resolve(this._pkgPath, "src/electron-main.ts"),
|
|
285
|
-
distPath: path.resolve(opt.cachePath, "src"),
|
|
286
|
-
cachePath: path.resolve(opt.cachePath, "electron-main")
|
|
287
|
-
}),
|
|
288
|
-
SdCliViteExternalPlugin({
|
|
289
|
-
target: "browser",
|
|
290
|
-
cachePath: path.resolve(opt.cachePath, "external"),
|
|
291
|
-
includes: opt.pkgConf.builder?.electron?.reinstallDependencies
|
|
292
|
-
})
|
|
293
|
-
] : [],
|
|
294
|
-
],
|
|
295
|
-
});
|
|
296
104
|
}
|
|
297
105
|
_debug(msg) {
|
|
298
106
|
this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
|