@simplysm/sd-cli 6.4.6 → 7.0.6

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 (182) 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 +60 -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 +43 -0
  15. package/dist/commons.mjs +2 -0
  16. package/dist/entry-points/SdCliWorkspace.d.ts +17 -0
  17. package/dist/entry-points/SdCliWorkspace.mjs +186 -0
  18. package/dist/packages/SdCliPackage.d.ts +19 -0
  19. package/dist/packages/SdCliPackage.mjs +89 -0
  20. package/dist/utils/SdBuildResultUtil.d.ts +6 -0
  21. package/dist/utils/SdBuildResultUtil.mjs +38 -0
  22. package/lib/ts-node-esm-paths.mjs +15 -0
  23. package/package.json +27 -59
  24. package/src/bin/sd-cli.ts +54 -220
  25. package/src/build-tool/SdCliCacheCompilerHost.ts +71 -0
  26. package/src/build-tool/SdCliNgCacheCompilerHost.ts +50 -0
  27. package/src/build-tool/SdCliPackageLinter.ts +54 -0
  28. package/src/builder/SdCliJsLibBuilder.ts +66 -0
  29. package/src/builder/SdCliTsLibBuilder.ts +335 -0
  30. package/src/commons.ts +15 -124
  31. package/src/entry-points/SdCliWorkspace.ts +222 -0
  32. package/src/packages/SdCliPackage.ts +111 -0
  33. package/src/utils/SdBuildResultUtil.ts +43 -0
  34. package/tsconfig-build.json +9 -0
  35. package/tsconfig.json +7 -18
  36. package/.eslintrc.js +0 -19
  37. package/dist-node/bin/sd-cli.js +0 -197
  38. package/dist-node/bin/sd-cli.js.map +0 -1
  39. package/dist-node/build-tools/SdCliCordova.js +0 -145
  40. package/dist-node/build-tools/SdCliCordova.js.map +0 -1
  41. package/dist-node/build-tools/SdCliIndexFileGenerator.js +0 -51
  42. package/dist-node/build-tools/SdCliIndexFileGenerator.js.map +0 -1
  43. package/dist-node/build-tools/SdCliNgModuleFilesGenerator.js +0 -675
  44. package/dist-node/build-tools/SdCliNgModuleFilesGenerator.js.map +0 -1
  45. package/dist-node/build-tools/metadata/SdAotMetadataReader.js +0 -274
  46. package/dist-node/build-tools/metadata/SdAotMetadataReader.js.map +0 -1
  47. package/dist-node/build-tools/metadata/SdIvyMetadataReader.js +0 -124
  48. package/dist-node/build-tools/metadata/SdIvyMetadataReader.js.map +0 -1
  49. package/dist-node/build-tools/metadata/SdMetadataError.js +0 -13
  50. package/dist-node/build-tools/metadata/SdMetadataError.js.map +0 -1
  51. package/dist-node/build-tools/metadata/SdMyMetadataReader.js +0 -321
  52. package/dist-node/build-tools/metadata/SdMyMetadataReader.js.map +0 -1
  53. package/dist-node/builders/SdCliJavascriptLinter.js +0 -65
  54. package/dist-node/builders/SdCliJavascriptLinter.js.map +0 -1
  55. package/dist-node/builders/SdCliNgClientBuilder.js +0 -636
  56. package/dist-node/builders/SdCliNgClientBuilder.js.map +0 -1
  57. package/dist-node/builders/SdCliNgLibraryBuilder.js +0 -217
  58. package/dist-node/builders/SdCliNgLibraryBuilder.js.map +0 -1
  59. package/dist-node/builders/SdCliPublisher.js +0 -129
  60. package/dist-node/builders/SdCliPublisher.js.map +0 -1
  61. package/dist-node/builders/SdCliServerBuilder.js +0 -452
  62. package/dist-node/builders/SdCliServerBuilder.js.map +0 -1
  63. package/dist-node/builders/SdCliTypescriptBuilder.js +0 -347
  64. package/dist-node/builders/SdCliTypescriptBuilder.js.map +0 -1
  65. package/dist-node/commons.js +0 -3
  66. package/dist-node/commons.js.map +0 -1
  67. package/dist-node/entry-points/SdCliLocalUpdater.js +0 -88
  68. package/dist-node/entry-points/SdCliLocalUpdater.js.map +0 -1
  69. package/dist-node/entry-points/SdCliPrepare.js +0 -56
  70. package/dist-node/entry-points/SdCliPrepare.js.map +0 -1
  71. package/dist-node/entry-points/SdCliProject.js +0 -302
  72. package/dist-node/entry-points/SdCliProject.js.map +0 -1
  73. package/dist-node/packages/SdCliClientPackage.js +0 -91
  74. package/dist-node/packages/SdCliClientPackage.js.map +0 -1
  75. package/dist-node/packages/SdCliLibraryPackage.js +0 -99
  76. package/dist-node/packages/SdCliLibraryPackage.js.map +0 -1
  77. package/dist-node/packages/SdCliPackageBase.js +0 -33
  78. package/dist-node/packages/SdCliPackageBase.js.map +0 -1
  79. package/dist-node/packages/SdCliServerPackage.js +0 -69
  80. package/dist-node/packages/SdCliServerPackage.js.map +0 -1
  81. package/dist-node/packages/SdCliUnknownPackage.js +0 -15
  82. package/dist-node/packages/SdCliUnknownPackage.js.map +0 -1
  83. package/dist-node/utils/SdCliFileCrypto.js +0 -76
  84. package/dist-node/utils/SdCliFileCrypto.js.map +0 -1
  85. package/dist-node/utils/SdProjectConfigUtil.js +0 -62
  86. package/dist-node/utils/SdProjectConfigUtil.js.map +0 -1
  87. package/dist-node/utils/SdTsDiagnosticUtil.js +0 -45
  88. package/dist-node/utils/SdTsDiagnosticUtil.js.map +0 -1
  89. package/dist-node/utils/SdWebpackUtil.js +0 -63
  90. package/dist-node/utils/SdWebpackUtil.js.map +0 -1
  91. package/dist-node/workers/client-ng-gen-worker.js +0 -57
  92. package/dist-node/workers/client-ng-gen-worker.js.map +0 -1
  93. package/dist-node/workers/lib-build-worker.js +0 -88
  94. package/dist-node/workers/lib-build-worker.js.map +0 -1
  95. package/dist-types/bin/sd-cli.d.ts +0 -3
  96. package/dist-types/bin/sd-cli.d.ts.map +0 -1
  97. package/dist-types/build-tools/SdCliCordova.d.ts +0 -15
  98. package/dist-types/build-tools/SdCliCordova.d.ts.map +0 -1
  99. package/dist-types/build-tools/SdCliIndexFileGenerator.d.ts +0 -13
  100. package/dist-types/build-tools/SdCliIndexFileGenerator.d.ts.map +0 -1
  101. package/dist-types/build-tools/SdCliNgModuleFilesGenerator.d.ts +0 -43
  102. package/dist-types/build-tools/SdCliNgModuleFilesGenerator.d.ts.map +0 -1
  103. package/dist-types/build-tools/metadata/SdAotMetadataReader.d.ts +0 -58
  104. package/dist-types/build-tools/metadata/SdAotMetadataReader.d.ts.map +0 -1
  105. package/dist-types/build-tools/metadata/SdIvyMetadataReader.d.ts +0 -43
  106. package/dist-types/build-tools/metadata/SdIvyMetadataReader.d.ts.map +0 -1
  107. package/dist-types/build-tools/metadata/SdMetadataError.d.ts +0 -7
  108. package/dist-types/build-tools/metadata/SdMetadataError.d.ts.map +0 -1
  109. package/dist-types/build-tools/metadata/SdMyMetadataReader.d.ts +0 -59
  110. package/dist-types/build-tools/metadata/SdMyMetadataReader.d.ts.map +0 -1
  111. package/dist-types/builders/SdCliJavascriptLinter.d.ts +0 -14
  112. package/dist-types/builders/SdCliJavascriptLinter.d.ts.map +0 -1
  113. package/dist-types/builders/SdCliNgClientBuilder.d.ts +0 -29
  114. package/dist-types/builders/SdCliNgClientBuilder.d.ts.map +0 -1
  115. package/dist-types/builders/SdCliNgLibraryBuilder.d.ts +0 -30
  116. package/dist-types/builders/SdCliNgLibraryBuilder.d.ts.map +0 -1
  117. package/dist-types/builders/SdCliPublisher.d.ts +0 -9
  118. package/dist-types/builders/SdCliPublisher.d.ts.map +0 -1
  119. package/dist-types/builders/SdCliServerBuilder.d.ts +0 -31
  120. package/dist-types/builders/SdCliServerBuilder.d.ts.map +0 -1
  121. package/dist-types/builders/SdCliTypescriptBuilder.d.ts +0 -56
  122. package/dist-types/builders/SdCliTypescriptBuilder.d.ts.map +0 -1
  123. package/dist-types/commons.d.ts +0 -134
  124. package/dist-types/commons.d.ts.map +0 -1
  125. package/dist-types/entry-points/SdCliLocalUpdater.d.ts +0 -12
  126. package/dist-types/entry-points/SdCliLocalUpdater.d.ts.map +0 -1
  127. package/dist-types/entry-points/SdCliPrepare.d.ts +0 -6
  128. package/dist-types/entry-points/SdCliPrepare.d.ts.map +0 -1
  129. package/dist-types/entry-points/SdCliProject.d.ts +0 -32
  130. package/dist-types/entry-points/SdCliProject.d.ts.map +0 -1
  131. package/dist-types/packages/SdCliClientPackage.d.ts +0 -17
  132. package/dist-types/packages/SdCliClientPackage.d.ts.map +0 -1
  133. package/dist-types/packages/SdCliLibraryPackage.d.ts +0 -20
  134. package/dist-types/packages/SdCliLibraryPackage.d.ts.map +0 -1
  135. package/dist-types/packages/SdCliPackageBase.d.ts +0 -11
  136. package/dist-types/packages/SdCliPackageBase.d.ts.map +0 -1
  137. package/dist-types/packages/SdCliServerPackage.d.ts +0 -16
  138. package/dist-types/packages/SdCliServerPackage.d.ts.map +0 -1
  139. package/dist-types/packages/SdCliUnknownPackage.d.ts +0 -9
  140. package/dist-types/packages/SdCliUnknownPackage.d.ts.map +0 -1
  141. package/dist-types/utils/SdCliFileCrypto.d.ts +0 -8
  142. package/dist-types/utils/SdCliFileCrypto.d.ts.map +0 -1
  143. package/dist-types/utils/SdProjectConfigUtil.d.ts +0 -7
  144. package/dist-types/utils/SdProjectConfigUtil.d.ts.map +0 -1
  145. package/dist-types/utils/SdTsDiagnosticUtil.d.ts +0 -6
  146. package/dist-types/utils/SdTsDiagnosticUtil.d.ts.map +0 -1
  147. package/dist-types/utils/SdWebpackUtil.d.ts +0 -7
  148. package/dist-types/utils/SdWebpackUtil.d.ts.map +0 -1
  149. package/dist-types/workers/client-ng-gen-worker.d.ts +0 -2
  150. package/dist-types/workers/client-ng-gen-worker.d.ts.map +0 -1
  151. package/dist-types/workers/lib-build-worker.d.ts +0 -2
  152. package/dist-types/workers/lib-build-worker.d.ts.map +0 -1
  153. package/schema/schema.json +0 -447
  154. package/sd-tsconfig.node.json +0 -18
  155. package/src/build-tools/SdCliCordova.ts +0 -242
  156. package/src/build-tools/SdCliIndexFileGenerator.ts +0 -61
  157. package/src/build-tools/SdCliNgModuleFilesGenerator.ts +0 -894
  158. package/src/build-tools/metadata/SdAotMetadataReader.ts +0 -374
  159. package/src/build-tools/metadata/SdIvyMetadataReader.ts +0 -183
  160. package/src/build-tools/metadata/SdMetadataError.ts +0 -7
  161. package/src/build-tools/metadata/SdMyMetadataReader.ts +0 -407
  162. package/src/builders/SdCliJavascriptLinter.ts +0 -81
  163. package/src/builders/SdCliNgClientBuilder.ts +0 -793
  164. package/src/builders/SdCliNgLibraryBuilder.ts +0 -301
  165. package/src/builders/SdCliPublisher.ts +0 -144
  166. package/src/builders/SdCliServerBuilder.ts +0 -555
  167. package/src/builders/SdCliTypescriptBuilder.ts +0 -552
  168. package/src/entry-points/SdCliLocalUpdater.ts +0 -114
  169. package/src/entry-points/SdCliPrepare.ts +0 -104
  170. package/src/entry-points/SdCliProject.ts +0 -405
  171. package/src/packages/SdCliClientPackage.ts +0 -111
  172. package/src/packages/SdCliLibraryPackage.ts +0 -118
  173. package/src/packages/SdCliPackageBase.ts +0 -34
  174. package/src/packages/SdCliServerPackage.ts +0 -85
  175. package/src/packages/SdCliUnknownPackage.ts +0 -14
  176. package/src/utils/SdCliFileCrypto.ts +0 -87
  177. package/src/utils/SdCliUtils.ts +0 -56
  178. package/src/utils/SdProjectConfigUtil.ts +0 -145
  179. package/src/utils/SdTsDiagnosticUtil.ts +0 -46
  180. package/src/utils/SdWebpackUtil.ts +0 -71
  181. package/src/workers/client-ng-gen-worker.ts +0 -63
  182. package/src/workers/lib-build-worker.ts +0 -97
@@ -1,104 +0,0 @@
1
- import { FsUtil, Logger } from "@simplysm/sd-core-node";
2
-
3
- export class SdCliPrepare {
4
- private readonly _logger = Logger.get(["simplysm", "sd-cli", this.constructor.name]);
5
-
6
- public async prepareAsync(): Promise<void> {
7
- // 타입체크 속도 지연 메시지 추가
8
- const r1 = await this._modifyTypescriptCodeForTypeCheckPerformanceWarning();
9
- this._logger.log(`[모듈수정] 타입체크 속도 지연 메시지 추가 (${r1 ? "O" : "X"})`);
10
-
11
- //-- 결굴 프로세싱중에 자꾸 'processModule'이 불려서... 문제가 생김
12
- // ngcc 동시작업 관련: ng-packagr 무조건 Async
13
- // const r2 = await this._modifyNgccProcessorNgPackagrCodeForAsync();
14
- // this._logger.log(`[모듈수정] ngcc: 비동기 처리 (${r2 ? "O" : "X"})`);
15
-
16
- // ngcc 동시작업 관련: 대기시간 늘림
17
- // const r3 = await this._modifyNgccProcessorConfigurationCodeForLongWaitTime();
18
- // this._logger.log(`[모듈수정] ngcc: 대기시간 늘림 (${r3 ? "O" : "X"})`);
19
-
20
- // ngcc 동시작업 관련: 디버깅 메시지 끄기
21
- // const r4 = await this._modifyNgccProcessorAsyncLockerCodeForRemoveWaitingMessage();
22
- // this._logger.log(`[모듈수정] ngcc: 불필요 메시지 제거 (${r4 ? "O" : "X"})`);
23
- }
24
-
25
- private async _modifyTypescriptCodeForTypeCheckPerformanceWarning(): Promise<boolean> {
26
- const filePath = require.resolve("typescript");
27
- const fileContent = await FsUtil.readFileAsync(filePath);
28
- const modifiedFileContent = fileContent.replace(`
29
- function checkSourceElement(node) {
30
- if (node) {
31
- var saveCurrentNode = currentNode;
32
- currentNode = node;
33
- instantiationCount = 0;
34
- checkSourceElementWorker(node);
35
- currentNode = saveCurrentNode;
36
- }
37
- }`, `
38
- function checkSourceElement(node) {
39
- if (node) {
40
- const prevUsage = process.cpuUsage();
41
-
42
- var saveCurrentNode = currentNode;
43
- currentNode = node;
44
- instantiationCount = 0;
45
- checkSourceElementWorker(node);
46
- currentNode = saveCurrentNode;
47
-
48
- const usage = process.cpuUsage(prevUsage);
49
- if (node.hasChildPerformanceWarning) {
50
- node.parent.hasChildPerformanceWarning = true;
51
- }
52
- else if (usage.user + usage.system > 2000 * 1000 && node.kind !== 253) {
53
- error(node, {
54
- code: 9000,
55
- category: ts.DiagnosticCategory.Warning,
56
- key: "simplysm_check_source_element_performance_slow",
57
- message: "소스코드 타입분석에 너무 오랜 시간이 소요됩니다. [" + Math.round((usage.user + usage.system) / 1000) + "ms/cpu, KIND: " + node.kind + "]"
58
- });
59
- node.parent.hasChildPerformanceWarning = true;
60
- }
61
- }
62
- }`);
63
- await FsUtil.writeFileAsync(filePath, modifiedFileContent);
64
- return fileContent !== modifiedFileContent;
65
- }
66
-
67
- /*private async _modifyNgccProcessorNgPackagrCodeForAsync(): Promise<boolean> {
68
- const filePath = require.resolve("ng-packagr/lib/ngc/ngcc-processor.js");
69
- const fileContent = await FsUtil.readFileAsync(filePath);
70
- const modifiedFileContent = fileContent.replace(`
71
- ngcc_1.process({
72
- basePath: this._nodeModulesDirectory`, `
73
- ngcc_1.process({
74
- async: true,
75
- basePath: this._nodeModulesDirectory`);
76
- await FsUtil.writeFileAsync(filePath, modifiedFileContent);
77
- return fileContent !== modifiedFileContent;
78
- }
79
-
80
- private async _modifyNgccProcessorConfigurationCodeForLongWaitTime(): Promise<boolean> {
81
- const filePath = require.resolve("@angular/compiler-cli/ngcc/src/packages/configuration.js");
82
- const fileContent = await FsUtil.readFileAsync(filePath);
83
- const modifiedFileContent = fileContent.replace(`
84
- locking: {
85
- retryDelay: 500,
86
- retryAttempts: 500`, `
87
- locking: {
88
- retryDelay: 1000,
89
- retryAttempts: 10 * 60`); // 10분
90
- await FsUtil.writeFileAsync(filePath, modifiedFileContent);
91
- return fileContent !== modifiedFileContent;
92
- }
93
-
94
- private async _modifyNgccProcessorAsyncLockerCodeForRemoveWaitingMessage(): Promise<boolean> {
95
- const filePath = require.resolve("@angular/compiler-cli/ngcc/src/locking/async_locker.js");
96
- const fileContent = await FsUtil.readFileAsync(filePath);
97
- const modifiedFileContent = fileContent.replace(`
98
- this.logger.info("Another process, with id " + pid + ", is currently running ngcc.\\n" +
99
- ("Waiting up to " + this.retryDelay * this.retryAttempts / 1000 + "s for it to finish.\\n") +
100
- ("(If you are sure no ngcc process is running then you should delete the lock-file at " + this.lockFile.path + ".)"));`, ``);
101
- await FsUtil.writeFileAsync(filePath, modifiedFileContent);
102
- return fileContent !== modifiedFileContent;
103
- }*/
104
- }
@@ -1,405 +0,0 @@
1
- import { SdProjectConfigUtil } from "../utils/SdProjectConfigUtil";
2
- import { FsUtil, Logger, SdProcessManager, SdProcessWorkManager } from "@simplysm/sd-core-node";
3
- import {
4
- INpmConfig,
5
- ISdClientPackageConfig,
6
- ISdPackageBuildResult,
7
- ISdProjectConfig,
8
- TSdPackageConfig
9
- } from "../commons";
10
- import * as path from "path";
11
- import { FunctionQueue, StringUtil, Wait } from "@simplysm/sd-core-common";
12
- import * as os from "os";
13
- import { NextHandleFunction } from "connect";
14
- import { SdCliLibraryPackage } from "../packages/SdCliLibraryPackage";
15
- import { SdCliServerPackage } from "../packages/SdCliServerPackage";
16
- import { SdCliClientPackage } from "../packages/SdCliClientPackage";
17
- import { SdCliUnknownPackage } from "../packages/SdCliUnknownPackage";
18
- import { SdCliLocalUpdater } from "./SdCliLocalUpdater";
19
- import * as semver from "semver";
20
-
21
- // TODO: Cordova
22
- // TODO: Electron
23
- export class SdCliProject {
24
- private readonly _logger = Logger.get(["simplysm", "sd-cli", this.constructor.name]);
25
-
26
- public readonly npmConfig: INpmConfig;
27
- public readonly npmConfigFilePath: string;
28
-
29
- private readonly _fnQueue = new FunctionQueue();
30
- private readonly _serverInfoMap = new Map<string, { middlewares: NextHandleFunction[]; clients: { name: string; platform: string }[]; port?: number; ssl?: boolean }>();
31
-
32
- public constructor(private readonly _rootPath: string) {
33
- this.npmConfigFilePath = path.resolve(this._rootPath, "package.json");
34
- this.npmConfig = FsUtil.readJson(this.npmConfigFilePath);
35
- }
36
-
37
- public async buildAsync(opt: { watch?: boolean; packages?: string[]; options?: string[]; config?: string; skipProcesses?: string[] }): Promise<{ hasError: boolean }> {
38
- this._logger.debug("프로젝트 설정 가져오기...");
39
- const config = await SdProjectConfigUtil.loadConfigAsync(
40
- this._rootPath,
41
- opt.watch,
42
- opt.options,
43
- opt.config
44
- );
45
-
46
- if (opt.watch && config.localUpdates) {
47
- this._logger.debug("로컬 라이브러리 업데이트 변경감지 시작...");
48
- await new SdCliLocalUpdater(this._rootPath).localUpdateAsync(true, opt);
49
- }
50
-
51
- this._logger.debug("프로젝트 패키지 목록 구성...");
52
- const allPkgs = await this._getAllPackagesAsync(config, opt.packages, opt.skipProcesses ?? []);
53
- const pkgs = allPkgs.filter((item) => !(item instanceof SdCliUnknownPackage)) as TSdCliBuildablePackage[];
54
-
55
- this._logger.debug("프로젝트 및 패키지 버전 설정...");
56
- if (!opt.watch) {
57
- const newVersion = await this._upgradeVersionAsync();
58
- await allPkgs.parallelAsync(async (pkg) => {
59
- await pkg.setNewVersionAsync(this.npmConfig.name, newVersion);
60
- });
61
- }
62
-
63
- this._logger.debug("패키지 빌드 이벤트 설정...");
64
- let changeCount = 0;
65
- const totalResultMap = new Map<string, (ISdPackageBuildResult & { pkgName: string })[]>();
66
- for (const pkg of pkgs) {
67
- pkg
68
- .on("change", (target) => {
69
- this._logger.debug(`[${pkg.npmConfig.name}${target !== undefined ? `(${target})` : ""}] 빌드를 시작합니다.`);
70
-
71
- this._fnQueue.run(() => {
72
- if (changeCount === 0) {
73
- this._logger.log(`빌드를 시작합니다...`);
74
- }
75
- changeCount++;
76
- });
77
- })
78
- .on("complete", (target, results) => {
79
- this._logger.debug(`[${pkg.npmConfig.name}${target !== undefined ? `(${target})` : ""}] 빌드가 완료되었습니다.`);
80
-
81
- this._fnQueue.run(() => {
82
- totalResultMap.set(pkg.npmConfig.name + "|_|" + target, results.map((item) => ({
83
- ...item,
84
- pkgName: pkg.npmConfig.name
85
- })));
86
-
87
- setTimeout(() => {
88
- changeCount--;
89
- if (changeCount === 0) {
90
- this._loggingResults(totalResultMap);
91
- this._logger.info(`모든 빌드가 완료되었습니다.`);
92
- this._loggingOpenClientHrefs();
93
- }
94
- }, 100);
95
- });
96
- });
97
-
98
- if (pkg instanceof SdCliServerPackage) {
99
- pkg.on("complete", (target, results, server) => {
100
- if (server) {
101
- const serverInfo = this._serverInfoMap.getOrCreate(pkg.npmConfig.name, {
102
- middlewares: [],
103
- clients: []
104
- });
105
- server.middlewares = serverInfo.middlewares;
106
- serverInfo.port = server.options.port;
107
- serverInfo.ssl = server.options.ssl !== undefined;
108
- }
109
- });
110
- }
111
- }
112
-
113
- this._logger.debug("패키지 빌드...");
114
- const pkgNames = pkgs.map((item) => item.npmConfig.name);
115
-
116
- this._logger.log(`빌드를 시작합니다...`);
117
- changeCount++;
118
- const buildCompletedPackageNames: string[] = [];
119
-
120
- let isOnBuildingNgPackage = false; // NGCC 동시오류를 막기위해, 빌드자체를 동시에 못돌게함..
121
-
122
- await pkgs.parallelAsync(async (pkg) => {
123
- await this._waitPackageDepCompleteAsync(pkg, pkgNames, buildCompletedPackageNames);
124
-
125
- if (pkg instanceof SdCliClientPackage || (pkg instanceof SdCliLibraryPackage && pkg.config.targets?.includes("angular"))) {
126
- await Wait.true(() => !isOnBuildingNgPackage);
127
- isOnBuildingNgPackage = true;
128
- }
129
-
130
- if (opt.watch) {
131
- if (pkg instanceof SdCliClientPackage) {
132
- const middlewares = await pkg.watchAsync();
133
- if (!StringUtil.isNullOrEmpty(pkg.config.server)) {
134
- const serverInfo = this._serverInfoMap.getOrCreate(pkg.config.server, { middlewares: [], clients: [] });
135
- serverInfo.middlewares.push(...middlewares);
136
- const platforms = pkg.config.platforms?.map((item) => item.type) ?? ["browser"];
137
- serverInfo.clients = serverInfo.clients.concat(platforms.map((platform) => ({
138
- name: pkg.npmConfig.name.split("/").last()!,
139
- platform
140
- }))).distinct();
141
- }
142
- }
143
- else {
144
- await pkg.watchAsync();
145
- }
146
- }
147
- else {
148
- await pkg.buildAsync();
149
- }
150
- buildCompletedPackageNames.push(pkg.npmConfig.name);
151
-
152
- if (pkg instanceof SdCliClientPackage || (pkg instanceof SdCliLibraryPackage && pkg.config.targets?.includes("angular"))) {
153
- isOnBuildingNgPackage = false;
154
- }
155
- });
156
- changeCount--;
157
- this._loggingResults(totalResultMap);
158
- this._logger.info(`모든 빌드가 완료되었습니다.`);
159
- this._loggingOpenClientHrefs();
160
-
161
- return {
162
- hasError: Array.from(totalResultMap.values()).mapMany().some((item) => item.severity === "error")
163
- };
164
- }
165
-
166
-
167
- public async publishAsync(opt: { build: boolean; packages?: string[]; options?: string[]; config?: string }): Promise<void> {
168
- if (!opt.build) {
169
- this._logger.warn("빌드하지 않고, 배포하는것은 상당히 위험합니다.");
170
- await this._waitSecMessageAsync("프로세스를 중지하려면, 'CTRL+C'를 누르세요.", 5);
171
- }
172
-
173
- // GIT 사용중일 경우, 커밋되지 않은 수정사항이 있는지 확인
174
- if (FsUtil.exists(path.resolve(process.cwd(), ".git"))) {
175
- this._logger.debug(`GIT 커밋여부 확인...`);
176
- await SdProcessManager.spawnAsync(
177
- "git status",
178
- undefined,
179
- (message) => {
180
- if (message.includes("Changes") || message.includes("Untracked")) {
181
- throw new Error("커밋되지 않은 정보가 있습니다.");
182
- }
183
- },
184
- false
185
- );
186
- }
187
-
188
- this._logger.debug("프로젝트 설정 가져오기...");
189
- const config = await SdProjectConfigUtil.loadConfigAsync(
190
- this._rootPath,
191
- false,
192
- opt.options,
193
- opt.config
194
- );
195
-
196
- this._logger.debug("프로젝트 패키지 목록 구성...");
197
- const allPkgs = await this._getAllPackagesAsync(config, opt.packages, []);
198
- const pkgs = allPkgs.filter((item) => !(item instanceof SdCliUnknownPackage) && item.config.publish) as TSdCliBuildablePackage[];
199
-
200
- // 빌드가 필요하면 빌드함
201
- if (opt.build) {
202
- this._logger.debug("빌드 수행...");
203
- const buildResult = await this.buildAsync({
204
- watch: false,
205
- packages: opt.packages,
206
- options: opt.options,
207
- config: opt.config
208
- });
209
- if (buildResult.hasError) {
210
- throw new Error("빌드중 에러가 발생했습니다.");
211
- }
212
- }
213
-
214
- // 빌드시엔 빌드에서 버전업했고, 빌드가 아닌경우 여기서 버전업
215
- if (!opt.build) {
216
- this._logger.debug("프로젝트 및 패키지 버전 설정...");
217
- const newVersion = await this._upgradeVersionAsync();
218
- await allPkgs.parallelAsync(async (pkg) => {
219
- await pkg.setNewVersionAsync(this.npmConfig.name, newVersion);
220
- });
221
- }
222
-
223
- // GIT 사용중일경우, 새 버전 커밋 및 TAG 생성
224
- if (FsUtil.exists(path.resolve(process.cwd(), ".git"))) {
225
- this._logger.debug("새 버전 커밋 및 TAG 생성...");
226
- await SdProcessManager.spawnAsync(`git add .`, undefined, false, false);
227
- await SdProcessManager.spawnAsync(`git commit -m "v${this.npmConfig.version}"`, undefined, false, false);
228
- await SdProcessManager.spawnAsync(`git tag -a "v${this.npmConfig.version}" -m "v${this.npmConfig.version}"`, undefined, false, false);
229
- }
230
-
231
- this._logger.debug(`배포 시작...`);
232
-
233
- await pkgs.filter((item) => item.config.publish === "npm").parallelAsync(async (pkg) => {
234
- await pkg.publishAsync();
235
- });
236
-
237
- for (const pkg of pkgs.filter((item) => item.config.publish !== "npm")) {
238
- await pkg.publishAsync();
239
- }
240
-
241
- this._logger.info(`배포 프로세스가 완료되었습니다.(v${this.npmConfig.version})`);
242
- }
243
-
244
- private async _waitSecMessageAsync(msg: string, sec: number): Promise<void> {
245
- for (let i = sec; i > 0; i--) {
246
- if (i !== sec) {
247
- process.stdout.cursorTo(0);
248
- }
249
- process.stdout.write(msg + " " + i);
250
- await Wait.time(1000);
251
- }
252
-
253
- process.stdout.cursorTo(0);
254
- process.stdout.clearLine(0);
255
- }
256
-
257
- private _loggingOpenClientHrefs(): void {
258
- const clientHrefs = Array.from(this._serverInfoMap.values()).mapMany((serverInfo) => serverInfo.clients.map((client) => {
259
- const protocolStr = serverInfo.ssl ? "https://" : "http://";
260
- const portStr = serverInfo.port !== undefined ? `:${serverInfo.port}` : "";
261
- let result = protocolStr + "localhost" + portStr + "/";
262
- if (client.platform !== "browser") {
263
- result += `__${client.platform}/`;
264
- }
265
- return result + client.name + "/";
266
- }));
267
- if (clientHrefs.length > 0) {
268
- this._logger.log(`오픈된 클라이언트: ${clientHrefs.join(", ")}`);
269
- }
270
- }
271
-
272
- private async _getAllPackagesAsync(config: ISdProjectConfig, packages: string[] | undefined, skipProcesses: string[]): Promise<TSdCliPackage[]> {
273
- // package.json에서 workspaces를 통해 패키지 경로 목록 가져오기
274
- const allPkgPaths = await this.npmConfig.workspaces?.mapManyAsync(async (item) => await FsUtil.globAsync(item));
275
- if (!allPkgPaths) {
276
- throw new Error("프로젝트의 'package.json'에서 'workspaces'를 찾을 수 없습니다.");
277
- }
278
-
279
- // 모든 패키지의 설정 가져오기
280
- const allPackageInfos: { rootPath: string; name: string; config: TSdPackageConfig | undefined }[] = [];
281
- for (const pkgPath of allPkgPaths) {
282
- // 패키지 package.json
283
- const pkgNpmConfigFilePath = path.resolve(pkgPath, "package.json");
284
- if (!FsUtil.exists(pkgNpmConfigFilePath)) continue; // package.json파일이 없는 폴더는 무시
285
- const pkgNpmConfig: INpmConfig = await FsUtil.readJsonAsync(pkgNpmConfigFilePath);
286
-
287
- // 패키지 설정
288
- const pkgName = pkgNpmConfig.name;
289
- const pkgConfig = config.packages[pkgName];
290
-
291
- // 사용할 패키지로 설정하지 않은 패키지면 타입을 'none'으로 강제
292
- if (packages && packages.length > 0 && !packages.includes(pkgName)) {
293
- allPackageInfos.push({ rootPath: pkgPath, name: pkgName, config: undefined });
294
- }
295
- else {
296
- allPackageInfos.push({ rootPath: pkgPath, name: pkgName, config: pkgConfig });
297
- }
298
- }
299
-
300
- // 각 package를 위한 worker 준비
301
- /*const workerCount = allPackageInfos.sum((item) => {
302
- if (item.config && item.config.type === "library") {
303
- return item.config.targets?.length ?? 1;
304
- }
305
- return 0;
306
- });*/
307
-
308
- const processWorkManager = await SdProcessWorkManager.createAsync(
309
- path.resolve(__dirname, `../workers/lib-build-worker`),
310
- [],
311
- this._logger,
312
- undefined,
313
- Math.max(os.cpus().length / 2, 1)
314
- );
315
-
316
- // 패키지 목록 구성
317
- const pkgs: TSdCliPackage[] = [];
318
- for (const pkgInfo of allPackageInfos) {
319
- if (pkgInfo.config?.type === "library") {
320
- pkgs.push(new SdCliLibraryPackage(pkgInfo.rootPath, pkgInfo.config, skipProcesses as any, processWorkManager));
321
- }
322
- else if (pkgInfo.config?.type === "client") {
323
- const serverPkgInfo = allPackageInfos.single((item) => item.name === (pkgInfo.config as ISdClientPackageConfig).server);
324
- pkgs.push(new SdCliClientPackage(pkgInfo.rootPath, pkgInfo.config, skipProcesses as any, serverPkgInfo?.rootPath));
325
- }
326
- else if (pkgInfo.config?.type === "server") {
327
- pkgs.push(new SdCliServerPackage(pkgInfo.rootPath, pkgInfo.config, skipProcesses as any));
328
- }
329
- else {
330
- pkgs.push(new SdCliUnknownPackage(pkgInfo.rootPath));
331
- }
332
- }
333
-
334
- return pkgs;
335
- }
336
-
337
- private async _waitPackageDepCompleteAsync(pkg: TSdCliPackage, pkgNames: string[], completedPkgNames: string[]): Promise<void> {
338
- // 패키지의 의존성 패키지 중에 빌드해야할 패키지 목록에 이미 있는 의존성 패키지만 추리기
339
- const depNames = [
340
- ...Object.keys(pkg.npmConfig.dependencies ?? {}),
341
- ...Object.keys(pkg.npmConfig.optionalDependencies ?? {}),
342
- ...Object.keys(pkg.npmConfig.devDependencies ?? {}),
343
- ...Object.keys(pkg.npmConfig.peerDependencies ?? {})
344
- ].distinct().filter((dep) => pkgNames.includes(dep));
345
-
346
- // 추려진 의존성 패키지별로 의존성 패키지의 빌드가 완료될때까지 기다리기
347
- await depNames.parallelAsync(async (depName) => {
348
- await Wait.true(() => completedPkgNames.includes(depName));
349
- });
350
- }
351
-
352
- private _loggingResults(totalResultMap: Map<string, (ISdPackageBuildResult & { pkgName: string })[]>): void {
353
- const totalResults = Array.from(totalResultMap.values()).mapMany();
354
-
355
- const warnings = totalResults
356
- .filter((item) => item.severity === "warning")
357
- .map((item) => item.message.trim() + " (" + item.pkgName + ")")
358
- .distinct();
359
-
360
- const errors = totalResults
361
- .filter((item) => item.severity === "error")
362
- .map((item) => item.message.trim() + " (" + item.pkgName + ")")
363
- .distinct();
364
-
365
- if (warnings.length > 0) {
366
- this._logger.warn(`경고 발생${os.EOL}`, warnings.join(os.EOL));
367
- }
368
- if (errors.length > 0) {
369
- this._logger.error(`오류 발생${os.EOL}`, errors.join(os.EOL));
370
- }
371
-
372
- if (errors.length > 0) {
373
- this._logger.error(`경고: ${warnings.length}건, 오류: ${errors.length}건`);
374
- }
375
- else if (warnings.length > 0) {
376
- this._logger.warn(`경고: ${warnings.length}건, 오류: ${errors.length}건`);
377
- }
378
- }
379
-
380
- private async _upgradeVersionAsync(): Promise<string> {
381
- // 프로젝트 및 패키지 버전 업
382
- const newVersion = semver.inc(this.npmConfig.version, "patch")!;
383
- this.npmConfig.version = newVersion;
384
-
385
- const updateDepVersion = (deps: Record<string, string> | undefined): void => {
386
- if (!deps) return;
387
- for (const dependencyName of Object.keys(deps)) {
388
- if (dependencyName.startsWith("@" + this.npmConfig.name + "/")) {
389
- deps[dependencyName] = newVersion;
390
- }
391
- }
392
- };
393
- updateDepVersion(this.npmConfig.dependencies);
394
- updateDepVersion(this.npmConfig.optionalDependencies);
395
- updateDepVersion(this.npmConfig.devDependencies);
396
- updateDepVersion(this.npmConfig.peerDependencies);
397
-
398
- await FsUtil.writeJsonAsync(this.npmConfigFilePath, this.npmConfig, { space: 2 });
399
-
400
- return newVersion;
401
- }
402
- }
403
-
404
- type TSdCliPackage = SdCliLibraryPackage | SdCliServerPackage | SdCliClientPackage | SdCliUnknownPackage;
405
- type TSdCliBuildablePackage = SdCliLibraryPackage | SdCliServerPackage | SdCliClientPackage;
@@ -1,111 +0,0 @@
1
- import { FsUtil } from "@simplysm/sd-core-node";
2
- import { ISdClientPackageConfig, ISdPackageBuildResult, ITsconfig } from "../commons";
3
- import * as path from "path";
4
- import { ObjectUtil } from "@simplysm/sd-core-common";
5
- import { SdCliNgClientBuilder } from "../builders/SdCliNgClientBuilder";
6
- import { NextHandleFunction } from "connect";
7
- import { SdCliPackageBase } from "./SdCliPackageBase";
8
- import { SdCliPublisher } from "../builders/SdCliPublisher";
9
-
10
- export class SdCliClientPackage extends SdCliPackageBase {
11
- public on(event: "change", listener: (target: "node" | "browser" | undefined) => void): this;
12
- public on(event: "complete", listener: (target: "node" | "browser" | undefined, results: ISdPackageBuildResult[]) => void): this;
13
- public on(event: string | symbol, listener: (...args: any[]) => void): this {
14
- return super.on(event, listener);
15
- }
16
-
17
- public constructor(public readonly rootPath: string,
18
- public readonly config: ISdClientPackageConfig,
19
- public readonly skipProcesses: ("lint" | "genNgModule")[],
20
- public readonly _serverPath?: string) {
21
- super(rootPath);
22
- }
23
-
24
- public async buildAsync(): Promise<void> {
25
- await this._genBuildTsconfigAsync();
26
-
27
- const targets = this.config.platforms?.map((item) => item.type) ?? ["browser"];
28
-
29
- const buildTsconfigFilePath = path.resolve(this.rootPath, `sd-tsconfig.json`);
30
-
31
- await targets.parallelAsync(async (target) => {
32
- const builder = new SdCliNgClientBuilder(this.rootPath, buildTsconfigFilePath, process.cwd(), this.config, target, this.skipProcesses);
33
-
34
- await builder
35
- .on("change", () => {
36
- this.emit("change", target);
37
- })
38
- .on("complete", (results) => {
39
- this.emit("complete", target, results);
40
- })
41
- .buildAsync();
42
- });
43
- }
44
-
45
- public async watchAsync(): Promise<NextHandleFunction[]> {
46
- await this._genBuildTsconfigAsync();
47
-
48
- const targets = this.config.platforms?.map((item) => item.type) ?? ["browser"];
49
-
50
- const buildTsconfigFilePath = path.resolve(this.rootPath, `sd-tsconfig.json`);
51
- const handlersArray = await targets.parallelAsync(async (target) => {
52
- const builder = new SdCliNgClientBuilder(this.rootPath, buildTsconfigFilePath, process.cwd(), this.config, target, this.skipProcesses);
53
-
54
- return await builder
55
- .on("change", () => {
56
- this.emit("change", target);
57
- })
58
- .on("complete", (results) => {
59
- this.emit("complete", target, results);
60
- })
61
- .watchAsync(this._serverPath);
62
- });
63
-
64
- return handlersArray.mapMany();
65
- }
66
-
67
- public async publishAsync(): Promise<void> {
68
- if (this.config.publish) {
69
- const publisher = new SdCliPublisher(
70
- this.config.publish,
71
- path.resolve(this.rootPath, "dist"),
72
- this.npmConfig.version
73
- );
74
- await publisher.runAsync();
75
- }
76
- }
77
-
78
- private async _genBuildTsconfigAsync(): Promise<void> {
79
- const baseTsconfigFilePath = path.resolve(this.rootPath, "tsconfig.json");
80
- const baseTsconfig: ITsconfig = await FsUtil.readJsonAsync(baseTsconfigFilePath);
81
-
82
- const buildTsconfig: ITsconfig = ObjectUtil.clone(baseTsconfig);
83
-
84
- buildTsconfig.compilerOptions = buildTsconfig.compilerOptions ?? {};
85
- delete buildTsconfig.compilerOptions.baseUrl;
86
- delete buildTsconfig.compilerOptions.paths;
87
- delete buildTsconfig.compilerOptions.declarationDir;
88
- buildTsconfig.compilerOptions = {
89
- ...buildTsconfig.compilerOptions,
90
- module: "es2020",
91
- target: "es2015",
92
- lib: ["es2015", "dom"],
93
- outDir: "dist",
94
- declaration: false,
95
- baseUrl: this.rootPath
96
- };
97
-
98
- buildTsconfig.angularCompilerOptions = {
99
- ...buildTsconfig.angularCompilerOptions ?? {},
100
- enableI18nLegacyMessageIdFormat: false,
101
- strictInjectionParameters: true,
102
- strictInputAccessModifiers: true,
103
- strictTemplates: true,
104
- strictInputTypes: false,
105
- strictOutputEventTypes: false
106
- };
107
-
108
- const buildTsconfigFilePath = path.resolve(this.rootPath, `sd-tsconfig.json`);
109
- await FsUtil.writeJsonAsync(buildTsconfigFilePath, buildTsconfig, { space: 2 });
110
- }
111
- }