@simplysm/sd-cli 11.0.3 → 11.0.5
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 +1 -1
- package/dist/build-cluster.js.map +1 -1
- package/dist/build-tools/SdLinter.js +2 -2
- package/dist/build-tools/SdLinter.js.map +1 -1
- package/dist/build-tools/SdNgBundler.d.ts +23 -0
- package/dist/build-tools/SdNgBundler.js +331 -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 +4 -2
- package/dist/builders/SdCliClientBuilder.js +60 -297
- package/dist/builders/SdCliClientBuilder.js.map +1 -1
- package/dist/builders/SdCliServerBuilder.js +79 -216
- package/dist/builders/SdCliServerBuilder.js.map +1 -1
- package/dist/builders/SdCliTsLibBuilder.d.ts +0 -1
- package/dist/builders/SdCliTsLibBuilder.js +35 -33
- package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
- package/dist/commons.d.ts +7 -0
- package/dist/entry/SdCliProject.js +13 -10
- package/dist/entry/SdCliProject.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/server-worker.js +3 -0
- package/dist/server-worker.js.map +1 -1
- package/dist/utils/SdCliBuildResultUtil.d.ts +1 -1
- package/dist/utils/SdCliBuildResultUtil.js +4 -4
- package/dist/utils/SdCliBuildResultUtil.js.map +1 -1
- package/package.json +14 -12
- package/src/build-cluster.ts +1 -1
- package/src/build-tools/SdLinter.ts +2 -2
- package/src/build-tools/SdNgBundler.ts +404 -0
- package/src/build-tools/SdTsBundler.ts +106 -0
- package/src/build-tools/SdTsCompiler.ts +304 -0
- package/src/builders/SdCliClientBuilder.ts +75 -322
- package/src/builders/SdCliServerBuilder.ts +95 -243
- package/src/builders/SdCliTsLibBuilder.ts +39 -40
- package/src/commons.ts +6 -0
- package/src/entry/SdCliProject.ts +17 -12
- package/src/index.ts +3 -1
- package/src/server-worker.ts +3 -0
- package/src/utils/SdCliBuildResultUtil.ts +4 -4
- package/dist/build-tools/SdTsIncrementalBuilder.d.ts +0 -31
- package/dist/build-tools/SdTsIncrementalBuilder.js +0 -126
- package/dist/build-tools/SdTsIncrementalBuilder.js.map +0 -1
- package/src/build-tools/SdTsIncrementalBuilder.ts +0 -207
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import {EventEmitter} from "events";
|
|
2
|
-
import {FsUtil, Logger} from "@simplysm/sd-core-node";
|
|
3
|
-
import {
|
|
4
|
-
INpmConfig,
|
|
5
|
-
ISdCliBuilderResult,
|
|
6
|
-
ISdCliConfig,
|
|
7
|
-
ISdCliPackageBuildResult,
|
|
8
|
-
ISdCliServerPackageConfig
|
|
9
|
-
} from "../commons";
|
|
10
|
-
import esbuild from "esbuild";
|
|
2
|
+
import {FsUtil, Logger, SdFsWatcher} from "@simplysm/sd-core-node";
|
|
3
|
+
import {INpmConfig, ISdCliBuilderResult, ISdCliConfig, ISdCliServerPackageConfig} from "../commons";
|
|
11
4
|
import path from "path";
|
|
12
|
-
import {
|
|
5
|
+
import {SdTsCompiler} from "../build-tools/SdTsCompiler";
|
|
13
6
|
import {SdLinter} from "../build-tools/SdLinter";
|
|
14
|
-
import {ObjectUtil, StringUtil} from "@simplysm/sd-core-common";
|
|
15
|
-
import
|
|
7
|
+
import {FunctionQueue, ObjectUtil, StringUtil} from "@simplysm/sd-core-common";
|
|
8
|
+
import {SdTsBundler} from "../build-tools/SdTsBundler";
|
|
16
9
|
|
|
17
10
|
export class SdCliServerBuilder extends EventEmitter {
|
|
18
11
|
private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliServerBuilder"]);
|
|
@@ -33,145 +26,68 @@ export class SdCliServerBuilder extends EventEmitter {
|
|
|
33
26
|
}
|
|
34
27
|
|
|
35
28
|
public async watchAsync(): Promise<void> {
|
|
36
|
-
this.
|
|
37
|
-
const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, () => ({emitJs: false}));
|
|
29
|
+
const extModules = await this._getExternalModulesAsync();
|
|
38
30
|
|
|
39
31
|
this._debug("dist 초기화...");
|
|
40
32
|
await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
|
|
41
33
|
|
|
42
|
-
this.emit("change");
|
|
43
|
-
|
|
44
34
|
this._debug("GEN .config...");
|
|
45
35
|
const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
|
|
46
36
|
await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
|
|
47
37
|
|
|
48
|
-
this._debug(`BUILD
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
entryPoints: "files" in tsConfig ? tsConfig.files.map((relPath) => path.resolve(this._pkgPath, relPath)) : [
|
|
55
|
-
path.resolve(this._pkgPath, "src", "main.ts"),
|
|
38
|
+
this._debug(`BUILD 준비...`);
|
|
39
|
+
const builder = new SdTsBundler({
|
|
40
|
+
dev: false,
|
|
41
|
+
pkgPath: this._pkgPath,
|
|
42
|
+
entryPoints: [
|
|
43
|
+
path.resolve(this._pkgPath, "src/main.ts")
|
|
56
44
|
],
|
|
57
|
-
|
|
58
|
-
bundle: true,
|
|
59
|
-
sourcemap: true,
|
|
60
|
-
target: "node20",
|
|
61
|
-
mainFields: ["es2021", "es2020", "module", "main"],
|
|
62
|
-
conditions: ["es2021", "es2020", "es2015", "module"],
|
|
63
|
-
tsconfig: path.resolve(this._pkgPath, "tsconfig.json"),
|
|
64
|
-
write: true,
|
|
65
|
-
format: "esm",
|
|
66
|
-
resolveExtensions: [".js", ".mjs", ".cjs", ".jsx", ".ts", ".tsx"],
|
|
67
|
-
loader: {
|
|
68
|
-
".xlsx": "binary",
|
|
69
|
-
".xls": "binary",
|
|
70
|
-
".docx": "binary",
|
|
71
|
-
".doc": "binary",
|
|
72
|
-
".pptx": "binary",
|
|
73
|
-
".ppt": "binary",
|
|
74
|
-
".woff": "binary",
|
|
75
|
-
".woff2": "binary",
|
|
76
|
-
".ttf": "binary",
|
|
77
|
-
".eot": "binary",
|
|
78
|
-
".otf": "binary",
|
|
79
|
-
".csv": "binary",
|
|
80
|
-
".zip": "binary",
|
|
81
|
-
".pfx": "binary",
|
|
82
|
-
".pkl": "binary",
|
|
83
|
-
},
|
|
84
|
-
platform: "node",
|
|
85
|
-
logLevel: "silent",
|
|
86
|
-
outdir: path.resolve(this._pkgPath, "dist"),
|
|
87
|
-
external: extModules.map((item) => item.name),
|
|
88
|
-
banner: {
|
|
89
|
-
js: `
|
|
90
|
-
import __path__ from 'path';
|
|
91
|
-
import { fileURLToPath as __fileURLToPath__ } from 'url';
|
|
92
|
-
import { createRequire as __createRequire__ } from 'module';
|
|
93
|
-
|
|
94
|
-
const require = __createRequire__(import.meta.url);
|
|
95
|
-
const __filename = __fileURLToPath__(import.meta.url);
|
|
96
|
-
const __dirname = __path__.dirname(__filename);`.trim()
|
|
97
|
-
},
|
|
98
|
-
plugins: [
|
|
99
|
-
esbuildPluginTsc(),
|
|
100
|
-
{
|
|
101
|
-
name: "sd-additional",
|
|
102
|
-
setup: ({onEnd, onStart}) => {
|
|
103
|
-
onStart(() => {
|
|
104
|
-
if (!isFirst) {
|
|
105
|
-
this.emit("change");
|
|
106
|
-
this._debug(`BUILD...`);
|
|
107
|
-
}
|
|
108
|
-
isFirst = false;
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
onEnd(async (result) => {
|
|
112
|
-
try {
|
|
113
|
-
const buildResults = [
|
|
114
|
-
...result.warnings.map((warn) => ({
|
|
115
|
-
filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
|
|
116
|
-
line: warn.location?.line,
|
|
117
|
-
char: warn.location?.column,
|
|
118
|
-
code: undefined,
|
|
119
|
-
severity: "warning" as const,
|
|
120
|
-
message: warn.text
|
|
121
|
-
})),
|
|
122
|
-
...result.errors.map((err) => ({
|
|
123
|
-
filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
|
|
124
|
-
line: err.location?.line,
|
|
125
|
-
char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
|
|
126
|
-
code: undefined,
|
|
127
|
-
severity: "error" as const,
|
|
128
|
-
message: err.text
|
|
129
|
-
}))
|
|
130
|
-
];
|
|
131
|
-
|
|
132
|
-
this._debug("CHECK...");
|
|
133
|
-
const checkResult = await sdTsProgram.buildAsync();
|
|
134
|
-
|
|
135
|
-
this._debug("LINT...");
|
|
136
|
-
const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
|
|
137
|
-
|
|
138
|
-
this._debug(`빌드 완료`);
|
|
139
|
-
this.emit("complete", {
|
|
140
|
-
affectedFilePaths: checkResult.affectedFilePaths,
|
|
141
|
-
buildResults: [...buildResults, ...checkResult.results, ...lintResults]
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
catch (err) {
|
|
145
|
-
this._logger.error(err);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
name: "jsdom-patch",
|
|
152
|
-
setup: ({onLoad}) => {
|
|
153
|
-
onLoad({filter: /XMLHttpRequest-impl\.js$/}, async (args) => {
|
|
154
|
-
let contents = await FsUtil.readFileAsync(args.path);
|
|
155
|
-
contents = contents.replace(
|
|
156
|
-
'./xhr-sync-worker.js',
|
|
157
|
-
'jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js'
|
|
158
|
-
);
|
|
159
|
-
return {contents};
|
|
160
|
-
});
|
|
161
|
-
},
|
|
162
|
-
}
|
|
163
|
-
]
|
|
45
|
+
external: extModules.map((item) => item.name)
|
|
164
46
|
});
|
|
165
|
-
|
|
47
|
+
|
|
48
|
+
const checker = new SdTsCompiler({
|
|
49
|
+
pkgPath: this._pkgPath,
|
|
50
|
+
emit: false,
|
|
51
|
+
emitDts: false,
|
|
52
|
+
globalStyle: false
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
this._debug("WATCH...");
|
|
56
|
+
const fnQ = new FunctionQueue();
|
|
57
|
+
SdFsWatcher
|
|
58
|
+
.watch([
|
|
59
|
+
path.resolve(this._pkgPath, "src/**/*.*")
|
|
60
|
+
], {
|
|
61
|
+
ignoreInitial: false
|
|
62
|
+
})
|
|
63
|
+
.onChange({
|
|
64
|
+
delay: 100
|
|
65
|
+
}, () => {
|
|
66
|
+
fnQ.runLast(async () => {
|
|
67
|
+
this.emit("change");
|
|
68
|
+
|
|
69
|
+
this._debug(`BUILD...`);
|
|
70
|
+
const buildResults = await builder.bundleAsync();
|
|
71
|
+
|
|
72
|
+
this._debug("CHECK...");
|
|
73
|
+
const checkResult = await checker.buildAsync();
|
|
74
|
+
|
|
75
|
+
this._debug(`LINT...`);
|
|
76
|
+
const lintResults = await SdLinter.lintAsync(checkResult.affectedFilePaths, checker.program);
|
|
77
|
+
|
|
78
|
+
this._debug(`빌드 완료`);
|
|
79
|
+
this.emit("complete", {
|
|
80
|
+
affectedFilePaths: checkResult.affectedFilePaths,
|
|
81
|
+
buildResults: [...buildResults, ...checkResult.results, ...lintResults]
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
166
85
|
}
|
|
167
86
|
|
|
168
87
|
public async buildAsync(): Promise<ISdCliBuilderResult> {
|
|
169
88
|
const npmConfig = (await FsUtil.readJsonAsync(path.resolve(this._pkgPath, "package.json"))) as INpmConfig;
|
|
170
89
|
const extModules = await this._getExternalModulesAsync();
|
|
171
90
|
|
|
172
|
-
this._debug("빌드 준비...");
|
|
173
|
-
const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, () => ({emitJs: false}));
|
|
174
|
-
|
|
175
91
|
this._debug("dist 초기화...");
|
|
176
92
|
await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
|
|
177
93
|
|
|
@@ -179,6 +95,29 @@ const __dirname = __path__.dirname(__filename);`.trim()
|
|
|
179
95
|
const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
|
|
180
96
|
await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
|
|
181
97
|
|
|
98
|
+
this._debug("GEN package.json...");
|
|
99
|
+
{
|
|
100
|
+
const deps = extModules.filter((item) => item.exists).map((item) => item.name);
|
|
101
|
+
|
|
102
|
+
const distNpmConfig = ObjectUtil.clone(npmConfig);
|
|
103
|
+
distNpmConfig.dependencies = {};
|
|
104
|
+
for (const dep of deps) {
|
|
105
|
+
distNpmConfig.dependencies[dep] = "*";
|
|
106
|
+
}
|
|
107
|
+
delete distNpmConfig.optionalDependencies;
|
|
108
|
+
delete distNpmConfig.devDependencies;
|
|
109
|
+
delete distNpmConfig.peerDependencies;
|
|
110
|
+
|
|
111
|
+
if (this._pkgConf.pm2 && !this._pkgConf.pm2.noStartScript) {
|
|
112
|
+
distNpmConfig.scripts = {"start": "pm2 start pm2.json"};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
await FsUtil.writeFileAsync(
|
|
116
|
+
path.resolve(this._pkgPath, "dist/package.json"),
|
|
117
|
+
JSON.stringify(distNpmConfig, undefined, 2)
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
182
121
|
if (this._pkgConf.pm2) {
|
|
183
122
|
this._debug("GEN pm2.json...");
|
|
184
123
|
|
|
@@ -209,8 +148,9 @@ const __dirname = __path__.dirname(__filename);`.trim()
|
|
|
209
148
|
);
|
|
210
149
|
}
|
|
211
150
|
|
|
212
|
-
this._debug("GEN web.config...");
|
|
213
151
|
if (this._pkgConf.iis) {
|
|
152
|
+
this._debug("GEN web.config...");
|
|
153
|
+
|
|
214
154
|
const iisDistPath = path.resolve(this._pkgPath, "dist/web.config");
|
|
215
155
|
const serverExeFilePath = this._pkgConf.iis.nodeExeFilePath ?? "C:\\Program Files\\nodejs\\node.exe";
|
|
216
156
|
await FsUtil.writeFileAsync(iisDistPath, `
|
|
@@ -237,119 +177,31 @@ const __dirname = __path__.dirname(__filename);`.trim()
|
|
|
237
177
|
`.trim());
|
|
238
178
|
}
|
|
239
179
|
|
|
240
|
-
this._debug(
|
|
241
|
-
{
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
for (const dep of deps) {
|
|
247
|
-
distNpmConfig.dependencies[dep] = "*";
|
|
248
|
-
}
|
|
249
|
-
delete distNpmConfig.optionalDependencies;
|
|
250
|
-
delete distNpmConfig.devDependencies;
|
|
251
|
-
delete distNpmConfig.peerDependencies;
|
|
252
|
-
|
|
253
|
-
if (this._pkgConf.pm2 && !this._pkgConf.pm2.noStartScript) {
|
|
254
|
-
distNpmConfig.scripts = {"start": "pm2 start pm2.json"};
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
await FsUtil.writeFileAsync(
|
|
258
|
-
path.resolve(this._pkgPath, "dist/package.json"),
|
|
259
|
-
JSON.stringify(distNpmConfig, undefined, 2)
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
this._debug("BUILD...");
|
|
264
|
-
const tsConfig = await FsUtil.readJsonAsync(path.resolve(this._pkgPath, "tsconfig.json"));
|
|
265
|
-
const esbuildResult = await esbuild.build({
|
|
266
|
-
entryPoints: "files" in tsConfig ? tsConfig.files.map((relPath) => path.resolve(this._pkgPath, relPath)) : [
|
|
267
|
-
path.resolve(this._pkgPath, "src", "main.ts"),
|
|
180
|
+
this._debug(`BUILD 준비...`);
|
|
181
|
+
const builder = new SdTsBundler({
|
|
182
|
+
dev: true,
|
|
183
|
+
pkgPath: this._pkgPath,
|
|
184
|
+
entryPoints: [
|
|
185
|
+
path.resolve(this._pkgPath, "src/main.ts")
|
|
268
186
|
],
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
resolveExtensions: [".js", ".mjs", ".cjs", ".jsx", ".ts", ".tsx"],
|
|
278
|
-
loader: {
|
|
279
|
-
".xlsx": "binary",
|
|
280
|
-
".xls": "binary",
|
|
281
|
-
".docx": "binary",
|
|
282
|
-
".doc": "binary",
|
|
283
|
-
".pptx": "binary",
|
|
284
|
-
".ppt": "binary",
|
|
285
|
-
".woff": "binary",
|
|
286
|
-
".woff2": "binary",
|
|
287
|
-
".ttf": "binary",
|
|
288
|
-
".eot": "binary",
|
|
289
|
-
".otf": "binary",
|
|
290
|
-
".csv": "binary",
|
|
291
|
-
".zip": "binary",
|
|
292
|
-
".pfx": "binary",
|
|
293
|
-
".pkl": "binary",
|
|
294
|
-
},
|
|
295
|
-
platform: "node",
|
|
296
|
-
logLevel: "silent",
|
|
297
|
-
outdir: path.resolve(this._pkgPath, "dist"),
|
|
298
|
-
external: extModules.map((item) => item.name),
|
|
299
|
-
banner: {
|
|
300
|
-
js: `
|
|
301
|
-
import __path__ from 'path';
|
|
302
|
-
import { fileURLToPath as __fileURLToPath__ } from 'url';
|
|
303
|
-
import { createRequire as __createRequire__ } from 'module';
|
|
304
|
-
|
|
305
|
-
const require = __createRequire__(import.meta.url);
|
|
306
|
-
const __filename = __fileURLToPath__(import.meta.url);
|
|
307
|
-
const __dirname = __path__.dirname(__filename);`.trim()
|
|
308
|
-
},
|
|
309
|
-
plugins: [
|
|
310
|
-
esbuildPluginTsc(),
|
|
311
|
-
{
|
|
312
|
-
name: "jsdom-patch",
|
|
313
|
-
setup: ({onLoad}) => {
|
|
314
|
-
onLoad({filter: /XMLHttpRequest-impl\.js$/}, async (args) => {
|
|
315
|
-
let contents = await FsUtil.readFileAsync(args.path);
|
|
316
|
-
contents = contents.replace(
|
|
317
|
-
'./xhr-sync-worker.js',
|
|
318
|
-
'jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js'
|
|
319
|
-
);
|
|
320
|
-
return {contents};
|
|
321
|
-
});
|
|
322
|
-
},
|
|
323
|
-
}
|
|
324
|
-
]
|
|
187
|
+
external: extModules.map((item) => item.name)
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const checker = new SdTsCompiler({
|
|
191
|
+
pkgPath: this._pkgPath,
|
|
192
|
+
emit: false,
|
|
193
|
+
emitDts: false,
|
|
194
|
+
globalStyle: false
|
|
325
195
|
});
|
|
326
196
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
|
|
330
|
-
line: warn.location?.line,
|
|
331
|
-
char: warn.location?.column,
|
|
332
|
-
code: undefined,
|
|
333
|
-
severity: "warning" as const,
|
|
334
|
-
message: warn.text,
|
|
335
|
-
type: "build" as const
|
|
336
|
-
})),
|
|
337
|
-
...esbuildResult.errors.map((err) => ({
|
|
338
|
-
filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
|
|
339
|
-
line: err.location?.line,
|
|
340
|
-
char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
|
|
341
|
-
code: undefined,
|
|
342
|
-
severity: "warning" as const,
|
|
343
|
-
message: err.text,
|
|
344
|
-
type: "build" as const
|
|
345
|
-
}))
|
|
346
|
-
];
|
|
197
|
+
this._debug(`BUILD...`);
|
|
198
|
+
const buildResults = await builder.bundleAsync();
|
|
347
199
|
|
|
348
200
|
this._debug("CHECK...");
|
|
349
|
-
const checkResult = await
|
|
201
|
+
const checkResult = await checker.buildAsync();
|
|
350
202
|
|
|
351
|
-
this._debug(
|
|
352
|
-
const lintResults =
|
|
203
|
+
this._debug(`LINT...`);
|
|
204
|
+
const lintResults = await SdLinter.lintAsync(checkResult.affectedFilePaths, checker.program);
|
|
353
205
|
|
|
354
206
|
this._debug(`빌드 완료`);
|
|
355
207
|
return {
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import {FsUtil, Logger, SdFsWatcher} from "@simplysm/sd-core-node";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import {ISdCliBuilderResult, ISdCliConfig
|
|
3
|
+
import {ISdCliBuilderResult, ISdCliConfig} from "../commons";
|
|
4
4
|
import {EventEmitter} from "events";
|
|
5
|
-
import {
|
|
6
|
-
import {SdTsIncrementalBuilder} from "../build-tools/SdTsIncrementalBuilder";
|
|
5
|
+
import {SdTsCompiler} from "../build-tools/SdTsCompiler";
|
|
7
6
|
import {SdLinter} from "../build-tools/SdLinter";
|
|
7
|
+
import {FunctionQueue} from "@simplysm/sd-core-common";
|
|
8
8
|
|
|
9
9
|
export class SdCliTsLibBuilder extends EventEmitter {
|
|
10
10
|
private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliTsLibBuilder"]);
|
|
11
|
-
private readonly _pkgConf: ISdCliLibPackageConfig;
|
|
12
11
|
|
|
13
12
|
public constructor(private readonly _projConf: ISdCliConfig,
|
|
14
13
|
private readonly _pkgPath: string,
|
|
15
14
|
private readonly _withLint: boolean) {
|
|
16
15
|
super();
|
|
17
|
-
this._pkgConf = this._projConf.packages[path.basename(_pkgPath)] as ISdCliLibPackageConfig;
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
public override on(event: "change", listener: () => void): this;
|
|
@@ -25,70 +23,71 @@ export class SdCliTsLibBuilder extends EventEmitter {
|
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
public async buildAsync(): Promise<ISdCliBuilderResult> {
|
|
28
|
-
this._debug("빌드 준비...");
|
|
29
|
-
const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, () => ({emitJs: true}));
|
|
30
|
-
|
|
31
26
|
this._debug("dist 초기화...");
|
|
32
27
|
await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
|
|
33
28
|
|
|
34
|
-
this._debug(
|
|
35
|
-
const
|
|
29
|
+
this._debug(`BUILD 준비...`);
|
|
30
|
+
const builder = new SdTsCompiler({
|
|
31
|
+
pkgPath: this._pkgPath,
|
|
32
|
+
emit: true,
|
|
33
|
+
emitDts: true,
|
|
34
|
+
globalStyle: true
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
this._debug(`BUILD & CHECK...`);
|
|
38
|
+
const checkResult = await builder.buildAsync();
|
|
36
39
|
|
|
37
40
|
this._debug("LINT...");
|
|
38
|
-
const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(
|
|
41
|
+
const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(checkResult.affectedFilePaths, builder.program);
|
|
39
42
|
|
|
40
43
|
this._debug(`빌드 완료`);
|
|
41
44
|
return {
|
|
42
|
-
affectedFilePaths:
|
|
43
|
-
buildResults: [...
|
|
45
|
+
affectedFilePaths: checkResult.affectedFilePaths,
|
|
46
|
+
buildResults: [...checkResult.results, ...lintResults]
|
|
44
47
|
};
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
public async watchAsync(): Promise<void> {
|
|
48
|
-
this._debug("빌드 준비...");
|
|
49
|
-
const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, () => ({emitJs: true}));
|
|
50
|
-
|
|
51
51
|
this._debug("dist 초기화...");
|
|
52
52
|
await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
|
|
53
53
|
|
|
54
|
-
this.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(buildResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
|
|
61
|
-
|
|
62
|
-
this._debug(`빌드 완료`);
|
|
63
|
-
this.emit("complete", {
|
|
64
|
-
affectedFilePaths: buildResult.affectedFilePaths,
|
|
65
|
-
buildResults: [...buildResult.results, ...lintResults]
|
|
54
|
+
this._debug(`BUILD 준비...`);
|
|
55
|
+
const builder = new SdTsCompiler({
|
|
56
|
+
pkgPath: this._pkgPath,
|
|
57
|
+
emit: true,
|
|
58
|
+
emitDts: true,
|
|
59
|
+
globalStyle: true
|
|
66
60
|
});
|
|
67
61
|
|
|
68
62
|
this._debug("WATCH...");
|
|
69
63
|
const fnQ = new FunctionQueue();
|
|
70
|
-
SdFsWatcher
|
|
64
|
+
const watcher = SdFsWatcher
|
|
71
65
|
.watch([
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
66
|
+
path.resolve(this._pkgPath, "src/**/*.*")
|
|
67
|
+
], {
|
|
68
|
+
ignoreInitial: false
|
|
69
|
+
})
|
|
75
70
|
.onChange({
|
|
76
|
-
delay: 100
|
|
77
|
-
}, () => {
|
|
71
|
+
delay: 100,
|
|
72
|
+
}, (changeInfos) => {
|
|
73
|
+
builder.markChanges(changeInfos.map((item) => item.path));
|
|
74
|
+
|
|
78
75
|
fnQ.runLast(async () => {
|
|
79
76
|
this.emit("change");
|
|
80
77
|
|
|
81
|
-
this._debug(`BUILD...`);
|
|
82
|
-
const
|
|
78
|
+
this._debug(`CHECK & BUILD...`);
|
|
79
|
+
const checkResult = await builder.buildAsync();
|
|
83
80
|
|
|
84
|
-
this._debug(
|
|
85
|
-
const
|
|
81
|
+
this._debug("LINT...");
|
|
82
|
+
const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(checkResult.affectedFilePaths, builder.program);
|
|
86
83
|
|
|
87
84
|
this._debug(`빌드 완료`);
|
|
88
85
|
this.emit("complete", {
|
|
89
|
-
affectedFilePaths:
|
|
90
|
-
buildResults: [...
|
|
86
|
+
affectedFilePaths: checkResult.affectedFilePaths,
|
|
87
|
+
buildResults: [...checkResult.results, ...lintResults]
|
|
91
88
|
});
|
|
89
|
+
|
|
90
|
+
watcher.add(builder.program.getSourceFiles().map((item) => item.fileName).distinct());
|
|
92
91
|
});
|
|
93
92
|
});
|
|
94
93
|
}
|
package/src/commons.ts
CHANGED
|
@@ -17,6 +17,12 @@ export interface INpmConfig {
|
|
|
17
17
|
scripts?: Record<string, string>;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
export interface ITsConfig {
|
|
21
|
+
files?: string[],
|
|
22
|
+
compilerOptions: { lib: string[] };
|
|
23
|
+
angularCompilerOptions?: {};
|
|
24
|
+
}
|
|
25
|
+
|
|
20
26
|
export interface ISdCliBuildClusterReqMessage {
|
|
21
27
|
cmd: "watch" | "build";
|
|
22
28
|
projConf: ISdCliConfig;
|
|
@@ -79,8 +79,8 @@ export class SdCliProject {
|
|
|
79
79
|
hasChanges: boolean;
|
|
80
80
|
|
|
81
81
|
//client
|
|
82
|
-
pathProxy: Record<string, number | undefined>; // persist
|
|
83
|
-
changeFilePaths: string[];
|
|
82
|
+
pathProxy: Record<string, string | number | undefined>; // persist
|
|
83
|
+
// changeFilePaths: string[];
|
|
84
84
|
}>();
|
|
85
85
|
cluster.on("message", (message: ISdCliBuildClusterResMessage) => {
|
|
86
86
|
if (message.type === "change") {
|
|
@@ -106,7 +106,7 @@ export class SdCliProject {
|
|
|
106
106
|
const serverInfo = serverInfoMap.getOrCreate(pkgName, {
|
|
107
107
|
hasChanges: false,
|
|
108
108
|
pathProxy: {},
|
|
109
|
-
changeFilePaths: []
|
|
109
|
+
// changeFilePaths: []
|
|
110
110
|
});
|
|
111
111
|
serverInfo.pkgPath = message.req.pkgPath;
|
|
112
112
|
serverInfo.hasChanges = true;
|
|
@@ -119,19 +119,24 @@ export class SdCliProject {
|
|
|
119
119
|
const serverInfo = serverInfoMap.getOrCreate(pkgConf.server, {
|
|
120
120
|
hasChanges: false,
|
|
121
121
|
pathProxy: {},
|
|
122
|
-
changeFilePaths: []
|
|
122
|
+
// changeFilePaths: []
|
|
123
123
|
});
|
|
124
|
-
serverInfo.pathProxy[pkgName] = message.
|
|
125
|
-
|
|
124
|
+
serverInfo.pathProxy[pkgName] = path.resolve(message.req.pkgPath, "dist");
|
|
125
|
+
//message.result!.port;
|
|
126
|
+
// serverInfo.changeFilePaths.push(...message.result!.affectedFilePaths);
|
|
127
|
+
|
|
128
|
+
serverInfo.worker?.send({type: "broadcastReload"});
|
|
126
129
|
}
|
|
127
130
|
else {
|
|
128
131
|
const serverInfo = serverInfoMap.getOrCreate(pkgName, {
|
|
129
132
|
hasChanges: false,
|
|
130
133
|
pathProxy: {},
|
|
131
|
-
changeFilePaths: []
|
|
134
|
+
// changeFilePaths: []
|
|
132
135
|
});
|
|
133
136
|
serverInfo.port = message.result!.port;
|
|
134
|
-
serverInfo.changeFilePaths.push(...message.result!.affectedFilePaths);
|
|
137
|
+
// serverInfo.changeFilePaths.push(...message.result!.affectedFilePaths);
|
|
138
|
+
|
|
139
|
+
serverInfo.worker?.send({type: "broadcastReload"});
|
|
135
140
|
}
|
|
136
141
|
}
|
|
137
142
|
|
|
@@ -471,10 +476,10 @@ export class SdCliProject {
|
|
|
471
476
|
}
|
|
472
477
|
|
|
473
478
|
private static _logging(buildResults: ISdCliPackageBuildResult[], logger: Logger): void {
|
|
474
|
-
const messages = buildResults.filter((item) => item.severity === "message");
|
|
475
|
-
const suggestions = buildResults.filter((item) => item.severity === "suggestion");
|
|
476
|
-
const warnings = buildResults.filter((item) => item.severity === "warning");
|
|
477
|
-
const errors = buildResults.filter((item) => item.severity === "error");
|
|
479
|
+
const messages = buildResults.filter((item) => item.severity === "message").distinct();
|
|
480
|
+
const suggestions = buildResults.filter((item) => item.severity === "suggestion").distinct();
|
|
481
|
+
const warnings = buildResults.filter((item) => item.severity === "warning").distinct();
|
|
482
|
+
const errors = buildResults.filter((item) => item.severity === "error").distinct();
|
|
478
483
|
|
|
479
484
|
if (messages.length > 0) {
|
|
480
485
|
logger.log("\n" + messages.map((item) => SdCliBuildResultUtil.getMessage(item)).join("\n"));
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from "./build-tools/SdCliIndexFileGenerator";
|
|
2
2
|
export * from "./build-tools/SdLinter";
|
|
3
|
-
export * from "./build-tools/
|
|
3
|
+
export * from "./build-tools/SdNgBundler";
|
|
4
|
+
export * from "./build-tools/SdTsBundler";
|
|
5
|
+
export * from "./build-tools/SdTsCompiler";
|
|
4
6
|
export * from "./builders/SdCliClientBuilder";
|
|
5
7
|
export * from "./builders/SdCliJsLibLinter";
|
|
6
8
|
export * from "./builders/SdCliServerBuilder";
|
package/src/server-worker.ts
CHANGED
|
@@ -4,7 +4,7 @@ import path from "path";
|
|
|
4
4
|
import {ISdCliPackageBuildResult} from "../commons";
|
|
5
5
|
|
|
6
6
|
export class SdCliBuildResultUtil {
|
|
7
|
-
public static convertFromTsDiag(diag: ts.Diagnostic): ISdCliPackageBuildResult {
|
|
7
|
+
public static convertFromTsDiag(diag: ts.Diagnostic, type: "build" | "check"): ISdCliPackageBuildResult {
|
|
8
8
|
const severity = diag.category === ts.DiagnosticCategory.Error ? "error" as const
|
|
9
9
|
: diag.category === ts.DiagnosticCategory.Warning ? "warning" as const
|
|
10
10
|
: diag.category === ts.DiagnosticCategory.Suggestion ? "suggestion" as const
|
|
@@ -34,9 +34,9 @@ export class SdCliBuildResultUtil {
|
|
|
34
34
|
if (result.filePath !== undefined) {
|
|
35
35
|
str += `${result.filePath}(${result.line ?? 0}, ${result.char ?? 0}): `;
|
|
36
36
|
}
|
|
37
|
-
if (result.code !== undefined) {
|
|
38
|
-
|
|
39
|
-
}
|
|
37
|
+
// if (result.code !== undefined) {
|
|
38
|
+
// str += `${result.code}: `;
|
|
39
|
+
// }
|
|
40
40
|
str += `(${result.type}) ${result.severity} ${result.message}`;
|
|
41
41
|
|
|
42
42
|
return str;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { ISdCliPackageBuildResult } from "../commons";
|
|
3
|
-
interface IOptTransform<T> {
|
|
4
|
-
fn: (_: ts.Program, arg: T) => ts.TransformerFactory<ts.SourceFile>;
|
|
5
|
-
args: T;
|
|
6
|
-
}
|
|
7
|
-
export declare class SdTsIncrementalBuilder {
|
|
8
|
-
private readonly _pkgPath;
|
|
9
|
-
private readonly _compilerOptions;
|
|
10
|
-
private readonly _host;
|
|
11
|
-
private readonly _opt;
|
|
12
|
-
builderProgram?: ts.SemanticDiagnosticsBuilderProgram;
|
|
13
|
-
private _program?;
|
|
14
|
-
private _ngProgram?;
|
|
15
|
-
private readonly _writeFileCache;
|
|
16
|
-
constructor(_pkgPath: string, _compilerOptions: ts.CompilerOptions, _host: ts.CompilerHost, _opt: {
|
|
17
|
-
emitJs: boolean | string[];
|
|
18
|
-
compilerOptions?: ts.CompilerOptions;
|
|
19
|
-
transforms?: IOptTransform<any>[];
|
|
20
|
-
});
|
|
21
|
-
static createAsync(pkgPath: string, optFn: (compilerOptions: ts.CompilerOptions) => {
|
|
22
|
-
emitJs: boolean | string[];
|
|
23
|
-
compilerOptions?: ts.CompilerOptions;
|
|
24
|
-
transforms?: IOptTransform<any>[];
|
|
25
|
-
}): Promise<SdTsIncrementalBuilder>;
|
|
26
|
-
buildAsync(): Promise<{
|
|
27
|
-
affectedFilePaths: string[];
|
|
28
|
-
results: ISdCliPackageBuildResult[];
|
|
29
|
-
}>;
|
|
30
|
-
}
|
|
31
|
-
export {};
|