@simplysm/sd-cli 7.3.1 → 10.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/.eslintrc.cjs +18 -0
- package/dist/build-cluster.js +75 -0
- package/dist/build-cluster.js.map +1 -0
- package/dist/builders/SdCliJsLibLinter.d.ts +18 -0
- package/dist/builders/SdCliJsLibLinter.js +69 -0
- package/dist/builders/SdCliJsLibLinter.js.map +1 -0
- package/dist/builders/SdCliTsLibBuilder.d.ts +20 -0
- package/dist/builders/SdCliTsLibBuilder.js +205 -0
- package/dist/builders/SdCliTsLibBuilder.js.map +1 -0
- package/dist/commons.d.ts +3 -117
- package/dist/commons.js +2 -0
- package/dist/commons.js.map +1 -0
- package/dist/entry/SdCliProject.d.ts +28 -0
- package/dist/entry/SdCliProject.js +269 -0
- package/dist/entry/SdCliProject.js.map +1 -0
- package/dist/sd-cli.js +118 -0
- package/dist/sd-cli.js.map +1 -0
- package/dist/utils/SdCliBuildResultUtil.d.ts +1 -4
- package/dist/utils/SdCliBuildResultUtil.js +37 -0
- package/dist/utils/SdCliBuildResultUtil.js.map +1 -0
- package/dist/utils/SdCliConfigUtil.js +69 -0
- package/dist/utils/SdCliConfigUtil.js.map +1 -0
- package/package.json +10 -59
- package/src/build-cluster.ts +82 -0
- package/src/builders/SdCliJsLibLinter.ts +84 -0
- package/src/builders/SdCliTsLibBuilder.ts +265 -0
- package/src/commons.ts +3 -123
- package/src/entry/SdCliProject.ts +351 -0
- package/src/sd-cli.ts +135 -0
- package/src/utils/SdCliBuildResultUtil.ts +5 -38
- package/tsconfig.json +18 -0
- package/README.md +0 -105
- package/assets/client-files/assets/icons/icon-128x128.png +0 -0
- package/assets/client-files/assets/icons/icon-144x144.png +0 -0
- package/assets/client-files/assets/icons/icon-152x152.png +0 -0
- package/assets/client-files/assets/icons/icon-192x192.png +0 -0
- package/assets/client-files/assets/icons/icon-384x384.png +0 -0
- package/assets/client-files/assets/icons/icon-512x512.png +0 -0
- package/assets/client-files/assets/icons/icon-72x72.png +0 -0
- package/assets/client-files/assets/icons/icon-96x96.png +0 -0
- package/assets/client-files/favicon.ico +0 -0
- package/dist/SdCliBuildResultError.d.ts +0 -5
- package/dist/SdCliBuildResultError.mjs +0 -8
- package/dist/bin/sd-cli.d.ts +0 -2
- package/dist/bin/sd-cli.mjs +0 -410
- package/dist/build-tool/SdCliCacheCompilerHost.d.ts +0 -10
- package/dist/build-tool/SdCliCacheCompilerHost.mjs +0 -51
- package/dist/build-tool/SdCliCordova.d.ts +0 -16
- package/dist/build-tool/SdCliCordova.mjs +0 -212
- package/dist/build-tool/SdCliElectron.d.ts +0 -9
- package/dist/build-tool/SdCliElectron.mjs +0 -71
- package/dist/build-tool/SdCliGithubApi.d.ts +0 -13
- package/dist/build-tool/SdCliGithubApi.mjs +0 -92
- package/dist/build-tool/SdCliIndexFileGenerator.d.ts +0 -13
- package/dist/build-tool/SdCliIndexFileGenerator.mjs +0 -62
- package/dist/build-tool/SdCliNgCacheCompilerHost.d.ts +0 -12
- package/dist/build-tool/SdCliNgCacheCompilerHost.mjs +0 -43
- package/dist/build-tool/SdCliPackageLinter.d.ts +0 -8
- package/dist/build-tool/SdCliPackageLinter.mjs +0 -62
- package/dist/builder/SdCliClientBuilder.d.ts +0 -26
- package/dist/builder/SdCliClientBuilder.mjs +0 -761
- package/dist/builder/SdCliJsLibBuilder.d.ts +0 -14
- package/dist/builder/SdCliJsLibBuilder.mjs +0 -54
- package/dist/builder/SdCliServerBuilder.d.ts +0 -28
- package/dist/builder/SdCliServerBuilder.mjs +0 -482
- package/dist/builder/SdCliTsLibBuilder.d.ts +0 -35
- package/dist/builder/SdCliTsLibBuilder.mjs +0 -317
- package/dist/commons.mjs +0 -2
- package/dist/entry-points/SdCliFileCrypto.d.ts +0 -7
- package/dist/entry-points/SdCliFileCrypto.mjs +0 -72
- package/dist/entry-points/SdCliLocalUpdate.d.ts +0 -13
- package/dist/entry-points/SdCliLocalUpdate.mjs +0 -100
- package/dist/entry-points/SdCliPrepare.d.ts +0 -5
- package/dist/entry-points/SdCliPrepare.mjs +0 -86
- package/dist/entry-points/SdCliProject.d.ts +0 -34
- package/dist/entry-points/SdCliProject.mjs +0 -416
- package/dist/entry-points/SdCliProjectGenerator.d.ts +0 -44
- package/dist/entry-points/SdCliProjectGenerator.mjs +0 -326
- package/dist/entry-points/file/base/fc_package_eslintrc.d.ts +0 -3
- package/dist/entry-points/file/base/fc_package_eslintrc.mjs +0 -31
- package/dist/entry-points/file/base/fc_package_npmconfig.d.ts +0 -9
- package/dist/entry-points/file/base/fc_package_npmconfig.mjs +0 -32
- package/dist/entry-points/file/base/fc_package_tsconfig.d.ts +0 -5
- package/dist/entry-points/file/base/fc_package_tsconfig.mjs +0 -13
- package/dist/entry-points/file/client/fc_package_AppModule.d.ts +0 -1
- package/dist/entry-points/file/client/fc_package_AppModule.mjs +0 -37
- package/dist/entry-points/file/client/fc_package_AppPage.d.ts +0 -1
- package/dist/entry-points/file/client/fc_package_AppPage.mjs +0 -14
- package/dist/entry-points/file/client/fc_package_Page.d.ts +0 -4
- package/dist/entry-points/file/client/fc_package_Page.mjs +0 -19
- package/dist/entry-points/file/client/fc_package_client_main.d.ts +0 -1
- package/dist/entry-points/file/client/fc_package_client_main.mjs +0 -19
- package/dist/entry-points/file/client/fc_package_index.d.ts +0 -3
- package/dist/entry-points/file/client/fc_package_index.mjs +0 -88
- package/dist/entry-points/file/client/fc_package_manifest.d.ts +0 -5
- package/dist/entry-points/file/client/fc_package_manifest.mjs +0 -54
- package/dist/entry-points/file/client/fc_package_polyfills.d.ts +0 -1
- package/dist/entry-points/file/client/fc_package_polyfills.mjs +0 -11
- package/dist/entry-points/file/client/fc_package_styles.d.ts +0 -1
- package/dist/entry-points/file/client/fc_package_styles.mjs +0 -7
- package/dist/entry-points/file/db/fc_package_DbContext.d.ts +0 -3
- package/dist/entry-points/file/db/fc_package_DbContext.mjs +0 -14
- package/dist/entry-points/file/db/fc_package_DbModel.d.ts +0 -4
- package/dist/entry-points/file/db/fc_package_DbModel.mjs +0 -12
- package/dist/entry-points/file/project/fc_project_editor_config.d.ts +0 -1
- package/dist/entry-points/file/project/fc_project_editor_config.mjs +0 -22
- package/dist/entry-points/file/project/fc_project_eslintrc.d.ts +0 -1
- package/dist/entry-points/file/project/fc_project_eslintrc.mjs +0 -30
- package/dist/entry-points/file/project/fc_project_gitattributes.d.ts +0 -1
- package/dist/entry-points/file/project/fc_project_gitattributes.mjs +0 -6
- package/dist/entry-points/file/project/fc_project_gitignore.d.ts +0 -1
- package/dist/entry-points/file/project/fc_project_gitignore.mjs +0 -27
- package/dist/entry-points/file/project/fc_project_npmconfig.d.ts +0 -7
- package/dist/entry-points/file/project/fc_project_npmconfig.mjs +0 -37
- package/dist/entry-points/file/project/fc_project_readme.d.ts +0 -3
- package/dist/entry-points/file/project/fc_project_readme.mjs +0 -13
- package/dist/entry-points/file/project/fc_project_simplysm.d.ts +0 -1
- package/dist/entry-points/file/project/fc_project_simplysm.mjs +0 -2
- package/dist/entry-points/file/project/fc_project_tsconfig.d.ts +0 -1
- package/dist/entry-points/file/project/fc_project_tsconfig.mjs +0 -25
- package/dist/entry-points/file/server/fc_package_server_main.d.ts +0 -5
- package/dist/entry-points/file/server/fc_package_server_main.mjs +0 -60
- package/dist/index.d.ts +0 -54
- package/dist/index.mjs +0 -55
- package/dist/ng-tools/SdCliNgModuleGenerator.d.ts +0 -29
- package/dist/ng-tools/SdCliNgModuleGenerator.mjs +0 -502
- package/dist/ng-tools/babel/SdCliBbFileMetadata.d.ts +0 -25
- package/dist/ng-tools/babel/SdCliBbFileMetadata.mjs +0 -539
- package/dist/ng-tools/babel/SdCliBbRootMetadata.d.ts +0 -23
- package/dist/ng-tools/babel/SdCliBbRootMetadata.mjs +0 -247
- package/dist/ng-tools/babel/SdCliBbUtil.d.ts +0 -5
- package/dist/ng-tools/babel/SdCliBbUtil.mjs +0 -14
- package/dist/ng-tools/babel/TSdCliBbNgMetadata.d.ts +0 -42
- package/dist/ng-tools/babel/TSdCliBbNgMetadata.mjs +0 -216
- package/dist/ng-tools/babel/TSdCliBbTypeMetadata.d.ts +0 -55
- package/dist/ng-tools/babel/TSdCliBbTypeMetadata.mjs +0 -151
- package/dist/ng-tools/commons.d.ts +0 -9
- package/dist/ng-tools/commons.mjs +0 -2
- package/dist/ng-tools/typescript/SdCliTsFileMetadata.d.ts +0 -61
- package/dist/ng-tools/typescript/SdCliTsFileMetadata.mjs +0 -325
- package/dist/ng-tools/typescript/SdCliTsRootMetadata.d.ts +0 -8
- package/dist/ng-tools/typescript/SdCliTsRootMetadata.mjs +0 -28
- package/dist/ng-tools/typescript/SdCliTsUtil.d.ts +0 -5
- package/dist/ng-tools/typescript/SdCliTsUtil.mjs +0 -28
- package/dist/packages/SdCliPackage.d.ts +0 -22
- package/dist/packages/SdCliPackage.mjs +0 -206
- package/dist/utils/SdCliBuildResultUtil.mjs +0 -63
- package/dist/utils/SdCliConfigUtil.mjs +0 -69
- package/dist/utils/SdCliNpmConfigUtil.d.ts +0 -7
- package/dist/utils/SdCliNpmConfigUtil.mjs +0 -15
- package/dist/worker/build-worker.mjs +0 -67
- package/dist/worker/server-worker.mjs +0 -67
- package/docs/client-add-page.md +0 -8
- package/docs/client-router.md +0 -85
- package/docs/client-sw.md +0 -101
- package/docs/conf-orm.md +0 -81
- package/docs/conf-usage.md +0 -5
- package/docs/lib-local-update.md +0 -50
- package/docs/lib-ts-paths.md +0 -25
- package/lib/cordova-entry.js +0 -22
- package/src/SdCliBuildResultError.ts +0 -9
- package/src/bin/sd-cli.ts +0 -493
- package/src/build-tool/SdCliCacheCompilerHost.ts +0 -79
- package/src/build-tool/SdCliCordova.ts +0 -263
- package/src/build-tool/SdCliElectron.ts +0 -84
- package/src/build-tool/SdCliGithubApi.ts +0 -111
- package/src/build-tool/SdCliIndexFileGenerator.ts +0 -79
- package/src/build-tool/SdCliNgCacheCompilerHost.ts +0 -58
- package/src/build-tool/SdCliPackageLinter.ts +0 -74
- package/src/builder/SdCliClientBuilder.ts +0 -871
- package/src/builder/SdCliJsLibBuilder.ts +0 -70
- package/src/builder/SdCliServerBuilder.ts +0 -552
- package/src/builder/SdCliTsLibBuilder.ts +0 -450
- package/src/entry-points/SdCliFileCrypto.ts +0 -87
- package/src/entry-points/SdCliLocalUpdate.ts +0 -121
- package/src/entry-points/SdCliPrepare.ts +0 -86
- package/src/entry-points/SdCliProject.ts +0 -491
- package/src/entry-points/SdCliProjectGenerator.ts +0 -402
- package/src/entry-points/file/base/fc_package_eslintrc.ts +0 -30
- package/src/entry-points/file/base/fc_package_npmconfig.ts +0 -43
- package/src/entry-points/file/base/fc_package_tsconfig.ts +0 -12
- package/src/entry-points/file/client/fc_package_AppModule.ts +0 -36
- package/src/entry-points/file/client/fc_package_AppPage.ts +0 -13
- package/src/entry-points/file/client/fc_package_Page.ts +0 -19
- package/src/entry-points/file/client/fc_package_client_main.ts +0 -18
- package/src/entry-points/file/client/fc_package_index.ts +0 -87
- package/src/entry-points/file/client/fc_package_manifest.ts +0 -53
- package/src/entry-points/file/client/fc_package_polyfills.ts +0 -10
- package/src/entry-points/file/client/fc_package_styles.ts +0 -6
- package/src/entry-points/file/db/fc_package_DbContext.ts +0 -14
- package/src/entry-points/file/db/fc_package_DbModel.ts +0 -11
- package/src/entry-points/file/project/fc_project_editor_config.ts +0 -21
- package/src/entry-points/file/project/fc_project_eslintrc.ts +0 -29
- package/src/entry-points/file/project/fc_project_gitattributes.ts +0 -5
- package/src/entry-points/file/project/fc_project_gitignore.ts +0 -26
- package/src/entry-points/file/project/fc_project_npmconfig.ts +0 -36
- package/src/entry-points/file/project/fc_project_readme.ts +0 -12
- package/src/entry-points/file/project/fc_project_simplysm.ts +0 -1
- package/src/entry-points/file/project/fc_project_tsconfig.ts +0 -24
- package/src/entry-points/file/server/fc_package_server_main.ts +0 -62
- package/src/index.ts +0 -54
- package/src/ng-tools/SdCliNgModuleGenerator.ts +0 -672
- package/src/ng-tools/babel/SdCliBbFileMetadata.ts +0 -629
- package/src/ng-tools/babel/SdCliBbRootMetadata.ts +0 -292
- package/src/ng-tools/babel/SdCliBbUtil.ts +0 -15
- package/src/ng-tools/babel/TSdCliBbNgMetadata.ts +0 -251
- package/src/ng-tools/babel/TSdCliBbTypeMetadata.ts +0 -212
- package/src/ng-tools/commons.ts +0 -3
- package/src/ng-tools/typescript/SdCliTsFileMetadata.ts +0 -384
- package/src/ng-tools/typescript/SdCliTsRootMetadata.ts +0 -32
- package/src/ng-tools/typescript/SdCliTsUtil.ts +0 -29
- package/src/packages/SdCliPackage.ts +0 -259
- package/src/utils/SdCliNpmConfigUtil.ts +0 -16
- package/src/worker/build-worker.ts +0 -73
- package/src/worker/server-worker.ts +0 -72
- /package/dist/{worker/build-worker.d.ts → build-cluster.d.ts} +0 -0
- /package/dist/{worker/server-worker.d.ts → sd-cli.d.ts} +0 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import cluster from "node:cluster";
|
|
2
|
+
import { SdCliTsLibBuilder } from "./builders/SdCliTsLibBuilder";
|
|
3
|
+
import { FsUtil, Logger, LoggerSeverity } from "@simplysm/sd-core-node";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { SdCliJsLibLinter } from "./builders/SdCliJsLibLinter";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
if (Boolean(process.env["SD_DEBUG"])) {
|
|
9
|
+
Logger.setConfig({
|
|
10
|
+
console: {
|
|
11
|
+
level: LoggerSeverity.debug
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
Logger.setConfig({
|
|
17
|
+
dot: true
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const logger = Logger.get(["simplysm", "sd-cli", "build-cluster"]);
|
|
22
|
+
|
|
23
|
+
if (cluster.isPrimary) {
|
|
24
|
+
logger.debug(`메인 프로세스 ${process.pid} 시작`);
|
|
25
|
+
|
|
26
|
+
cluster.on("exit", (worker, code) => {
|
|
27
|
+
logger.debug(`워커 프로세스 ${worker.process.pid} 종료 (code: ${code})`);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
cluster.on("message", (worker, message) => {
|
|
31
|
+
process.send!(message);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
process.on("message", (message) => {
|
|
35
|
+
cluster.fork({
|
|
36
|
+
"SD_CLUSTER_MESSAGE": JSON.stringify(message)
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
process.send!("ready");
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const message = JSON.parse(process.env["SD_CLUSTER_MESSAGE"]!);
|
|
43
|
+
|
|
44
|
+
if (message.cmd === "watch") {
|
|
45
|
+
// javascript
|
|
46
|
+
if (!FsUtil.exists(path.resolve(message.pkgPath, "tsconfig.json"))) {
|
|
47
|
+
await new SdCliJsLibLinter(message.pkgPath)
|
|
48
|
+
.on("change", () => {
|
|
49
|
+
process.send!({ type: "change", ...message });
|
|
50
|
+
})
|
|
51
|
+
.on("complete", (result) => {
|
|
52
|
+
process.send!({ type: "complete", result, ...message });
|
|
53
|
+
})
|
|
54
|
+
.watchAsync();
|
|
55
|
+
process.send!({ type: "ready", ...message });
|
|
56
|
+
}
|
|
57
|
+
// typescript
|
|
58
|
+
else {
|
|
59
|
+
await new SdCliTsLibBuilder(message.pkgPath)
|
|
60
|
+
.on("change", () => {
|
|
61
|
+
process.send!({ type: "change", ...message });
|
|
62
|
+
})
|
|
63
|
+
.on("complete", (result) => {
|
|
64
|
+
process.send!({ type: "complete", result, ...message });
|
|
65
|
+
})
|
|
66
|
+
.watchAsync();
|
|
67
|
+
process.send!({ type: "ready", ...message });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else { // build
|
|
71
|
+
// javascript
|
|
72
|
+
if (!FsUtil.exists(path.resolve(message.pkgPath, "tsconfig.json"))) {
|
|
73
|
+
const result = await new SdCliJsLibLinter(message.pkgPath).buildAsync();
|
|
74
|
+
process.send!({ type: "complete", result, ...message });
|
|
75
|
+
}
|
|
76
|
+
// typescript
|
|
77
|
+
else {
|
|
78
|
+
const result = await new SdCliTsLibBuilder(message.pkgPath).buildAsync();
|
|
79
|
+
process.send!({ type: "complete", result, ...message });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { FsUtil, Logger, SdFsWatcher } from "@simplysm/sd-core-node";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { ISdCliPackageBuildResult } from "../commons";
|
|
4
|
+
import { EventEmitter } from "events";
|
|
5
|
+
import { ESLint } from "eslint";
|
|
6
|
+
|
|
7
|
+
export class SdCliJsLibLinter extends EventEmitter {
|
|
8
|
+
private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliJsLibLinter"]);
|
|
9
|
+
private readonly _pkgName: string;
|
|
10
|
+
|
|
11
|
+
public constructor(private readonly _pkgPath: string) {
|
|
12
|
+
super();
|
|
13
|
+
this._pkgName = path.basename(_pkgPath);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public override on(event: "change", listener: () => void): this;
|
|
17
|
+
public override on(event: "complete", listener: (result: { affectedFilePaths: string[]; buildResults: ISdCliPackageBuildResult[] }) => void): this;
|
|
18
|
+
public override on(event: string | symbol, listener: (...args: any[]) => void): this {
|
|
19
|
+
super.on(event, listener);
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public async buildAsync(): Promise<ISdCliPackageBuildResult[]> {
|
|
24
|
+
this._debug("LINT...");
|
|
25
|
+
const srcGlobPath = path.resolve(this._pkgPath, "src/**/*.+(js|cjs|mjs)");
|
|
26
|
+
const srcFilePaths = await FsUtil.globAsync(srcGlobPath);
|
|
27
|
+
const lintResults = await this._lintAsync(srcFilePaths);
|
|
28
|
+
|
|
29
|
+
this._debug(`LINT 완료`);
|
|
30
|
+
return lintResults;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public async watchAsync(): Promise<void> {
|
|
34
|
+
this.emit("change");
|
|
35
|
+
this._debug("LINT...");
|
|
36
|
+
const srcGlobPath = path.resolve(this._pkgPath, "src/**/*.+(js|cjs|mjs)");
|
|
37
|
+
const srcFilePaths = await FsUtil.globAsync(srcGlobPath);
|
|
38
|
+
const lintResults = await this._lintAsync(srcFilePaths);
|
|
39
|
+
|
|
40
|
+
this._debug(`LINT 완료`);
|
|
41
|
+
this.emit("complete", {
|
|
42
|
+
affectedFilePaths: srcFilePaths,
|
|
43
|
+
buildResults: lintResults
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
SdFsWatcher
|
|
47
|
+
.watch([srcGlobPath])
|
|
48
|
+
.onChange({
|
|
49
|
+
delay: 100
|
|
50
|
+
}, async (changeInfos) => {
|
|
51
|
+
const watchFilePaths = changeInfos.filter((item) => FsUtil.exists(item.path)).map((item) => item.path);
|
|
52
|
+
if (watchFilePaths.length < 1) return;
|
|
53
|
+
|
|
54
|
+
this.emit("change");
|
|
55
|
+
this._debug("LINT...");
|
|
56
|
+
const watchLintResults = await this._lintAsync(watchFilePaths);
|
|
57
|
+
|
|
58
|
+
this._debug(`LINT 완료`);
|
|
59
|
+
this.emit("complete", {
|
|
60
|
+
affectedFilePaths: changeInfos.map((item) => item.path),
|
|
61
|
+
buildResults: watchLintResults
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private async _lintAsync(srcFilePaths: string[]): Promise<ISdCliPackageBuildResult[]> {
|
|
67
|
+
const linter = new ESLint();
|
|
68
|
+
|
|
69
|
+
const lintResults = await linter.lintFiles(srcFilePaths);
|
|
70
|
+
|
|
71
|
+
return lintResults.mapMany((lintResult) => lintResult.messages.map((msg) => ({
|
|
72
|
+
filePath: lintResult.filePath,
|
|
73
|
+
line: msg.line,
|
|
74
|
+
char: msg.column,
|
|
75
|
+
code: msg.ruleId ?? undefined,
|
|
76
|
+
severity: msg.severity === 1 ? "warning" as const : "error" as const,
|
|
77
|
+
message: msg.message
|
|
78
|
+
})));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private _debug(msg: string): void {
|
|
82
|
+
this._logger.debug(`[${this._pkgName}] ${msg}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { FsUtil, Logger, PathUtil, SdFsWatcher } from "@simplysm/sd-core-node";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { ISdCliPackageBuildResult } from "../commons";
|
|
5
|
+
import { SdCliBuildResultUtil } from "../utils/SdCliBuildResultUtil";
|
|
6
|
+
import { EventEmitter } from "events";
|
|
7
|
+
import { ESLint } from "eslint";
|
|
8
|
+
import { FunctionQueue } from "@simplysm/sd-core-common";
|
|
9
|
+
|
|
10
|
+
export class SdCliTsLibBuilder extends EventEmitter {
|
|
11
|
+
private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliTsLibBuilder"]);
|
|
12
|
+
private readonly _pkgName: string;
|
|
13
|
+
private readonly _writeFileCache = new Map<string, string>();
|
|
14
|
+
|
|
15
|
+
public constructor(private readonly _pkgPath: string) {
|
|
16
|
+
super();
|
|
17
|
+
this._pkgName = path.basename(_pkgPath);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public override on(event: "change", listener: () => void): this;
|
|
21
|
+
public override on(event: "complete", listener: (result: { affectedFilePaths: string[]; buildResults: ISdCliPackageBuildResult[] }) => void): this;
|
|
22
|
+
public override on(event: string | symbol, listener: (...args: any[]) => void): this {
|
|
23
|
+
super.on(event, listener);
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public async buildAsync(): Promise<ISdCliPackageBuildResult[]> {
|
|
28
|
+
this._debug("빌드 준비...");
|
|
29
|
+
|
|
30
|
+
const srcGlobPath = path.resolve(this._pkgPath, "src/**/*.ts");
|
|
31
|
+
|
|
32
|
+
const parsedTsConfig = ts.parseJsonConfigFileContent(
|
|
33
|
+
await FsUtil.readJsonAsync(path.resolve(this._pkgPath, "tsconfig.json")),
|
|
34
|
+
ts.sys,
|
|
35
|
+
this._pkgPath,
|
|
36
|
+
{
|
|
37
|
+
outDir: path.resolve(this._pkgPath, "dist"),
|
|
38
|
+
incremental: true,
|
|
39
|
+
tsBuildInfoFile: path.resolve(this._pkgPath, ".cache/tsbuildinfo.json"),
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const host = ts.createIncrementalCompilerHost(parsedTsConfig.options, ts.sys);
|
|
44
|
+
|
|
45
|
+
this._debug("dist 초기화...");
|
|
46
|
+
await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
|
|
47
|
+
|
|
48
|
+
this._debug("빌드...");
|
|
49
|
+
const srcFilePaths = await FsUtil.globAsync(srcGlobPath);
|
|
50
|
+
const emitResult = this._emitIncrementalProgram({
|
|
51
|
+
rootNames: srcFilePaths,
|
|
52
|
+
options: parsedTsConfig.options,
|
|
53
|
+
host: host
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
this._debug("LINT...");
|
|
57
|
+
const lintResults = await this._lintAsync(emitResult.program.getProgram(), srcFilePaths);
|
|
58
|
+
|
|
59
|
+
this._debug(`빌드 완료`);
|
|
60
|
+
return [...emitResult.buildResults, ...lintResults];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public async watchAsync(): Promise<void> {
|
|
64
|
+
this.emit("change");
|
|
65
|
+
this._debug("빌드 준비...");
|
|
66
|
+
|
|
67
|
+
const srcGlobPath = path.resolve(this._pkgPath, "src/**/*.ts");
|
|
68
|
+
|
|
69
|
+
const parsedTsConfig = ts.parseJsonConfigFileContent(
|
|
70
|
+
await FsUtil.readJsonAsync(path.resolve(this._pkgPath, "tsconfig.json")),
|
|
71
|
+
ts.sys,
|
|
72
|
+
this._pkgPath,
|
|
73
|
+
{
|
|
74
|
+
outDir: path.resolve(this._pkgPath, "dist"),
|
|
75
|
+
incremental: true,
|
|
76
|
+
tsBuildInfoFile: path.resolve(this._pkgPath, ".cache/tsbuildinfo.json"),
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const host = ts.createIncrementalCompilerHost(parsedTsConfig.options, ts.sys);
|
|
81
|
+
|
|
82
|
+
this._debug("dist 초기화...");
|
|
83
|
+
await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
|
|
84
|
+
|
|
85
|
+
this._debug("빌드...");
|
|
86
|
+
const srcFilePaths = await FsUtil.globAsync(srcGlobPath);
|
|
87
|
+
const emitResult = this._emitIncrementalProgram({
|
|
88
|
+
rootNames: srcFilePaths,
|
|
89
|
+
options: parsedTsConfig.options,
|
|
90
|
+
host: host
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
this._debug("LINT...");
|
|
94
|
+
const lintResults = await this._lintAsync(emitResult.program.getProgram(), srcFilePaths);
|
|
95
|
+
|
|
96
|
+
this._debug(`빌드 완료`);
|
|
97
|
+
this.emit("complete", {
|
|
98
|
+
affectedFilePaths: srcFilePaths,
|
|
99
|
+
buildResults: [...emitResult.buildResults, ...lintResults]
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const fnQ = new FunctionQueue();
|
|
103
|
+
SdFsWatcher
|
|
104
|
+
.watch([
|
|
105
|
+
...emitResult.program.getSourceFiles().map((item) => item.fileName),
|
|
106
|
+
srcGlobPath
|
|
107
|
+
])
|
|
108
|
+
.onChange({
|
|
109
|
+
delay: 100
|
|
110
|
+
}, () => {
|
|
111
|
+
fnQ.runLast(async () => {
|
|
112
|
+
this.emit("change");
|
|
113
|
+
this._debug(`빌드...`);
|
|
114
|
+
|
|
115
|
+
const watchSrcFilePaths = await FsUtil.globAsync(srcGlobPath);
|
|
116
|
+
const watchResult = this._emitIncrementalProgram({
|
|
117
|
+
rootNames: await FsUtil.globAsync(srcGlobPath),
|
|
118
|
+
options: parsedTsConfig.options,
|
|
119
|
+
host: host
|
|
120
|
+
});
|
|
121
|
+
const watchAffectedSrcFilePaths = watchResult.affectedFileNames.map((item) => path.resolve(item)).filter((item) => watchSrcFilePaths.includes(item));
|
|
122
|
+
|
|
123
|
+
this._debug("LINT...");
|
|
124
|
+
const watchLintResults = await this._lintAsync(watchResult.program.getProgram(), watchAffectedSrcFilePaths);
|
|
125
|
+
|
|
126
|
+
this._debug(`빌드 완료`);
|
|
127
|
+
this.emit("complete", {
|
|
128
|
+
affectedFilePaths: watchAffectedSrcFilePaths,
|
|
129
|
+
buildResults: [...watchResult.buildResults, ...watchLintResults]
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private _emitIncrementalProgram(opt: {
|
|
136
|
+
rootNames: string[];
|
|
137
|
+
options: ts.CompilerOptions;
|
|
138
|
+
host: ts.CompilerHost;
|
|
139
|
+
}): {
|
|
140
|
+
program: ts.SemanticDiagnosticsBuilderProgram;
|
|
141
|
+
buildResults: ISdCliPackageBuildResult[];
|
|
142
|
+
affectedFileNames: string[];
|
|
143
|
+
} {
|
|
144
|
+
const program = ts.createIncrementalProgram({
|
|
145
|
+
rootNames: opt.rootNames,
|
|
146
|
+
options: opt.options,
|
|
147
|
+
host: opt.host,
|
|
148
|
+
createProgram: ts.createSemanticDiagnosticsBuilderProgram
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const diagnostics: ts.Diagnostic[] = [];
|
|
152
|
+
const affectedFileNames: string[] = [];
|
|
153
|
+
|
|
154
|
+
diagnostics.push(
|
|
155
|
+
...program.getOptionsDiagnostics(),
|
|
156
|
+
...program.getGlobalDiagnostics(),
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
while (true) {
|
|
160
|
+
const semanticResult = program.getSemanticDiagnosticsOfNextAffectedFile(undefined, (sourceFile) => {
|
|
161
|
+
return !opt.rootNames.includes(path.resolve(sourceFile.fileName));
|
|
162
|
+
});
|
|
163
|
+
if (!semanticResult) break;
|
|
164
|
+
diagnostics.push(...semanticResult.result);
|
|
165
|
+
|
|
166
|
+
/*const result = program.emitNextAffectedFile((filePath, data, writeByteOrderMark) => {
|
|
167
|
+
if (this._writeFileCache.get(filePath) !== data) {
|
|
168
|
+
ts.sys.writeFile(filePath, data, writeByteOrderMark);
|
|
169
|
+
}
|
|
170
|
+
this._writeFileCache.set(filePath, data);
|
|
171
|
+
});
|
|
172
|
+
if (!result) break;*/
|
|
173
|
+
|
|
174
|
+
if ("fileName" in semanticResult.affected) {
|
|
175
|
+
const emitResult = program.emit(program.getSourceFile(semanticResult.affected.fileName), (filePath, data, writeByteOrderMark) => {
|
|
176
|
+
let realFilePath = filePath;
|
|
177
|
+
if (PathUtil.isChildPath(realFilePath, path.resolve(this._pkgPath, "dist", this._pkgName, "src"))) {
|
|
178
|
+
realFilePath = path.resolve(this._pkgPath, "dist", path.relative(path.resolve(this._pkgPath, "dist", this._pkgName, "src"), realFilePath));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (this._writeFileCache.get(realFilePath) !== data) {
|
|
182
|
+
ts.sys.writeFile(realFilePath, data, writeByteOrderMark);
|
|
183
|
+
}
|
|
184
|
+
this._writeFileCache.set(realFilePath, data);
|
|
185
|
+
});
|
|
186
|
+
diagnostics.push(...emitResult.diagnostics);
|
|
187
|
+
|
|
188
|
+
affectedFileNames.push(semanticResult.affected.fileName);
|
|
189
|
+
diagnostics.push(...program.getSyntacticDiagnostics(semanticResult.affected));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const buildResults = diagnostics.map((item) => SdCliBuildResultUtil.convertFromTsDiag(item));
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
program,
|
|
197
|
+
buildResults,
|
|
198
|
+
affectedFileNames
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/*private readonly _linter = new ESLint({
|
|
203
|
+
overrideConfig: {
|
|
204
|
+
overrides: [
|
|
205
|
+
{
|
|
206
|
+
files: ["*.ts"],
|
|
207
|
+
parserOptions: {
|
|
208
|
+
tsconfigRootDir: this._pkgPath,
|
|
209
|
+
project: "tsconfig.json"
|
|
210
|
+
},
|
|
211
|
+
settings: {
|
|
212
|
+
"import/resolver": {
|
|
213
|
+
"typescript": {
|
|
214
|
+
project: path.resolve(this._pkgPath, "tsconfig.json")
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
]
|
|
220
|
+
}
|
|
221
|
+
});*/
|
|
222
|
+
|
|
223
|
+
private async _lintAsync(program: ts.Program, srcFilePaths: string[]): Promise<ISdCliPackageBuildResult[]> {
|
|
224
|
+
const linter = new ESLint({
|
|
225
|
+
overrideConfig: {
|
|
226
|
+
overrides: [
|
|
227
|
+
{
|
|
228
|
+
files: ["*.ts"],
|
|
229
|
+
parserOptions: {
|
|
230
|
+
programs: [program],
|
|
231
|
+
tsconfigRootDir: null,
|
|
232
|
+
project: null,
|
|
233
|
+
// tsconfigRootDir: this._pkgPath,
|
|
234
|
+
// project: "tsconfig.json"
|
|
235
|
+
},
|
|
236
|
+
settings: {
|
|
237
|
+
"import/resolver": {
|
|
238
|
+
"typescript": {
|
|
239
|
+
programs: [program],
|
|
240
|
+
project: null,
|
|
241
|
+
// project: path.resolve(this._pkgPath, "tsconfig.json"),
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
const lintResults = await linter.lintFiles(srcFilePaths);
|
|
251
|
+
|
|
252
|
+
return lintResults.mapMany((lintResult) => lintResult.messages.map((msg) => ({
|
|
253
|
+
filePath: lintResult.filePath,
|
|
254
|
+
line: msg.line,
|
|
255
|
+
char: msg.column,
|
|
256
|
+
code: msg.ruleId ?? undefined,
|
|
257
|
+
severity: msg.severity === 1 ? "warning" as const : "error" as const,
|
|
258
|
+
message: msg.message
|
|
259
|
+
})));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
private _debug(msg: string): void {
|
|
263
|
+
this._logger.debug(`[${this._pkgName}] ${msg}`);
|
|
264
|
+
}
|
|
265
|
+
}
|
package/src/commons.ts
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
1
1
|
export interface INpmConfig {
|
|
2
2
|
name: string;
|
|
3
3
|
version: string;
|
|
4
|
-
description?: string;
|
|
5
|
-
author?: string;
|
|
6
|
-
license?: string;
|
|
7
|
-
repository?: {
|
|
8
|
-
type: string;
|
|
9
|
-
url: string;
|
|
10
|
-
directory?: string;
|
|
11
|
-
};
|
|
12
|
-
type?: "module";
|
|
13
4
|
workspaces?: string[];
|
|
14
|
-
main?: string;
|
|
15
|
-
types?: string;
|
|
16
|
-
exports?: Record<string, {
|
|
17
|
-
types?: string;
|
|
18
|
-
}>;
|
|
19
|
-
scripts?: Record<string, string>;
|
|
20
5
|
|
|
21
6
|
dependencies?: Record<string, string>;
|
|
22
7
|
optionalDependencies?: Record<string, string>;
|
|
@@ -25,127 +10,22 @@ export interface INpmConfig {
|
|
|
25
10
|
peerDependenciesMeta?: Record<string, { optional?: boolean }>;
|
|
26
11
|
}
|
|
27
12
|
|
|
28
|
-
export interface ITsconfig {
|
|
29
|
-
compilerOptions?: {
|
|
30
|
-
module?: string;
|
|
31
|
-
lib?: string[];
|
|
32
|
-
outDir?: string;
|
|
33
|
-
baseUrl?: string;
|
|
34
|
-
paths?: Record<string, string[]>;
|
|
35
|
-
declaration?: boolean;
|
|
36
|
-
};
|
|
37
|
-
files?: string[];
|
|
38
|
-
angularCompilerOptions?: Record<string, any>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
13
|
export interface ISdCliPackageBuildResult {
|
|
42
14
|
filePath: string | undefined;
|
|
43
15
|
line: number | undefined;
|
|
44
16
|
char: number | undefined;
|
|
45
17
|
code: string | undefined;
|
|
46
|
-
severity: "error" | "warning";
|
|
18
|
+
severity: "error" | "warning" | "suggestion" | "message";
|
|
47
19
|
message: string;
|
|
48
20
|
}
|
|
49
21
|
|
|
50
22
|
export interface ISdCliConfig {
|
|
51
23
|
packages: Record<string, TSdCliPackageConfig | undefined>;
|
|
52
|
-
localUpdates?: Record<string, string>;
|
|
53
24
|
}
|
|
54
25
|
|
|
55
|
-
export type TSdCliPackageConfig = ISdCliLibPackageConfig
|
|
26
|
+
export type TSdCliPackageConfig = ISdCliLibPackageConfig;
|
|
56
27
|
|
|
57
28
|
export interface ISdCliLibPackageConfig {
|
|
58
29
|
type: "library";
|
|
59
|
-
|
|
60
|
-
autoIndex?: {
|
|
61
|
-
polyfills?: string[];
|
|
62
|
-
};
|
|
63
|
-
publish?: "npm";
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export interface ISdCliServerPackageConfig {
|
|
67
|
-
type: "server";
|
|
68
|
-
env?: Record<string, string>;
|
|
69
|
-
configs?: Record<string, any>;
|
|
70
|
-
pm2?: {
|
|
71
|
-
fileName?: string;
|
|
72
|
-
noInterpreter?: boolean;
|
|
73
|
-
noStartScript?: boolean;
|
|
74
|
-
config: Record<string, any>;
|
|
75
|
-
} | boolean;
|
|
76
|
-
iis?: boolean | { serverExeFilePath?: string };
|
|
77
|
-
externalNodeModules?: string[];
|
|
78
|
-
publish?: TSdCliPublishConfig;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export interface ISdCliClientPackageConfig {
|
|
82
|
-
type: "client";
|
|
83
|
-
builder?: {
|
|
84
|
-
web?: ISdCliClientBuilderWebConfig;
|
|
85
|
-
cordova?: ISdCliClientBuilderCordovaConfig;
|
|
86
|
-
electron?: ISdCliClientBuilderElectronConfig;
|
|
87
|
-
};
|
|
88
|
-
server: string | { port: number };
|
|
89
|
-
env?: Record<string, string>;
|
|
90
|
-
configs?: Record<string, any>;
|
|
91
|
-
publish?: TSdCliPublishConfig;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export type TSdCliPublishConfig =
|
|
95
|
-
ISdCliFtpPublishConfig
|
|
96
|
-
| ISdCliLocalDirectoryPublishConfig
|
|
97
|
-
| ISdCliGithubPublishConfig;
|
|
98
|
-
|
|
99
|
-
export interface ISdCliFtpPublishConfig {
|
|
100
|
-
type: "ftp" | "ftps" | "sftp";
|
|
101
|
-
host: string;
|
|
102
|
-
port?: number;
|
|
103
|
-
path: string;
|
|
104
|
-
user: string;
|
|
105
|
-
pass: string;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export interface ISdCliLocalDirectoryPublishConfig {
|
|
109
|
-
type: "local-directory";
|
|
110
|
-
path: string;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export interface ISdCliGithubPublishConfig {
|
|
114
|
-
type: "github";
|
|
115
|
-
apiKey: string;
|
|
116
|
-
files: { from: string; to: string }[];
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export interface ISdCliClientBuilderWebConfig {
|
|
120
|
-
env?: Record<string, string>;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export interface ISdCliClientBuilderCordovaConfig {
|
|
124
|
-
env?: Record<string, string>;
|
|
125
|
-
appId: string;
|
|
126
|
-
appName: string;
|
|
127
|
-
plugins?: string[];
|
|
128
|
-
icon?: string;
|
|
129
|
-
debug?: boolean;
|
|
130
|
-
target?: {
|
|
131
|
-
browser?: {};
|
|
132
|
-
android?: {
|
|
133
|
-
bundle?: boolean;
|
|
134
|
-
sign?: {
|
|
135
|
-
keystore: string;
|
|
136
|
-
storePassword: string;
|
|
137
|
-
alias: string;
|
|
138
|
-
password: string;
|
|
139
|
-
keystoreType: string;
|
|
140
|
-
};
|
|
141
|
-
};
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export interface ISdCliClientBuilderElectronConfig {
|
|
146
|
-
env?: Record<string, string>;
|
|
147
|
-
externalNodeModules?: string[];
|
|
148
|
-
appId: string;
|
|
149
|
-
icon?: string;
|
|
150
|
-
installerIcon?: string;
|
|
30
|
+
publish: "npm";
|
|
151
31
|
}
|