@simplysm/sd-cli 6.4.6 → 7.0.12

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 (185) hide show
  1. package/.eslintrc.cjs +11 -0
  2. package/dist/bin/sd-cli.d.ts +1 -0
  3. package/dist/bin/sd-cli.mjs +86 -0
  4. package/dist/build-tool/SdCliCacheCompilerHost.d.ts +10 -0
  5. package/dist/build-tool/SdCliCacheCompilerHost.mjs +44 -0
  6. package/dist/build-tool/SdCliNgCacheCompilerHost.d.ts +11 -0
  7. package/dist/build-tool/SdCliNgCacheCompilerHost.mjs +36 -0
  8. package/dist/build-tool/SdCliPackageLinter.d.ts +8 -0
  9. package/dist/build-tool/SdCliPackageLinter.mjs +41 -0
  10. package/dist/builder/SdCliJsLibBuilder.d.ts +14 -0
  11. package/dist/builder/SdCliJsLibBuilder.mjs +50 -0
  12. package/dist/builder/SdCliTsLibBuilder.d.ts +27 -0
  13. package/dist/builder/SdCliTsLibBuilder.mjs +226 -0
  14. package/dist/commons.d.ts +46 -0
  15. package/dist/commons.mjs +2 -0
  16. package/dist/entry-points/SdCliWorkspace.d.ts +18 -0
  17. package/dist/entry-points/SdCliWorkspace.mjs +193 -0
  18. package/dist/packages/SdCliPackage.d.ts +19 -0
  19. package/dist/packages/SdCliPackage.mjs +89 -0
  20. package/dist/utils/SdCliBuildResultUtil.d.ts +6 -0
  21. package/dist/utils/SdCliBuildResultUtil.mjs +38 -0
  22. package/dist/utils/SdCliConfigUtil.d.ts +7 -0
  23. package/dist/utils/SdCliConfigUtil.mjs +69 -0
  24. package/lib/ts-node-esm-paths.mjs +15 -0
  25. package/package.json +27 -59
  26. package/src/bin/sd-cli.ts +86 -214
  27. package/src/build-tool/SdCliCacheCompilerHost.ts +71 -0
  28. package/src/build-tool/SdCliNgCacheCompilerHost.ts +50 -0
  29. package/src/build-tool/SdCliPackageLinter.ts +54 -0
  30. package/src/builder/SdCliJsLibBuilder.ts +66 -0
  31. package/src/builder/SdCliTsLibBuilder.ts +335 -0
  32. package/src/commons.ts +17 -122
  33. package/src/entry-points/SdCliWorkspace.ts +229 -0
  34. package/src/packages/SdCliPackage.ts +111 -0
  35. package/src/utils/SdCliBuildResultUtil.ts +43 -0
  36. package/src/utils/SdCliConfigUtil.ts +94 -0
  37. package/tsconfig-build.json +9 -0
  38. package/tsconfig.json +7 -18
  39. package/.eslintrc.js +0 -19
  40. package/dist-node/bin/sd-cli.js +0 -197
  41. package/dist-node/bin/sd-cli.js.map +0 -1
  42. package/dist-node/build-tools/SdCliCordova.js +0 -145
  43. package/dist-node/build-tools/SdCliCordova.js.map +0 -1
  44. package/dist-node/build-tools/SdCliIndexFileGenerator.js +0 -51
  45. package/dist-node/build-tools/SdCliIndexFileGenerator.js.map +0 -1
  46. package/dist-node/build-tools/SdCliNgModuleFilesGenerator.js +0 -675
  47. package/dist-node/build-tools/SdCliNgModuleFilesGenerator.js.map +0 -1
  48. package/dist-node/build-tools/metadata/SdAotMetadataReader.js +0 -274
  49. package/dist-node/build-tools/metadata/SdAotMetadataReader.js.map +0 -1
  50. package/dist-node/build-tools/metadata/SdIvyMetadataReader.js +0 -124
  51. package/dist-node/build-tools/metadata/SdIvyMetadataReader.js.map +0 -1
  52. package/dist-node/build-tools/metadata/SdMetadataError.js +0 -13
  53. package/dist-node/build-tools/metadata/SdMetadataError.js.map +0 -1
  54. package/dist-node/build-tools/metadata/SdMyMetadataReader.js +0 -321
  55. package/dist-node/build-tools/metadata/SdMyMetadataReader.js.map +0 -1
  56. package/dist-node/builders/SdCliJavascriptLinter.js +0 -65
  57. package/dist-node/builders/SdCliJavascriptLinter.js.map +0 -1
  58. package/dist-node/builders/SdCliNgClientBuilder.js +0 -636
  59. package/dist-node/builders/SdCliNgClientBuilder.js.map +0 -1
  60. package/dist-node/builders/SdCliNgLibraryBuilder.js +0 -217
  61. package/dist-node/builders/SdCliNgLibraryBuilder.js.map +0 -1
  62. package/dist-node/builders/SdCliPublisher.js +0 -129
  63. package/dist-node/builders/SdCliPublisher.js.map +0 -1
  64. package/dist-node/builders/SdCliServerBuilder.js +0 -452
  65. package/dist-node/builders/SdCliServerBuilder.js.map +0 -1
  66. package/dist-node/builders/SdCliTypescriptBuilder.js +0 -347
  67. package/dist-node/builders/SdCliTypescriptBuilder.js.map +0 -1
  68. package/dist-node/commons.js +0 -3
  69. package/dist-node/commons.js.map +0 -1
  70. package/dist-node/entry-points/SdCliLocalUpdater.js +0 -88
  71. package/dist-node/entry-points/SdCliLocalUpdater.js.map +0 -1
  72. package/dist-node/entry-points/SdCliPrepare.js +0 -56
  73. package/dist-node/entry-points/SdCliPrepare.js.map +0 -1
  74. package/dist-node/entry-points/SdCliProject.js +0 -302
  75. package/dist-node/entry-points/SdCliProject.js.map +0 -1
  76. package/dist-node/packages/SdCliClientPackage.js +0 -91
  77. package/dist-node/packages/SdCliClientPackage.js.map +0 -1
  78. package/dist-node/packages/SdCliLibraryPackage.js +0 -99
  79. package/dist-node/packages/SdCliLibraryPackage.js.map +0 -1
  80. package/dist-node/packages/SdCliPackageBase.js +0 -33
  81. package/dist-node/packages/SdCliPackageBase.js.map +0 -1
  82. package/dist-node/packages/SdCliServerPackage.js +0 -69
  83. package/dist-node/packages/SdCliServerPackage.js.map +0 -1
  84. package/dist-node/packages/SdCliUnknownPackage.js +0 -15
  85. package/dist-node/packages/SdCliUnknownPackage.js.map +0 -1
  86. package/dist-node/utils/SdCliFileCrypto.js +0 -76
  87. package/dist-node/utils/SdCliFileCrypto.js.map +0 -1
  88. package/dist-node/utils/SdProjectConfigUtil.js +0 -62
  89. package/dist-node/utils/SdProjectConfigUtil.js.map +0 -1
  90. package/dist-node/utils/SdTsDiagnosticUtil.js +0 -45
  91. package/dist-node/utils/SdTsDiagnosticUtil.js.map +0 -1
  92. package/dist-node/utils/SdWebpackUtil.js +0 -63
  93. package/dist-node/utils/SdWebpackUtil.js.map +0 -1
  94. package/dist-node/workers/client-ng-gen-worker.js +0 -57
  95. package/dist-node/workers/client-ng-gen-worker.js.map +0 -1
  96. package/dist-node/workers/lib-build-worker.js +0 -88
  97. package/dist-node/workers/lib-build-worker.js.map +0 -1
  98. package/dist-types/bin/sd-cli.d.ts +0 -3
  99. package/dist-types/bin/sd-cli.d.ts.map +0 -1
  100. package/dist-types/build-tools/SdCliCordova.d.ts +0 -15
  101. package/dist-types/build-tools/SdCliCordova.d.ts.map +0 -1
  102. package/dist-types/build-tools/SdCliIndexFileGenerator.d.ts +0 -13
  103. package/dist-types/build-tools/SdCliIndexFileGenerator.d.ts.map +0 -1
  104. package/dist-types/build-tools/SdCliNgModuleFilesGenerator.d.ts +0 -43
  105. package/dist-types/build-tools/SdCliNgModuleFilesGenerator.d.ts.map +0 -1
  106. package/dist-types/build-tools/metadata/SdAotMetadataReader.d.ts +0 -58
  107. package/dist-types/build-tools/metadata/SdAotMetadataReader.d.ts.map +0 -1
  108. package/dist-types/build-tools/metadata/SdIvyMetadataReader.d.ts +0 -43
  109. package/dist-types/build-tools/metadata/SdIvyMetadataReader.d.ts.map +0 -1
  110. package/dist-types/build-tools/metadata/SdMetadataError.d.ts +0 -7
  111. package/dist-types/build-tools/metadata/SdMetadataError.d.ts.map +0 -1
  112. package/dist-types/build-tools/metadata/SdMyMetadataReader.d.ts +0 -59
  113. package/dist-types/build-tools/metadata/SdMyMetadataReader.d.ts.map +0 -1
  114. package/dist-types/builders/SdCliJavascriptLinter.d.ts +0 -14
  115. package/dist-types/builders/SdCliJavascriptLinter.d.ts.map +0 -1
  116. package/dist-types/builders/SdCliNgClientBuilder.d.ts +0 -29
  117. package/dist-types/builders/SdCliNgClientBuilder.d.ts.map +0 -1
  118. package/dist-types/builders/SdCliNgLibraryBuilder.d.ts +0 -30
  119. package/dist-types/builders/SdCliNgLibraryBuilder.d.ts.map +0 -1
  120. package/dist-types/builders/SdCliPublisher.d.ts +0 -9
  121. package/dist-types/builders/SdCliPublisher.d.ts.map +0 -1
  122. package/dist-types/builders/SdCliServerBuilder.d.ts +0 -31
  123. package/dist-types/builders/SdCliServerBuilder.d.ts.map +0 -1
  124. package/dist-types/builders/SdCliTypescriptBuilder.d.ts +0 -56
  125. package/dist-types/builders/SdCliTypescriptBuilder.d.ts.map +0 -1
  126. package/dist-types/commons.d.ts +0 -134
  127. package/dist-types/commons.d.ts.map +0 -1
  128. package/dist-types/entry-points/SdCliLocalUpdater.d.ts +0 -12
  129. package/dist-types/entry-points/SdCliLocalUpdater.d.ts.map +0 -1
  130. package/dist-types/entry-points/SdCliPrepare.d.ts +0 -6
  131. package/dist-types/entry-points/SdCliPrepare.d.ts.map +0 -1
  132. package/dist-types/entry-points/SdCliProject.d.ts +0 -32
  133. package/dist-types/entry-points/SdCliProject.d.ts.map +0 -1
  134. package/dist-types/packages/SdCliClientPackage.d.ts +0 -17
  135. package/dist-types/packages/SdCliClientPackage.d.ts.map +0 -1
  136. package/dist-types/packages/SdCliLibraryPackage.d.ts +0 -20
  137. package/dist-types/packages/SdCliLibraryPackage.d.ts.map +0 -1
  138. package/dist-types/packages/SdCliPackageBase.d.ts +0 -11
  139. package/dist-types/packages/SdCliPackageBase.d.ts.map +0 -1
  140. package/dist-types/packages/SdCliServerPackage.d.ts +0 -16
  141. package/dist-types/packages/SdCliServerPackage.d.ts.map +0 -1
  142. package/dist-types/packages/SdCliUnknownPackage.d.ts +0 -9
  143. package/dist-types/packages/SdCliUnknownPackage.d.ts.map +0 -1
  144. package/dist-types/utils/SdCliFileCrypto.d.ts +0 -8
  145. package/dist-types/utils/SdCliFileCrypto.d.ts.map +0 -1
  146. package/dist-types/utils/SdProjectConfigUtil.d.ts +0 -7
  147. package/dist-types/utils/SdProjectConfigUtil.d.ts.map +0 -1
  148. package/dist-types/utils/SdTsDiagnosticUtil.d.ts +0 -6
  149. package/dist-types/utils/SdTsDiagnosticUtil.d.ts.map +0 -1
  150. package/dist-types/utils/SdWebpackUtil.d.ts +0 -7
  151. package/dist-types/utils/SdWebpackUtil.d.ts.map +0 -1
  152. package/dist-types/workers/client-ng-gen-worker.d.ts +0 -2
  153. package/dist-types/workers/client-ng-gen-worker.d.ts.map +0 -1
  154. package/dist-types/workers/lib-build-worker.d.ts +0 -2
  155. package/dist-types/workers/lib-build-worker.d.ts.map +0 -1
  156. package/schema/schema.json +0 -447
  157. package/sd-tsconfig.node.json +0 -18
  158. package/src/build-tools/SdCliCordova.ts +0 -242
  159. package/src/build-tools/SdCliIndexFileGenerator.ts +0 -61
  160. package/src/build-tools/SdCliNgModuleFilesGenerator.ts +0 -894
  161. package/src/build-tools/metadata/SdAotMetadataReader.ts +0 -374
  162. package/src/build-tools/metadata/SdIvyMetadataReader.ts +0 -183
  163. package/src/build-tools/metadata/SdMetadataError.ts +0 -7
  164. package/src/build-tools/metadata/SdMyMetadataReader.ts +0 -407
  165. package/src/builders/SdCliJavascriptLinter.ts +0 -81
  166. package/src/builders/SdCliNgClientBuilder.ts +0 -793
  167. package/src/builders/SdCliNgLibraryBuilder.ts +0 -301
  168. package/src/builders/SdCliPublisher.ts +0 -144
  169. package/src/builders/SdCliServerBuilder.ts +0 -555
  170. package/src/builders/SdCliTypescriptBuilder.ts +0 -552
  171. package/src/entry-points/SdCliLocalUpdater.ts +0 -114
  172. package/src/entry-points/SdCliPrepare.ts +0 -104
  173. package/src/entry-points/SdCliProject.ts +0 -405
  174. package/src/packages/SdCliClientPackage.ts +0 -111
  175. package/src/packages/SdCliLibraryPackage.ts +0 -118
  176. package/src/packages/SdCliPackageBase.ts +0 -34
  177. package/src/packages/SdCliServerPackage.ts +0 -85
  178. package/src/packages/SdCliUnknownPackage.ts +0 -14
  179. package/src/utils/SdCliFileCrypto.ts +0 -87
  180. package/src/utils/SdCliUtils.ts +0 -56
  181. package/src/utils/SdProjectConfigUtil.ts +0 -145
  182. package/src/utils/SdTsDiagnosticUtil.ts +0 -46
  183. package/src/utils/SdWebpackUtil.ts +0 -71
  184. package/src/workers/client-ng-gen-worker.ts +0 -63
  185. package/src/workers/lib-build-worker.ts +0 -97
@@ -0,0 +1,229 @@
1
+ import { FsUtil, Logger, SdProcess } from "@simplysm/sd-core-node";
2
+ import path from "path";
3
+ import { INpmConfig, ISdCliConfig, ISdCliPackageBuildResult } from "../commons";
4
+ import { SdCliPackage } from "../packages/SdCliPackage";
5
+ import { Wait } from "@simplysm/sd-core-common";
6
+ import os from "os";
7
+ import { SdCliBuildResultUtil } from "../utils/SdCliBuildResultUtil";
8
+ import semver from "semver/preload";
9
+
10
+ export class SdCliWorkspace {
11
+ private readonly _logger = Logger.get(["simplysm", "sd-cli", this.constructor.name]);
12
+
13
+ private readonly _npmConfig: INpmConfig;
14
+ private readonly _config: ISdCliConfig;
15
+
16
+ public constructor(private readonly _rootPath: string,
17
+ private readonly _configFilePath?: string) {
18
+ const npmConfigFilePath = path.resolve(this._rootPath, "package.json");
19
+ this._npmConfig = FsUtil.readJson(npmConfigFilePath);
20
+
21
+ this._config = FsUtil.readJson(path.resolve(this._rootPath, this._configFilePath ?? "simplysm.json"));
22
+ }
23
+
24
+ public async watchAsync(): Promise<void> {
25
+ this._logger.debug("패키지 목록 구성...");
26
+ const pkgs = await this._getPackagesAsync();
27
+
28
+ this._logger.debug("패키지 이벤트 설정...");
29
+ let changeCount = 0;
30
+ const totalResultMap = new Map<string, ISdCliPackageBuildResult[]>();
31
+ for (const pkg of pkgs) {
32
+ pkg
33
+ .on("change", () => {
34
+ if (changeCount === 0) {
35
+ this._logger.log("빌드를 시작합니다...");
36
+ }
37
+ changeCount++;
38
+ this._logger.debug(`[${pkg.name}] 빌드를 시작합니다...`);
39
+ })
40
+ .on("complete", (results) => {
41
+ this._logger.debug(`[${pkg.name}] 빌드가 완료되었습니다.`);
42
+ totalResultMap.set(pkg.name, results);
43
+
44
+ setTimeout(() => {
45
+ changeCount--;
46
+ if (changeCount === 0) {
47
+ this._loggingResults(totalResultMap);
48
+ this._logger.info("모든 빌드가 완료되었습니다.");
49
+ }
50
+ }, 500);
51
+ });
52
+ }
53
+
54
+ this._logger.debug("빌드를 시작합니다...");
55
+ const pkgNames = pkgs.map((item) => item.name);
56
+ const buildCompletedPackageNames: string[] = [];
57
+ await pkgs.parallelAsync(async (pkg) => {
58
+ await Wait.until(() => !pkg.allDependencies.some((dep) => pkgNames.includes(dep) && !buildCompletedPackageNames.includes(dep)));
59
+ await pkg.watchAsync();
60
+ buildCompletedPackageNames.push(pkg.name);
61
+ });
62
+ }
63
+
64
+ public async buildAsync(): Promise<void> {
65
+ this._logger.debug("패키지 목록 구성...");
66
+ const pkgs = await this._getPackagesAsync();
67
+
68
+ this._logger.debug("프로젝트 및 패키지 버전 설정...");
69
+ await this._upgradeVersionAsync(pkgs);
70
+
71
+ // 빌드
72
+ await this._buildPkgsAsync(pkgs);
73
+ }
74
+
75
+ private async _buildPkgsAsync(pkgs: SdCliPackage[]): Promise<void> {
76
+ this._logger.debug("빌드를 시작합니다...");
77
+ const pkgNames = pkgs.map((item) => item.name);
78
+ const buildCompletedPackageNames: string[] = [];
79
+ const totalResultMap = new Map<string, ISdCliPackageBuildResult[]>();
80
+ await pkgs.parallelAsync(async (pkg) => {
81
+ await Wait.until(() => !pkg.allDependencies.some((dep) => pkgNames.includes(dep) && !buildCompletedPackageNames.includes(dep)));
82
+
83
+ this._logger.debug(`[${pkg.name}] 빌드를 시작합니다...`);
84
+ totalResultMap.set(pkg.name, await pkg.buildAsync());
85
+ this._logger.debug(`[${pkg.name}] 빌드가 완료되었습니다.`);
86
+
87
+ buildCompletedPackageNames.push(pkg.name);
88
+ });
89
+
90
+ this._loggingResults(totalResultMap);
91
+ if (Array.from(totalResultMap.values()).mapMany().some((item) => item.severity === "error")) {
92
+ throw new Error("빌드중 오류가 발생하였습니다.");
93
+ }
94
+ else {
95
+ this._logger.info("모든 빌드가 완료되었습니다.");
96
+ }
97
+ }
98
+
99
+ public async publishAsync(opt: { noBuild: boolean }): Promise<void> {
100
+ if (opt.noBuild) {
101
+ this._logger.warn("빌드하지 않고, 배포하는것은 상당히 위험합니다.");
102
+ await this._waitSecMessageAsync("프로세스를 중지하려면, 'CTRL+C'를 누르세요.", 5);
103
+ }
104
+
105
+ // GIT 사용중일 경우, 커밋되지 않은 수정사항이 있는지 확인
106
+ if (FsUtil.exists(path.resolve(process.cwd(), ".git"))) {
107
+ this._logger.debug("GIT 커밋여부 확인...");
108
+ const gitStatusResult = await SdProcess.execAsync("git status");
109
+ if (gitStatusResult.includes("Changes") || gitStatusResult.includes("Untracked")) {
110
+ throw new Error("커밋되지 않은 정보가 있습니다.");
111
+ }
112
+ }
113
+
114
+ this._logger.debug("패키지 목록 구성...");
115
+ const pkgs = await this._getPackagesAsync();
116
+
117
+ this._logger.debug("프로젝트 및 패키지 버전 설정...");
118
+ await this._upgradeVersionAsync(pkgs);
119
+
120
+ // 빌드
121
+ if (!opt.noBuild) {
122
+ this._logger.debug("빌드를 시작합니다...");
123
+ await this._buildPkgsAsync(pkgs);
124
+ }
125
+
126
+ // GIT 사용중일경우, 새 버전 커밋 및 TAG 생성
127
+ if (FsUtil.exists(path.resolve(process.cwd(), ".git"))) {
128
+ this._logger.debug("새 버전 커밋 및 TAG 생성...");
129
+ await SdProcess.execAsync("git add .");
130
+ await SdProcess.execAsync(`git commit -m "v${this._npmConfig.version}"`);
131
+ await SdProcess.execAsync(`git tag -a "v${this._npmConfig.version}" -m "v${this._npmConfig.version}"`);
132
+ }
133
+
134
+ this._logger.debug("배포 시작...");
135
+ await pkgs.parallelAsync(async (pkg) => {
136
+ this._logger.debug(`[${pkg.name}] 배포를 시작합니다...`);
137
+ await pkg.publishAsync();
138
+ this._logger.debug(`[${pkg.name}] 배포가 완료되었습니다.`);
139
+ });
140
+ this._logger.info(`모든 배포가 완료되었습니다. (v${this._npmConfig.version})`);
141
+ }
142
+
143
+ private async _upgradeVersionAsync(pkgs: SdCliPackage[]): Promise<void> {
144
+ // 작업공간 package.json 버전 설정
145
+ const newVersion = semver.inc(this._npmConfig.version, "patch")!;
146
+ this._npmConfig.version = newVersion;
147
+
148
+ const pkgNames = pkgs.map((item) => item.name);
149
+
150
+ const updateDepVersion = (deps: Record<string, string> | undefined): void => {
151
+ if (!deps) return;
152
+ for (const depName of Object.keys(deps)) {
153
+ if (pkgNames.includes(depName)) {
154
+ deps[depName] = newVersion;
155
+ }
156
+ }
157
+ };
158
+ updateDepVersion(this._npmConfig.dependencies);
159
+ updateDepVersion(this._npmConfig.optionalDependencies);
160
+ updateDepVersion(this._npmConfig.devDependencies);
161
+ updateDepVersion(this._npmConfig.peerDependencies);
162
+
163
+ const npmConfigFilePath = path.resolve(this._rootPath, "package.json");
164
+ await FsUtil.writeJsonAsync(npmConfigFilePath, this._npmConfig, { space: 2 });
165
+
166
+ // 각 패키지 package.json 버전 설정
167
+ await pkgs.parallelAsync(async (pkg) => {
168
+ await pkg.setNewVersionAsync(newVersion, pkgNames);
169
+ });
170
+ }
171
+
172
+ private async _waitSecMessageAsync(msg: string, sec: number): Promise<void> {
173
+ for (let i = sec; i > 0; i--) {
174
+ if (i !== sec) {
175
+ process.stdout.cursorTo(0);
176
+ }
177
+ process.stdout.write(msg + " " + i);
178
+ await Wait.time(1000);
179
+ }
180
+
181
+ process.stdout.cursorTo(0);
182
+ process.stdout.clearLine(0);
183
+ }
184
+
185
+ private async _getPackagesAsync(): Promise<SdCliPackage[]> {
186
+ const pkgRootPaths = await this._npmConfig.workspaces?.mapManyAsync(async (item) => await FsUtil.globAsync(item));
187
+ if (!pkgRootPaths) {
188
+ throw new Error("최상위 'package.json'에서 'workspaces'를 찾을 수 없습니다.");
189
+ }
190
+
191
+ return pkgRootPaths.map((pkgRootPath) => {
192
+ const pkgConfig = this._config.packages[path.basename(pkgRootPath)];
193
+ return pkgConfig ? new SdCliPackage(this._rootPath, pkgRootPath, pkgConfig) : undefined;
194
+ }).filterExists();
195
+ }
196
+
197
+ private _loggingResults(totalResultMap: Map<string, ISdCliPackageBuildResult[]>): void {
198
+ const totalResults = Array.from(totalResultMap.entries())
199
+ .mapMany((item) => item[1].map((item1) => ({
200
+ pkgName: item[0],
201
+ ...item1
202
+ })))
203
+ .orderBy((item) => item.pkgName + "_" + item.filePath);
204
+
205
+ const warnings = totalResults
206
+ .filter((item) => item.severity === "warning")
207
+ .map((item) => `${SdCliBuildResultUtil.getMessage(item)} (${item.pkgName})`)
208
+ .distinct();
209
+
210
+ const errors = totalResults
211
+ .filter((item) => item.severity === "error")
212
+ .map((item) => `${SdCliBuildResultUtil.getMessage(item)} (${item.pkgName})`)
213
+ .distinct();
214
+
215
+ if (warnings.length > 0) {
216
+ this._logger.warn(`경고 발생${os.EOL}`, warnings.join(os.EOL));
217
+ }
218
+ if (errors.length > 0) {
219
+ this._logger.error(`오류 발생${os.EOL}`, errors.join(os.EOL));
220
+ }
221
+
222
+ if (errors.length > 0) {
223
+ this._logger.error(`경고: ${warnings.length}건, 오류: ${errors.length}건`);
224
+ }
225
+ else if (warnings.length > 0) {
226
+ this._logger.warn(`경고: ${warnings.length}건, 오류: ${errors.length}건`);
227
+ }
228
+ }
229
+ }
@@ -0,0 +1,111 @@
1
+ import { INpmConfig, ISdCliPackageBuildResult, ITsconfig, TSdCliPackageConfig } from "../commons";
2
+ import path from "path";
3
+ import { FsUtil, SdProcess } from "@simplysm/sd-core-node";
4
+ import { EventEmitter } from "events";
5
+ import { ObjectUtil } from "@simplysm/sd-core-common";
6
+ import { SdCliTsLibBuilder } from "../builder/SdCliTsLibBuilder";
7
+ import { SdCliJsLibBuilder } from "../builder/SdCliJsLibBuilder";
8
+
9
+ export class SdCliPackage extends EventEmitter {
10
+ private readonly _npmConfig: INpmConfig;
11
+
12
+ public get name(): string {
13
+ return this._npmConfig.name;
14
+ }
15
+
16
+ public get allDependencies(): string[] {
17
+ return [
18
+ ...Object.keys(this._npmConfig.dependencies ?? {}),
19
+ ...Object.keys(this._npmConfig.optionalDependencies ?? {}),
20
+ ...Object.keys(this._npmConfig.devDependencies ?? {}),
21
+ ...Object.keys(this._npmConfig.peerDependencies ?? {})
22
+ ].distinct();
23
+ }
24
+
25
+ public constructor(private readonly _workspaceRootPath: string,
26
+ private readonly _rootPath: string,
27
+ private readonly _config: TSdCliPackageConfig) {
28
+ super();
29
+
30
+ const npmConfigFilePath = path.resolve(this._rootPath, "package.json");
31
+ this._npmConfig = FsUtil.readJson(npmConfigFilePath);
32
+ }
33
+
34
+ public override on(event: "change", listener: () => void): this;
35
+ public override on(event: "complete", listener: (results: ISdCliPackageBuildResult[]) => void): this;
36
+ public override on(event: string | symbol, listener: (...args: any[]) => void): this {
37
+ return super.on(event, listener);
38
+ }
39
+
40
+ public async setNewVersionAsync(newVersion: string, pkgNames: string[]): Promise<void> {
41
+ this._npmConfig.version = newVersion;
42
+
43
+ const updateDepVersion = (deps: Record<string, string> | undefined): void => {
44
+ if (!deps) return;
45
+ for (const depName of Object.keys(deps)) {
46
+ if (pkgNames.includes(depName)) {
47
+ deps[depName] = newVersion;
48
+ }
49
+ }
50
+ };
51
+ updateDepVersion(this._npmConfig.dependencies);
52
+ updateDepVersion(this._npmConfig.optionalDependencies);
53
+ updateDepVersion(this._npmConfig.devDependencies);
54
+ updateDepVersion(this._npmConfig.peerDependencies);
55
+
56
+ const npmConfigFilePath = path.resolve(this._rootPath, "package.json");
57
+ await FsUtil.writeJsonAsync(npmConfigFilePath, this._npmConfig, { space: 2 });
58
+ }
59
+
60
+ public async watchAsync(): Promise<void> {
61
+ const isTs = FsUtil.exists(path.resolve(this._rootPath, "tsconfig.json"));
62
+
63
+ if (isTs) {
64
+ await this._genBuildTsconfigAsync();
65
+ }
66
+
67
+ const isAngular = isTs && this.allDependencies.includes("@angular/core");
68
+ const builder = !isTs ? new SdCliJsLibBuilder(this._rootPath) : new SdCliTsLibBuilder(this._rootPath, isAngular);
69
+
70
+ await builder
71
+ .on("change", () => {
72
+ this.emit("change");
73
+ })
74
+ .on("complete", (results) => {
75
+ this.emit("complete", results);
76
+ })
77
+ .watchAsync();
78
+ }
79
+
80
+ public async buildAsync(): Promise<ISdCliPackageBuildResult[]> {
81
+ const isTs = FsUtil.exists(path.resolve(this._rootPath, "tsconfig.json"));
82
+
83
+ if (isTs) {
84
+ await this._genBuildTsconfigAsync();
85
+ }
86
+
87
+ const isAngular = isTs && this.allDependencies.includes("@angular/core");
88
+ const builder = isTs ? new SdCliTsLibBuilder(this._rootPath, isAngular) : new SdCliJsLibBuilder(this._rootPath);
89
+
90
+ return await builder.buildAsync();
91
+ }
92
+
93
+ public async publishAsync(): Promise<void> {
94
+ if (this._config.type === "library" && this._config.publish === "npm") {
95
+ await SdProcess.execAsync("npm publish --quiet --access public", { cwd: this._rootPath });
96
+ }
97
+ }
98
+
99
+ private async _genBuildTsconfigAsync(): Promise<void> {
100
+ const baseTsconfigFilePath = path.resolve(this._rootPath, "tsconfig.json");
101
+ const baseTsconfig: ITsconfig = await FsUtil.readJsonAsync(baseTsconfigFilePath);
102
+
103
+ const buildTsconfig: ITsconfig = ObjectUtil.clone(baseTsconfig);
104
+ buildTsconfig.compilerOptions = buildTsconfig.compilerOptions ?? {};
105
+ delete buildTsconfig.compilerOptions.baseUrl;
106
+ delete buildTsconfig.compilerOptions.paths;
107
+
108
+ const buildTsconfigFilePath = path.resolve(this._rootPath, "tsconfig-build.json");
109
+ await FsUtil.writeJsonAsync(buildTsconfigFilePath, buildTsconfig, { space: 2 });
110
+ }
111
+ }
@@ -0,0 +1,43 @@
1
+ import ts from "typescript";
2
+ import * as os from "os";
3
+ import * as path from "path";
4
+ import { ISdCliPackageBuildResult } from "../commons";
5
+
6
+ export class SdCliBuildResultUtil {
7
+ public static convertDiagsToResult(diag: ts.Diagnostic): ISdCliPackageBuildResult | undefined {
8
+ const severity = diag.category === ts.DiagnosticCategory.Error ? "error"
9
+ : diag.category === ts.DiagnosticCategory.Warning ? "warning"
10
+ : undefined;
11
+ if (!severity) return undefined;
12
+
13
+ const code = "TS" + diag.code;
14
+ const message = ts.flattenDiagnosticMessageText(diag.messageText, os.EOL);
15
+
16
+
17
+ const filePath = diag.file ? path.resolve(diag.file.fileName) : undefined;
18
+ const position = diag.file && diag.start !== undefined ? diag.file.getLineAndCharacterOfPosition(diag.start) : undefined;
19
+ const line = position ? position.line + 1 : undefined;
20
+ const char = position ? position.character + 1 : undefined;
21
+
22
+ return {
23
+ filePath,
24
+ line,
25
+ char,
26
+ code,
27
+ severity,
28
+ message
29
+ };
30
+ }
31
+
32
+ public static getMessage(result: ISdCliPackageBuildResult): string {
33
+ let str = "";
34
+ if (result.filePath !== undefined) {
35
+ str += `${result.filePath}(${result.line ?? 0}, ${result.char ?? 0}): `;
36
+ }
37
+ if (result.code !== undefined) {
38
+ str += `${result.code}: `;
39
+ }
40
+ str += `${result.severity} ${result.message}`;
41
+ return str;
42
+ }
43
+ }
@@ -0,0 +1,94 @@
1
+ import { ISdCliConfig, TSdCliPackageConfig } from "../commons";
2
+ import { FsUtil } from "@simplysm/sd-core-node";
3
+ import { ObjectUtil } from "@simplysm/sd-core-common";
4
+ import path from "path";
5
+
6
+ export class SdCliConfigUtil {
7
+ public static loadConfig(confFilePath: string, isDev?: boolean, opts?: string[]): ISdCliConfig {
8
+ const confFileCont = FsUtil.readJson(confFilePath);
9
+ let conf = this._getConfigFromFileContent(confFileCont, isDev, opts);
10
+
11
+ // extends
12
+ if (conf.extends) {
13
+ for (const extConfFilePath of conf.extends) {
14
+ const extConf = this.loadConfig(path.resolve(path.dirname(confFilePath), extConfFilePath), isDev, opts);
15
+ conf = this._mergeObj(conf, extConf);
16
+ }
17
+ }
18
+ delete conf["extends"];
19
+
20
+ return conf as ISdCliConfig;
21
+ }
22
+
23
+ private static _getConfigFromFileContent(confFileCont: ISdCliConfigFileContent, isDev?: boolean, opts?: string[]): ISdCliConfigFileContent {
24
+ const conf = ObjectUtil.clone(confFileCont);
25
+
26
+ if (conf.packages) {
27
+ for (const pkgName of Object.keys(conf.packages)) {
28
+ conf.packages[pkgName] = this._getPkgConfigFromFileContent(conf, conf.packages[pkgName], isDev, opts);
29
+ }
30
+ }
31
+ return conf;
32
+ }
33
+
34
+ private static _getPkgConfigFromFileContent(confFileCont: ISdCliConfigFileContent, pkgConfFileCont: TSdCliPackageConfigFileContent, isDev?: boolean, opts?: string[]): TSdCliPackageConfig {
35
+ let pkgConf = ObjectUtil.clone(pkgConfFileCont);
36
+
37
+ // override
38
+ const pkgOvrNames = pkgConf.overrides;
39
+ if (pkgOvrNames) {
40
+ for (const pkgOvrName of pkgOvrNames) {
41
+ const rootOvr = confFileCont.overrides?.[pkgOvrName];
42
+ if (rootOvr) {
43
+ const ovrConf = this._getPkgConfigFromFileContent(confFileCont, rootOvr, isDev, opts);
44
+ pkgConf = this._mergeObj(pkgConf, ovrConf);
45
+ }
46
+ }
47
+ delete pkgConf.overrides;
48
+ }
49
+
50
+
51
+ // mode 처리
52
+ const mode = isDev ? "dev" : "prod";
53
+ if (pkgConf[mode] !== undefined) {
54
+ const modeConf = this._getPkgConfigFromFileContent(confFileCont, pkgConf[mode], isDev, opts);
55
+ pkgConf = this._mergeObj(pkgConf, modeConf);
56
+ }
57
+ delete pkgConf["dev"];
58
+ delete pkgConf["prod"];
59
+
60
+ // options
61
+ if (opts && opts.length > 0) {
62
+ const pkgOpts = Object.keys(pkgConf).filter((key) => key.startsWith("@") && opts.some((opt) => opt === key.slice(1)));
63
+
64
+ for (const pkgOpt of pkgOpts) {
65
+ const optConf = this._getPkgConfigFromFileContent(confFileCont, pkgConf[pkgOpt], isDev, opts);
66
+ pkgConf = this._mergeObj(pkgConf, optConf);
67
+ }
68
+
69
+ for (const optKey of Object.keys(pkgConf).filter((item) => item.startsWith("@"))) {
70
+ delete pkgConf[optKey];
71
+ }
72
+ }
73
+
74
+ return pkgConf;
75
+ }
76
+
77
+ private static _mergeObj<A, B>(org: A, target: B): A & B {
78
+ return ObjectUtil.merge(org, target, {
79
+ arrayProcess: "replace",
80
+ useDelTargetUndefined: true
81
+ });
82
+ }
83
+ }
84
+
85
+ interface ISdCliConfigFileContent {
86
+ packages?: Record<string, TSdCliPackageConfigFileContent>;
87
+ overrides?: Record<string, TSdCliPackageConfigFileContent>;
88
+ extends?: string[];
89
+ }
90
+
91
+ type TSdCliPackageConfigFileContent =
92
+ TSdCliPackageConfig
93
+ & { overrides?: string[] }
94
+ & Record<string, any>;
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "lib": [
5
+ "ES2020"
6
+ ],
7
+ "outDir": "./dist"
8
+ }
9
+ }
package/tsconfig.json CHANGED
@@ -1,29 +1,18 @@
1
1
  {
2
- "extends": "../../tsconfig-base.json",
2
+ "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
- "target": "es2020",
5
4
  "lib": [
6
- "es2020"
5
+ "ES2020"
7
6
  ],
7
+ "outDir": "./dist",
8
8
  "baseUrl": ".",
9
9
  "paths": {
10
- "@simplysm/sd-core-common": [
11
- "../sd-core-common/src/index.ts"
12
- ],
13
10
  "@simplysm/sd-core-node": [
14
11
  "../sd-core-node/src/index.ts"
15
12
  ],
16
- "@simplysm/sd-server-node": [
17
- "../sd-server-node/src/index.ts"
18
- ],
19
- "@simplysm/sd-storage": [
20
- "../sd-storage/src/index.ts"
13
+ "@simplysm/sd-core-common": [
14
+ "../sd-core-common/src/index.ts"
21
15
  ]
22
16
  }
23
- },
24
- "files": [
25
- "src/bin/sd-cli.ts",
26
- "src/workers/lib-build-worker.ts",
27
- "src/workers/client-ng-gen-worker.ts"
28
- ]
29
- }
17
+ }
18
+ }
package/.eslintrc.js DELETED
@@ -1,19 +0,0 @@
1
- module.exports = {
2
- overrides: [
3
- {
4
- files: ["*.ts"],
5
- extends: ["../eslint-plugin/src/configs/typescript"],
6
- parserOptions: {
7
- tsconfigRootDir: __dirname,
8
- project: "tsconfig.json"
9
- },
10
- settings: {
11
- "import/resolver": {
12
- typescript: {
13
- project: require("path").join(__dirname, "tsconfig.json")
14
- }
15
- }
16
- }
17
- }
18
- ]
19
- };