@simplysm/sd-cli 12.5.20 → 12.5.22

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.
Files changed (183) hide show
  1. package/dist/{build-tools → entry}/SdCliCordova.d.ts +5 -6
  2. package/dist/{build-tools → entry}/SdCliCordova.js +117 -99
  3. package/dist/entry/SdCliCordova.js.map +1 -0
  4. package/dist/entry/SdCliElectron.d.ts +2 -2
  5. package/dist/entry/SdCliElectron.js +50 -40
  6. package/dist/entry/SdCliElectron.js.map +1 -1
  7. package/dist/entry/SdCliLocalUpdate.d.ts +1 -2
  8. package/dist/entry/SdCliLocalUpdate.js +26 -27
  9. package/dist/entry/SdCliLocalUpdate.js.map +1 -1
  10. package/dist/entry/SdCliProject.d.ts +1 -5
  11. package/dist/entry/SdCliProject.js +62 -288
  12. package/dist/entry/SdCliProject.js.map +1 -1
  13. package/dist/index.d.ts +23 -17
  14. package/dist/index.js +23 -17
  15. package/dist/index.js.map +1 -1
  16. package/dist/pkg-builders/SdMultiBuildRunner.d.ts +21 -0
  17. package/dist/pkg-builders/SdMultiBuildRunner.js +174 -0
  18. package/dist/pkg-builders/SdMultiBuildRunner.js.map +1 -0
  19. package/dist/pkg-builders/client/SdCliNgRoutesFileGenerator.d.ts +4 -0
  20. package/dist/{build-tools → pkg-builders/client}/SdCliNgRoutesFileGenerator.js +7 -7
  21. package/dist/pkg-builders/client/SdCliNgRoutesFileGenerator.js.map +1 -0
  22. package/dist/pkg-builders/client/SdClientBuildRunner.d.ts +20 -0
  23. package/dist/pkg-builders/client/SdClientBuildRunner.js +135 -0
  24. package/dist/pkg-builders/client/SdClientBuildRunner.js.map +1 -0
  25. package/dist/pkg-builders/client/SdNgBundler.d.ts +29 -0
  26. package/dist/{build-tools → pkg-builders/client}/SdNgBundler.js +100 -95
  27. package/dist/pkg-builders/client/SdNgBundler.js.map +1 -0
  28. package/dist/{build-tools → pkg-builders/client}/SdNgBundlerContext.d.ts +1 -2
  29. package/dist/{build-tools → pkg-builders/client}/SdNgBundlerContext.js +19 -45
  30. package/dist/pkg-builders/client/SdNgBundlerContext.js.map +1 -0
  31. package/dist/pkg-builders/client/createSdNgPlugin.d.ts +10 -0
  32. package/dist/{bundle-plugins/sdNgPlugin.js → pkg-builders/client/createSdNgPlugin.js} +32 -33
  33. package/dist/pkg-builders/client/createSdNgPlugin.js.map +1 -0
  34. package/dist/pkg-builders/lib/SdCliIndexFileGenerator.d.ts +5 -0
  35. package/dist/{build-tools → pkg-builders/lib}/SdCliIndexFileGenerator.js +11 -11
  36. package/dist/pkg-builders/lib/SdCliIndexFileGenerator.js.map +1 -0
  37. package/dist/pkg-builders/lib/SdJsLibBuildRunner.d.ts +16 -0
  38. package/dist/pkg-builders/lib/SdJsLibBuildRunner.js +81 -0
  39. package/dist/pkg-builders/lib/SdJsLibBuildRunner.js.map +1 -0
  40. package/dist/pkg-builders/lib/SdTsLibBuildRunner.d.ts +13 -0
  41. package/dist/pkg-builders/lib/SdTsLibBuildRunner.js +89 -0
  42. package/dist/pkg-builders/lib/SdTsLibBuildRunner.js.map +1 -0
  43. package/dist/pkg-builders/lib/SdTsLibBuilder.d.ts +14 -0
  44. package/dist/pkg-builders/lib/SdTsLibBuilder.js +54 -0
  45. package/dist/pkg-builders/lib/SdTsLibBuilder.js.map +1 -0
  46. package/dist/pkg-builders/server/SdServerBuildRunner.d.ts +17 -0
  47. package/dist/{builders/SdCliServerBuilder.js → pkg-builders/server/SdServerBuildRunner.js} +48 -53
  48. package/dist/pkg-builders/server/SdServerBuildRunner.js.map +1 -0
  49. package/dist/pkg-builders/server/SdServerBundler.d.ts +19 -0
  50. package/dist/{build-tools → pkg-builders/server}/SdServerBundler.js +25 -30
  51. package/dist/pkg-builders/server/SdServerBundler.js.map +1 -0
  52. package/dist/pkg-builders/server/createSdServerPlugin.d.ts +10 -0
  53. package/dist/pkg-builders/server/createSdServerPlugin.js +53 -0
  54. package/dist/pkg-builders/server/createSdServerPlugin.js.map +1 -0
  55. package/dist/sd-cli.js +61 -54
  56. package/dist/sd-cli.js.map +1 -1
  57. package/dist/ts-builder/SdTsCompileWorker.d.ts +9 -0
  58. package/dist/ts-builder/SdTsCompileWorker.js +16 -0
  59. package/dist/ts-builder/SdTsCompileWorker.js.map +1 -0
  60. package/dist/ts-builder/SdTsCompiler.d.ts +7 -0
  61. package/dist/{build-tools → ts-builder}/SdTsCompiler.js +226 -212
  62. package/dist/ts-builder/SdTsCompiler.js.map +1 -0
  63. package/dist/types/build-plugin.type.d.ts +14 -0
  64. package/dist/types/build-plugin.type.js +2 -0
  65. package/dist/types/build-plugin.type.js.map +1 -0
  66. package/dist/types/build.type.d.ts +15 -0
  67. package/dist/types/build.type.js +2 -0
  68. package/dist/types/build.type.js.map +1 -0
  69. package/dist/types/common-configs.type.d.ts +22 -0
  70. package/dist/types/common-configs.type.js +2 -0
  71. package/dist/types/common-configs.type.js.map +1 -0
  72. package/dist/types/sd-configs.type.d.ts +99 -0
  73. package/dist/types/sd-configs.type.js +2 -0
  74. package/dist/types/sd-configs.type.js.map +1 -0
  75. package/dist/types/ts-compiler.type.d.ts +29 -0
  76. package/dist/types/ts-compiler.type.js +2 -0
  77. package/dist/types/ts-compiler.type.js.map +1 -0
  78. package/dist/types/workers.type.d.ts +49 -0
  79. package/dist/types/workers.type.js +2 -0
  80. package/dist/types/workers.type.js.map +1 -0
  81. package/dist/utils/SdCliConvertMessageUtil.d.ts +21 -0
  82. package/dist/utils/SdCliConvertMessageUtil.js +137 -0
  83. package/dist/utils/SdCliConvertMessageUtil.js.map +1 -0
  84. package/dist/workers/compile-worker.js +27 -0
  85. package/dist/workers/compile-worker.js.map +1 -0
  86. package/dist/workers/lint-worker.js +36 -0
  87. package/dist/workers/lint-worker.js.map +1 -0
  88. package/dist/workers/server-worker.d.ts +1 -0
  89. package/dist/workers/server-worker.js +49 -0
  90. package/dist/workers/server-worker.js.map +1 -0
  91. package/lib/dev-worker.cjs +5 -0
  92. package/package.json +7 -7
  93. package/src/entry/SdCliCordova.ts +363 -0
  94. package/src/entry/SdCliElectron.ts +96 -69
  95. package/src/entry/SdCliLocalUpdate.ts +43 -44
  96. package/src/entry/SdCliProject.ts +72 -417
  97. package/src/index.ts +23 -17
  98. package/src/pkg-builders/SdMultiBuildRunner.ts +250 -0
  99. package/src/{build-tools → pkg-builders/client}/SdCliNgRoutesFileGenerator.ts +7 -7
  100. package/src/pkg-builders/client/SdClientBuildRunner.ts +191 -0
  101. package/src/{build-tools → pkg-builders/client}/SdNgBundler.ts +125 -121
  102. package/src/pkg-builders/client/SdNgBundlerContext.ts +111 -0
  103. package/src/{bundle-plugins/sdNgPlugin.ts → pkg-builders/client/createSdNgPlugin.ts} +43 -46
  104. package/src/{build-tools → pkg-builders/lib}/SdCliIndexFileGenerator.ts +11 -11
  105. package/src/pkg-builders/lib/SdJsLibBuildRunner.ts +105 -0
  106. package/src/pkg-builders/lib/SdTsLibBuildRunner.ts +128 -0
  107. package/src/pkg-builders/lib/SdTsLibBuilder.ts +69 -0
  108. package/src/{builders/SdCliServerBuilder.ts → pkg-builders/server/SdServerBuildRunner.ts} +66 -78
  109. package/src/{build-tools → pkg-builders/server}/SdServerBundler.ts +40 -41
  110. package/src/pkg-builders/server/createSdServerPlugin.ts +77 -0
  111. package/src/sd-cli.ts +197 -211
  112. package/src/ts-builder/SdTsCompileWorker.ts +21 -0
  113. package/src/ts-builder/SdTsCompiler.ts +758 -0
  114. package/src/types/build-plugin.type.ts +16 -0
  115. package/src/types/build.type.ts +17 -0
  116. package/src/types/common-configs.type.ts +27 -0
  117. package/src/types/sd-configs.type.ts +114 -0
  118. package/src/types/ts-compiler.type.ts +29 -0
  119. package/src/types/workers.type.ts +27 -0
  120. package/src/utils/SdCliConvertMessageUtil.ts +177 -0
  121. package/src/workers/compile-worker.ts +31 -0
  122. package/src/workers/lint-worker.ts +44 -0
  123. package/src/workers/server-worker.ts +52 -0
  124. package/tsconfig.json +7 -1
  125. package/dist/build-cluster.js +0 -201
  126. package/dist/build-cluster.js.map +0 -1
  127. package/dist/build-tools/SdCliCordova.js.map +0 -1
  128. package/dist/build-tools/SdCliIndexFileGenerator.d.ts +0 -5
  129. package/dist/build-tools/SdCliIndexFileGenerator.js.map +0 -1
  130. package/dist/build-tools/SdCliNgRoutesFileGenerator.d.ts +0 -4
  131. package/dist/build-tools/SdCliNgRoutesFileGenerator.js.map +0 -1
  132. package/dist/build-tools/SdLinter.d.ts +0 -5
  133. package/dist/build-tools/SdLinter.js +0 -49
  134. package/dist/build-tools/SdLinter.js.map +0 -1
  135. package/dist/build-tools/SdNgBundler.d.ts +0 -29
  136. package/dist/build-tools/SdNgBundler.js.map +0 -1
  137. package/dist/build-tools/SdNgBundlerContext.js.map +0 -1
  138. package/dist/build-tools/SdServerBundler.d.ts +0 -20
  139. package/dist/build-tools/SdServerBundler.js.map +0 -1
  140. package/dist/build-tools/SdTsCompiler.d.ts +0 -34
  141. package/dist/build-tools/SdTsCompiler.js.map +0 -1
  142. package/dist/build-tools/SdTsLibBundler.d.ts +0 -13
  143. package/dist/build-tools/SdTsLibBundler.js +0 -58
  144. package/dist/build-tools/SdTsLibBundler.js.map +0 -1
  145. package/dist/builders/SdCliClientBuilder.d.ts +0 -18
  146. package/dist/builders/SdCliClientBuilder.js +0 -151
  147. package/dist/builders/SdCliClientBuilder.js.map +0 -1
  148. package/dist/builders/SdCliJsLibLinter.d.ts +0 -13
  149. package/dist/builders/SdCliJsLibLinter.js +0 -60
  150. package/dist/builders/SdCliJsLibLinter.js.map +0 -1
  151. package/dist/builders/SdCliServerBuilder.d.ts +0 -15
  152. package/dist/builders/SdCliServerBuilder.js.map +0 -1
  153. package/dist/builders/SdCliTsLibBuilder.d.ts +0 -12
  154. package/dist/builders/SdCliTsLibBuilder.js +0 -90
  155. package/dist/builders/SdCliTsLibBuilder.js.map +0 -1
  156. package/dist/bundle-plugins/sdNgPlugin.d.ts +0 -16
  157. package/dist/bundle-plugins/sdNgPlugin.js.map +0 -1
  158. package/dist/bundle-plugins/sdServerPlugin.d.ts +0 -16
  159. package/dist/bundle-plugins/sdServerPlugin.js +0 -63
  160. package/dist/bundle-plugins/sdServerPlugin.js.map +0 -1
  161. package/dist/commons.d.ts +0 -145
  162. package/dist/commons.js +0 -2
  163. package/dist/commons.js.map +0 -1
  164. package/dist/server-worker.js +0 -57
  165. package/dist/server-worker.js.map +0 -1
  166. package/dist/utils/SdCliBuildResultUtil.d.ts +0 -16
  167. package/dist/utils/SdCliBuildResultUtil.js +0 -54
  168. package/dist/utils/SdCliBuildResultUtil.js.map +0 -1
  169. package/src/build-cluster.ts +0 -212
  170. package/src/build-tools/SdCliCordova.ts +0 -340
  171. package/src/build-tools/SdLinter.ts +0 -65
  172. package/src/build-tools/SdNgBundlerContext.ts +0 -137
  173. package/src/build-tools/SdTsCompiler.ts +0 -754
  174. package/src/build-tools/SdTsLibBundler.ts +0 -72
  175. package/src/builders/SdCliClientBuilder.ts +0 -211
  176. package/src/builders/SdCliJsLibLinter.ts +0 -72
  177. package/src/builders/SdCliTsLibBuilder.ts +0 -126
  178. package/src/bundle-plugins/sdServerPlugin.ts +0 -94
  179. package/src/commons.ts +0 -171
  180. package/src/server-worker.ts +0 -65
  181. package/src/utils/SdCliBuildResultUtil.ts +0 -63
  182. /package/dist/{build-cluster.d.ts → workers/compile-worker.d.ts} +0 -0
  183. /package/dist/{server-worker.d.ts → workers/lint-worker.d.ts} +0 -0
@@ -1,72 +0,0 @@
1
- import { SdCliBuildResultUtil } from "../utils/SdCliBuildResultUtil";
2
- import { ISdCliPackageBuildResult } from "../commons";
3
- import { SdTsCompiler } from "./SdTsCompiler";
4
- import ts from "typescript";
5
- import path from "path";
6
- import { FsUtil, PathUtil } from "@simplysm/sd-core-node";
7
-
8
- export class SdTsLibBundler {
9
- readonly #compiler: SdTsCompiler;
10
-
11
- readonly #pkgPath: string;
12
-
13
- public constructor(pkgPath: string, dev: boolean, watchScopePaths: string[]) {
14
- this.#pkgPath = pkgPath;
15
- this.#compiler = new SdTsCompiler({
16
- pkgPath,
17
- additionalOptions: { declaration: true },
18
- isDevMode: dev,
19
- globalStyleFilePath: path.resolve(pkgPath, "src/styles.scss"),
20
- isForBundle: false,
21
- watchScopePaths: watchScopePaths,
22
- });
23
- }
24
-
25
- public markChanges(modifiedFileSet: Set<string>): void {
26
- this.#compiler.invalidate(modifiedFileSet);
27
- }
28
-
29
- public async buildAsync(): Promise<{
30
- program: ts.Program;
31
- watchFileSet: Set<string>;
32
- affectedFileSet: Set<string>;
33
- results: ISdCliPackageBuildResult[];
34
- }> {
35
- const buildResult = await this.#compiler.buildAsync();
36
-
37
- for (const emitFile of buildResult.emitFileSet) {
38
- const emitFileInfos = buildResult.emittedFilesCacheMap.get(emitFile);
39
- if (emitFileInfos) {
40
- for (const emitFileInfo of emitFileInfos) {
41
- if (emitFileInfo.outAbsPath != null) {
42
- await FsUtil.writeFileAsync(emitFileInfo.outAbsPath, emitFileInfo.text);
43
- }
44
- }
45
- }
46
-
47
- const globalStylesheetBundlingResult = buildResult.stylesheetBundlingResultMap.get(emitFile);
48
- if (globalStylesheetBundlingResult) {
49
- for (const outputFile of globalStylesheetBundlingResult.outputFiles) {
50
- const distPath = path.resolve(this.#pkgPath, "dist", path.relative(this.#pkgPath, outputFile.path));
51
- if (PathUtil.isChildPath(distPath, path.resolve(this.#pkgPath, "dist"))) {
52
- await FsUtil.writeFileAsync(distPath, outputFile.text);
53
- }
54
- }
55
- }
56
- }
57
-
58
- return {
59
- program: buildResult.program,
60
- watchFileSet: buildResult.watchFileSet,
61
- affectedFileSet: buildResult.affectedFileSet,
62
- results: [
63
- ...buildResult.typescriptDiagnostics.map((item) => SdCliBuildResultUtil.convertFromTsDiag(item, "build")),
64
- ...Array.from(buildResult.stylesheetBundlingResultMap.values())
65
- .mapMany((item) => item.errors ?? [])
66
- .map((err) => SdCliBuildResultUtil.convertFromEsbuildResult(err, "build", "error")),
67
- /*...Array.from(buildResult.stylesheetResultMap.values()).mapMany(item => item.warnings!)
68
- .map(warn => SdCliBuildResultUtil.convertFromEsbuildResult(warn, "build", "warning"))*/
69
- ],
70
- };
71
- }
72
- }
@@ -1,211 +0,0 @@
1
- import { EventEmitter } from "events";
2
- import { FsUtil, Logger, PathUtil, SdFsWatcher } from "@simplysm/sd-core-node";
3
- import {
4
- INpmConfig,
5
- ISdCliBuilderResult,
6
- ISdCliClientPackageConfig,
7
- ISdCliConfig,
8
- ISdCliPackageBuildResult,
9
- } from "../commons";
10
- import { FunctionQueue } from "@simplysm/sd-core-common";
11
- import path from "path";
12
- import { SdNgBundler } from "../build-tools/SdNgBundler";
13
- import { SdCliCordova } from "../build-tools/SdCliCordova";
14
- import { SdCliNgRoutesFileGenerator } from "../build-tools/SdCliNgRoutesFileGenerator";
15
- import { SdLinter } from "../build-tools/SdLinter";
16
- import { SdCliElectron } from "../entry/SdCliElectron";
17
-
18
- // import ts from "typescript";
19
-
20
- export class SdCliClientBuilder extends EventEmitter {
21
- private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliClientBuilder"]);
22
- private readonly _pkgConf: ISdCliClientPackageConfig;
23
- private readonly _npmConf: INpmConfig;
24
- private _builders?: SdNgBundler[];
25
- private _cordova?: SdCliCordova;
26
-
27
- // #program?: ts.Program;
28
-
29
- public constructor(
30
- private readonly _projConf: ISdCliConfig,
31
- private readonly _pkgPath: string,
32
- ) {
33
- super();
34
- this._pkgConf = this._projConf.packages[path.basename(_pkgPath)] as ISdCliClientPackageConfig;
35
- this._npmConf = FsUtil.readJson(path.resolve(_pkgPath, "package.json")) as INpmConfig;
36
- }
37
-
38
- public override on(event: "change", listener: () => void): this;
39
- public override on(event: "complete", listener: (result: ISdCliBuilderResult) => void): this;
40
- public override on(event: string | symbol, listener: (...args: any[]) => void): this {
41
- super.on(event, listener);
42
- return this;
43
- }
44
-
45
- public async buildAsync(): Promise<ISdCliBuilderResult> {
46
- this._debug("dist 초기화...");
47
- await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
48
-
49
- if (this._npmConf.dependencies && Object.keys(this._npmConf.dependencies).includes("@angular/router")) {
50
- this._debug(`GEN routes.ts...`);
51
- await SdCliNgRoutesFileGenerator.runAsync(this._pkgPath, undefined, this._pkgConf.noLazyRoute);
52
- }
53
-
54
- this._debug("GEN .config...");
55
- const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
56
- await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
57
-
58
- const result = await this._runAsync({ dev: false });
59
- return {
60
- affectedFilePaths: Array.from(result.affectedFileSet),
61
- buildResults: result.buildResults,
62
- };
63
- }
64
-
65
- public async watchAsync() {
66
- this.emit("change");
67
-
68
- this._debug("dist 초기화...");
69
- await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
70
-
71
- if (this._npmConf.dependencies && Object.keys(this._npmConf.dependencies).includes("@angular/router")) {
72
- this._debug(`WATCH GEN routes.ts...`);
73
- await SdCliNgRoutesFileGenerator.watchAsync(this._pkgPath, this._pkgConf.noLazyRoute);
74
- }
75
-
76
- this._debug("GEN .config...");
77
- const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
78
- await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
79
-
80
- const result = await this._runAsync({ dev: !this._pkgConf.forceProductionMode });
81
- this.emit("complete", {
82
- affectedFilePaths: Array.from(result.affectedFileSet),
83
- buildResults: result.buildResults,
84
- });
85
-
86
- this._debug("WATCH...");
87
- let changeFiles: string[] = [];
88
- const fnQ = new FunctionQueue();
89
- const watcher = SdFsWatcher.watch(Array.from(result.watchFileSet)).onChange({ delay: 100 }, (changeInfos) => {
90
- changeFiles.push(...changeInfos.map((item) => item.path));
91
-
92
- fnQ.runLast(async () => {
93
- const currChangeFiles = [...changeFiles];
94
- changeFiles = [];
95
-
96
- this.emit("change");
97
-
98
- for (const builder of this._builders!) {
99
- // builder.removeCache(currChangeFiles);
100
- builder.markForChanges(currChangeFiles);
101
- }
102
-
103
- const watchResult = await this._runAsync({ dev: !this._pkgConf.forceProductionMode });
104
- this.emit("complete", {
105
- affectedFilePaths: Array.from(watchResult.affectedFileSet),
106
- buildResults: watchResult.buildResults,
107
- });
108
-
109
- watcher.add(watchResult.watchFileSet);
110
- });
111
- });
112
- }
113
-
114
- private async _runAsync(opt: { dev: boolean }): Promise<{
115
- watchFileSet: Set<string>;
116
- affectedFileSet: Set<string>;
117
- buildResults: ISdCliPackageBuildResult[];
118
- }> {
119
- const localUpdatePaths = Object.keys(this._projConf.localUpdates ?? {}).mapMany((key) =>
120
- FsUtil.glob(path.resolve(this._pkgPath, "../../node_modules", key)),
121
- );
122
-
123
- const builderTypes = Object.keys(this._pkgConf.builder ?? { web: {} }) as ("web" | "electron" | "cordova")[];
124
- if (this._pkgConf.builder?.cordova && !this._cordova) {
125
- this._debug("CORDOVA 준비...");
126
- this._cordova = new SdCliCordova({
127
- pkgPath: this._pkgPath,
128
- config: this._pkgConf.builder.cordova,
129
- });
130
- await this._cordova.initializeAsync();
131
- }
132
-
133
- if (!this._builders) {
134
- this._debug(`BUILD 준비...`);
135
-
136
- this._builders = builderTypes.map(
137
- (builderType) =>
138
- new SdNgBundler({
139
- dev: opt.dev,
140
- builderType: builderType,
141
- pkgPath: this._pkgPath,
142
- outputPath:
143
- builderType === "web"
144
- ? path.resolve(this._pkgPath, "dist")
145
- : builderType === "electron" && !opt.dev
146
- ? path.resolve(this._pkgPath, ".electron/src")
147
- : builderType === "cordova" && !opt.dev
148
- ? path.resolve(this._pkgPath, ".cordova/www")
149
- : path.resolve(this._pkgPath, "dist", builderType),
150
- env: {
151
- ...this._pkgConf.env,
152
- ...this._pkgConf.builder?.[builderType]?.env,
153
- },
154
- cordovaConfig: builderType === "cordova" ? this._pkgConf.builder!.cordova : undefined,
155
- watchScopePaths: [path.resolve(this._pkgPath, "../"), ...localUpdatePaths],
156
- }),
157
- );
158
- }
159
-
160
- this._debug(`BUILD & CHECK...`);
161
- const buildResults = await Promise.all(this._builders.map((builder) => builder.bundleAsync()));
162
- const watchFileSet = new Set(buildResults.mapMany((item) => Array.from(item.watchFileSet)));
163
- const affectedFileSet = new Set(buildResults.mapMany((item) => Array.from(item.affectedFileSet)));
164
- const results = buildResults.mapMany((item) => item.results).distinct();
165
- const firstProgram = buildResults.first()?.program;
166
-
167
- this._debug(`LINT...`);
168
- // const tsConfig = FsUtil.readJson(path.resolve(this._pkgPath, "tsconfig.json")) as ITsConfig;
169
- // const parsedTsConfig = ts.parseJsonConfigFileContent(tsConfig, ts.sys, this._pkgPath);
170
- // this.#program = ts.createProgram({
171
- // rootNames: parsedTsConfig.fileNames,
172
- // options: parsedTsConfig.options,
173
- // oldProgram: this.#program
174
- // });
175
- // const pkgFilePaths = filePaths.filter(item => PathUtil.isChildPath(item, this._pkgPath));
176
- const lintResults = await SdLinter.lintAsync(this._pkgPath, affectedFileSet, firstProgram);
177
-
178
- if (!opt.dev && this._cordova) {
179
- this._debug("CORDOVA BUILD...");
180
- await this._cordova.buildAsync(path.resolve(this._pkgPath, "dist"));
181
- }
182
-
183
- if (!opt.dev && this._pkgConf.builder?.electron) {
184
- this._debug("ELECTRON BUILD...");
185
- await SdCliElectron.buildAsync({
186
- pkgPath: this._pkgPath,
187
- config: this._pkgConf.builder.electron,
188
- });
189
- }
190
-
191
- this._debug(`빌드 완료`);
192
- const currWatchFileSet = new Set(
193
- Array.from(watchFileSet).filter(
194
- (item) =>
195
- PathUtil.isChildPath(item, path.resolve(this._pkgPath, "../")) ||
196
- localUpdatePaths.some((lu) => PathUtil.isChildPath(item, lu)),
197
- ),
198
- );
199
- return {
200
- watchFileSet: currWatchFileSet,
201
- affectedFileSet,
202
- buildResults: [...results, ...lintResults].filter(
203
- (item) => item.filePath !== path.resolve(this._pkgPath, "src/routes.ts"),
204
- ),
205
- };
206
- }
207
-
208
- private _debug(msg: string): void {
209
- this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
210
- }
211
- }
@@ -1,72 +0,0 @@
1
- import {FsUtil, Logger, SdFsWatcher} from "@simplysm/sd-core-node";
2
- import path from "path";
3
- import {ISdCliBuilderResult} from "../commons";
4
- import {EventEmitter} from "events";
5
- import {SdLinter} from "../build-tools/SdLinter";
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: ISdCliBuilderResult) => 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<ISdCliBuilderResult> {
24
- this._debug("LINT...");
25
- const srcGlobPath = path.resolve(this._pkgPath, "src/**/*.js");
26
- const srcFilePaths = await FsUtil.globAsync(srcGlobPath);
27
- const lintResults = await SdLinter.lintAsync(this._pkgPath, new Set(srcFilePaths), undefined);
28
-
29
- this._debug(`LINT 완료`);
30
- return {
31
- affectedFilePaths: srcFilePaths,
32
- buildResults: lintResults
33
- };
34
- }
35
-
36
- public async watchAsync(): Promise<void> {
37
- this.emit("change");
38
- this._debug("LINT...");
39
- const srcGlobPath = path.resolve(this._pkgPath, "src/**/*.js");
40
- const srcFilePaths = await FsUtil.globAsync(srcGlobPath);
41
- const lintResults = await SdLinter.lintAsync(this._pkgPath, new Set(srcFilePaths), undefined);
42
-
43
- this._debug(`LINT 완료`);
44
- this.emit("complete", {
45
- affectedFilePaths: srcFilePaths,
46
- buildResults: lintResults
47
- });
48
-
49
- SdFsWatcher
50
- .watch([srcGlobPath])
51
- .onChange({
52
- delay: 100
53
- }, async (changeInfos) => {
54
- const watchFilePaths = changeInfos.filter((item) => FsUtil.exists(item.path)).map((item) => item.path);
55
- if (watchFilePaths.length < 1) return;
56
-
57
- this.emit("change");
58
- this._debug("LINT...");
59
- const watchLintResults = await SdLinter.lintAsync(this._pkgPath, new Set(watchFilePaths), undefined);
60
-
61
- this._debug(`LINT 완료`);
62
- this.emit("complete", {
63
- affectedFilePaths: changeInfos.map((item) => item.path),
64
- buildResults: watchLintResults
65
- });
66
- });
67
- }
68
-
69
- private _debug(msg: string): void {
70
- this._logger.debug(`[${this._pkgName}] ${msg}`);
71
- }
72
- }
@@ -1,126 +0,0 @@
1
- import { FsUtil, Logger, PathUtil, SdFsWatcher } from "@simplysm/sd-core-node";
2
- import path from "path";
3
- import { ISdCliBuilderResult, ISdCliConfig, ISdCliLibPackageConfig, ISdCliPackageBuildResult } from "../commons";
4
- import { EventEmitter } from "events";
5
- import { SdTsLibBundler } from "../build-tools/SdTsLibBundler";
6
- import { SdLinter } from "../build-tools/SdLinter";
7
- import { FunctionQueue } from "@simplysm/sd-core-common";
8
- import { SdCliIndexFileGenerator } from "../build-tools/SdCliIndexFileGenerator";
9
-
10
- export class SdCliTsLibBuilder extends EventEmitter {
11
- readonly #logger = Logger.get(["simplysm", "sd-cli", "SdCliTsLibBuilder"]);
12
-
13
- readonly #projConf: ISdCliConfig;
14
- readonly #pkgPath: string;
15
- readonly #pkgConf: ISdCliLibPackageConfig;
16
-
17
- #bundler?: SdTsLibBundler;
18
-
19
- public constructor(projConf: ISdCliConfig, pkgPath: string) {
20
- super();
21
- this.#projConf = projConf;
22
- this.#pkgPath = pkgPath;
23
-
24
- this.#pkgConf = projConf.packages[path.basename(pkgPath)] as ISdCliLibPackageConfig;
25
- }
26
-
27
- public override on(event: "change", listener: () => void): this;
28
- public override on(event: "complete", listener: (result: ISdCliBuilderResult) => void): this;
29
- public override on(event: string | symbol, listener: (...args: any[]) => void): this {
30
- super.on(event, listener);
31
- return this;
32
- }
33
-
34
- public async buildAsync(): Promise<ISdCliBuilderResult> {
35
- this._debug("dist 초기화...");
36
- await FsUtil.removeAsync(path.resolve(this.#pkgPath, "dist"));
37
-
38
- if (!this.#pkgConf.noGenIndex) {
39
- this._debug("GEN index.ts...");
40
- await SdCliIndexFileGenerator.runAsync(this.#pkgPath, this.#pkgConf.polyfills);
41
- }
42
-
43
- const result = await this._runAsync(false);
44
- return {
45
- affectedFilePaths: Array.from(result.affectedFileSet),
46
- buildResults: result.buildResults,
47
- };
48
- }
49
-
50
- public async watchAsync(): Promise<void> {
51
- this.emit("change");
52
-
53
- this._debug("dist 초기화...");
54
- await FsUtil.removeAsync(path.resolve(this.#pkgPath, "dist"));
55
-
56
- if (!this.#pkgConf.noGenIndex) {
57
- this._debug("WATCH GEN index.ts...");
58
- await SdCliIndexFileGenerator.watchAsync(this.#pkgPath, this.#pkgConf.polyfills);
59
- }
60
-
61
- const result = await this._runAsync(true);
62
- this.emit("complete", {
63
- affectedFilePaths: Array.from(result.affectedFileSet),
64
- buildResults: result.buildResults,
65
- });
66
-
67
- this._debug("WATCH...");
68
- const fnQ = new FunctionQueue();
69
- const watcher = SdFsWatcher.watch(Array.from(result.watchFileSet)).onChange({ delay: 100 }, (changeInfos) => {
70
- this.#bundler!.markChanges(new Set(changeInfos.map((item) => item.path)));
71
-
72
- fnQ.runLast(async () => {
73
- this.emit("change");
74
-
75
- const watchResult = await this._runAsync(true);
76
- this.emit("complete", {
77
- affectedFilePaths: Array.from(watchResult.affectedFileSet),
78
- buildResults: watchResult.buildResults,
79
- });
80
-
81
- watcher.add(watchResult.watchFileSet);
82
- });
83
- });
84
- }
85
-
86
- private async _runAsync(dev: boolean): Promise<{
87
- watchFileSet: Set<string>;
88
- affectedFileSet: Set<string>;
89
- buildResults: ISdCliPackageBuildResult[];
90
- }> {
91
- const localUpdatePaths = Object.keys(this.#projConf.localUpdates ?? {}).mapMany((key) =>
92
- FsUtil.glob(path.resolve(this.#pkgPath, "../../node_modules", key)),
93
- );
94
-
95
- this._debug(`BUILD...`);
96
- this.#bundler =
97
- this.#bundler ??
98
- new SdTsLibBundler(this.#pkgPath, dev, [path.resolve(this.#pkgPath, "../"), ...localUpdatePaths]);
99
- const buildResult = await this.#bundler.buildAsync();
100
-
101
- this._debug("LINT...");
102
- /*const lintFilePaths = Array.from(buildResult.affectedFileSet).filter((item) =>
103
- PathUtil.isChildPath(item, this.#pkgPath),
104
- );*/
105
- const lintResults = await SdLinter.lintAsync(this.#pkgPath, buildResult.affectedFileSet, buildResult.program);
106
-
107
- this._debug(`빌드 완료`);
108
- const watchFileSet = new Set(
109
- Array.from(buildResult.watchFileSet).filter(
110
- (item) =>
111
- PathUtil.isChildPath(item, path.resolve(this.#pkgPath, "../")) ||
112
- localUpdatePaths.some((lu) => PathUtil.isChildPath(item, lu)),
113
- ),
114
- );
115
-
116
- return {
117
- watchFileSet,
118
- affectedFileSet: buildResult.affectedFileSet,
119
- buildResults: [...buildResult.results, ...lintResults],
120
- };
121
- }
122
-
123
- private _debug(msg: string): void {
124
- this.#logger.debug(`[${path.basename(this.#pkgPath)}] ${msg}`);
125
- }
126
- }
@@ -1,94 +0,0 @@
1
- import esbuild from "esbuild";
2
- import ts from "typescript";
3
- import path from "path";
4
- import { ISdTsCompilerResult, SdTsCompiler } from "../build-tools/SdTsCompiler";
5
- import { convertTypeScriptDiagnostic } from "@angular/build/src/tools/esbuild/angular/diagnostics";
6
-
7
- export function sdServerPlugin(conf: {
8
- pkgPath: string;
9
- dev: boolean;
10
- modifiedFileSet: Set<string>;
11
- result: IServerPluginResultCache;
12
- watchScopePaths: string[];
13
- }): esbuild.Plugin {
14
- return {
15
- name: "sd-server-compiler",
16
- setup: (build: esbuild.PluginBuild) => {
17
- const compiler = new SdTsCompiler({
18
- pkgPath: conf.pkgPath,
19
- additionalOptions: { declaration: false },
20
- isDevMode: conf.dev,
21
- isForBundle: true,
22
- watchScopePaths: conf.watchScopePaths
23
- });
24
-
25
- let buildResult: ISdTsCompilerResult;
26
-
27
- build.onStart(async () => {
28
- compiler.invalidate(conf.modifiedFileSet);
29
- buildResult = await compiler.buildAsync();
30
-
31
- conf.result.watchFileSet = buildResult.watchFileSet;
32
- conf.result.affectedFileSet = buildResult.affectedFileSet;
33
- conf.result.program = buildResult.program;
34
-
35
- //-- return err/warn
36
-
37
- return {
38
- errors: buildResult.typescriptDiagnostics
39
- .filter((item) => item.category === ts.DiagnosticCategory.Error)
40
- .map((item) => convertTypeScriptDiagnostic(ts, item)),
41
- warnings: buildResult.typescriptDiagnostics
42
- .filter((item) => item.category !== ts.DiagnosticCategory.Error)
43
- .map((item) => convertTypeScriptDiagnostic(ts, item)),
44
- };
45
- });
46
-
47
- build.onLoad({ filter: /\.ts$/ }, (args) => {
48
- const emittedJsFile = buildResult.emittedFilesCacheMap.get(path.normalize(args.path))?.last();
49
- if (!emittedJsFile) {
50
- throw new Error(`ts 빌더 결과 emit 파일이 존재하지 않습니다. ${args.path}`);
51
- }
52
-
53
- const contents = emittedJsFile.text;
54
- return { contents, loader: "js" };
55
- });
56
-
57
- build.onLoad({ filter: /\.[cm]?js$/ }, (args) => {
58
- conf.result.watchFileSet!.add(path.normalize(args.path));
59
- return null;
60
- });
61
-
62
- build.onLoad(
63
- {
64
- filter: new RegExp(
65
- "(" +
66
- Object.keys(build.initialOptions.loader!)
67
- .map((item) => "\\" + item)
68
- .join("|") +
69
- ")$",
70
- ),
71
- },
72
- (args) => {
73
- conf.result.watchFileSet!.add(path.normalize(args.path));
74
- return null;
75
- },
76
- );
77
-
78
- build.onEnd((result) => {
79
- conf.result.outputFiles = result.outputFiles;
80
- conf.result.metafile = result.metafile;
81
-
82
- conf.modifiedFileSet.clear();
83
- });
84
- },
85
- };
86
- }
87
-
88
- export interface IServerPluginResultCache {
89
- watchFileSet?: Set<string>;
90
- affectedFileSet?: Set<string>;
91
- outputFiles?: esbuild.OutputFile[];
92
- metafile?: esbuild.Metafile;
93
- program?: ts.Program;
94
- }