@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
@@ -1,301 +0,0 @@
1
- import * as ts from "typescript";
2
- import { ISdAutoIndexConfig, ISdPackageBuildResult } from "../commons";
3
- import * as path from "path";
4
- import { SdTsDiagnosticUtil } from "../utils/SdTsDiagnosticUtil";
5
- import { NgccProcessingCache } from "ng-packagr/lib/ng-package/ngcc-cache";
6
- import { NgccProcessor } from "ng-packagr/lib/ngc/ngcc-processor";
7
- import { EntryPointNode } from "ng-packagr/lib/ng-package/nodes";
8
- import { ngccTransformCompilerHost } from "ng-packagr/lib/ts/ngcc-transform-compiler-host";
9
- import { MetadataCollector, NgtscProgram } from "@angular/compiler-cli";
10
- import { ITsBuildFileCache, ITsGenResult, SdCliTypescriptBuilder } from "./SdCliTypescriptBuilder";
11
- import { NgCompiler } from "@angular/compiler-cli/src/ngtsc/core";
12
- import { NeverEntryError, StringUtil } from "@simplysm/sd-core-common";
13
- import { PathUtil } from "@simplysm/sd-core-node";
14
- import * as os from "os";
15
- import * as nodeSass from "node-sass";
16
- import { SdCliNgModuleFilesGenerator } from "../build-tools/SdCliNgModuleFilesGenerator";
17
- import { OptimizeFor } from "@angular/compiler-cli/src/ngtsc/typecheck/api";
18
- import { ModuleMetadata } from "@angular/compiler-cli/src/metadata/schema";
19
-
20
- export class SdCliNgLibraryBuilder extends SdCliTypescriptBuilder {
21
- protected _ngProgram?: NgtscProgram;
22
- protected _ngCompiler?: NgCompiler;
23
- private readonly _ngccProcessingCache = new NgccProcessingCache();
24
-
25
- private readonly _moduleFilesGenerator = new SdCliNgModuleFilesGenerator(this.rootPath);
26
-
27
- protected override readonly _fileCache = new Map<string, (ITsBuildFileCache & { scssDependencies?: string[] })>();
28
-
29
- public constructor(public rootPath: string,
30
- public tsconfigFilePath: string,
31
- skipProcesses: ("emit" | "check" | "lint" | "genIndex" | "genNgModule")[],
32
- public autoIndexConfig: ISdAutoIndexConfig | undefined) {
33
- super(rootPath, tsconfigFilePath, skipProcesses as ("emit" | "check" | "lint" | "genIndex")[], autoIndexConfig);
34
- this.skipProcesses = skipProcesses;
35
- }
36
-
37
- protected override async _runProgramAsync(dirtyFilePaths: string[]): Promise<ISdPackageBuildResult[]> {
38
- this._logger.debug("빌드", dirtyFilePaths);
39
-
40
- if (!this._ngCompiler) throw new NeverEntryError();
41
- if (!this._builder) throw new NeverEntryError();
42
-
43
- const diagnostics: ts.Diagnostic[] = [];
44
-
45
- if (!this.skipProcesses.includes("check")) {
46
- diagnostics.push(
47
- ...this._ngCompiler.getOptionDiagnostics(),
48
- ...this._builder.getOptionsDiagnostics(),
49
- ...this._builder.getGlobalDiagnostics()
50
- );
51
-
52
- await this._ngCompiler.analyzeAsync();
53
-
54
- for (const sourceFile of this._builder.getSourceFiles()) {
55
- if (this._ngCompiler.ignoreForDiagnostics.has(sourceFile)) continue;
56
- if (sourceFile.isDeclarationFile) continue;
57
-
58
- diagnostics.push(
59
- ...this._builder.getSyntacticDiagnostics(sourceFile),
60
- ...this._builder.getSemanticDiagnostics(sourceFile),
61
- ...this._ngCompiler.getDiagnosticsForFile(sourceFile, OptimizeFor.WholeProgram)
62
- );
63
- }
64
- }
65
-
66
- if (!this.skipProcesses.includes("emit")) {
67
- const transformers = this._ngCompiler.prepareEmit().transformers;
68
-
69
- for (const filePath of dirtyFilePaths) {
70
- const sourceFile = this._builder.getSourceFile(filePath);
71
- if (!sourceFile) continue;
72
- if (this._ngCompiler.ignoreForEmit.has(sourceFile)) continue;
73
- if (sourceFile.isDeclarationFile) continue;
74
-
75
- this._builder.emit(sourceFile, undefined, undefined, undefined, transformers);
76
-
77
- if (this._program!.getCompilerOptions().declaration) {
78
- if (sourceFile.fileName.endsWith(".ts") && !sourceFile.fileName.endsWith(".d.ts")) {
79
- const metadata = this._getMetadata(sourceFile);
80
- if (metadata) {
81
- this._writeMetadataFile(sourceFile, metadata);
82
- }
83
- }
84
- }
85
- }
86
- }
87
-
88
- const result = diagnostics.map((item) => SdTsDiagnosticUtil.convertDiagnosticsToResult(item)).filterExists();
89
-
90
- this._logger.debug("빌드 결과", result);
91
-
92
- return result;
93
- }
94
-
95
- private _writeMetadataFile(sourceFile: ts.SourceFile, metadata: ModuleMetadata): void {
96
- const metadataText = JSON.stringify({
97
- ...metadata,
98
- importAs: this.npmConfig.name
99
- });
100
- const outFileName = path.resolve(
101
- this._program!.getCompilerOptions().declarationDir!,
102
- path.relative(path.resolve(this.rootPath, "src"), sourceFile.fileName)
103
- ).replace(/\.ts$/, ".sd-metadata.json");
104
- this._cacheCompilerHost!.writeFile(outFileName, metadataText, false, undefined, [sourceFile]);
105
- }
106
-
107
- private _getMetadata(sourceFile: ts.SourceFile): ModuleMetadata | undefined {
108
- return new MetadataCollector().getMetadata(sourceFile, false);
109
- }
110
-
111
- public override getParsedTsconfig(): ts.ParsedCommandLine {
112
- return ts.parseJsonConfigFileContent(this._tsconfig, ts.sys, this.rootPath, this._tsconfig.angularCompilerOptions);
113
- }
114
-
115
- public override configProgram(parsedTsconfig: ts.ParsedCommandLine): void {
116
- this._ngProgram = new NgtscProgram(
117
- parsedTsconfig.fileNames,
118
- parsedTsconfig.options,
119
- this._cacheCompilerHost!,
120
- this._ngProgram
121
- );
122
-
123
- this._ngCompiler = this._ngProgram.compiler;
124
- this._program = this._ngProgram.getTsProgram();
125
- }
126
-
127
- public override getSemanticDiagnosticsOfNextAffectedFiles(): string[] | undefined {
128
- const builder = this._builder as ts.SemanticDiagnosticsBuilderProgram;
129
- const affectedFilePaths: string[] = [];
130
- const result = builder.getSemanticDiagnosticsOfNextAffectedFile(undefined, (sourceFile) => {
131
- if (this._ngCompiler!.ignoreForDiagnostics.has(sourceFile) && sourceFile.fileName.endsWith(".ngtypecheck.ts")) {
132
- const originalFilename = sourceFile.fileName.slice(0, -15) + ".ts";
133
- const originalSourceFile = builder.getSourceFile(originalFilename);
134
- if (originalSourceFile) {
135
- affectedFilePaths.push(originalSourceFile.fileName);
136
- }
137
- return true;
138
- }
139
- return false;
140
- });
141
-
142
- if (result && "fileName" in result.affected) {
143
- affectedFilePaths.push(result.affected.fileName);
144
- return affectedFilePaths.distinct();
145
- }
146
- if (!result) {
147
- return undefined;
148
- }
149
-
150
- return [];
151
- }
152
-
153
- protected override _deleteFileCaches(filePaths: string[]): void {
154
- super._deleteFileCaches(filePaths);
155
- this._moduleFilesGenerator.deleteFileCaches(filePaths);
156
- }
157
-
158
- public async generateAdditionalFilesAsync(dirtyFilePaths: string[], watch: boolean): Promise<ITsGenResult> {
159
- const result: ITsGenResult = { dirtyFilePaths: [], result: [] };
160
-
161
- // index.ts 파일 생성
162
- const genIndexResult = await super._generateIndexFileAsync(watch);
163
- result.result.push(...genIndexResult.result);
164
- result.dirtyFilePaths.push(...genIndexResult.dirtyFilePaths);
165
-
166
- // Angular Module 및 RoutingModule 생성
167
- const genModuleResult = await this._generateModuleFilesAsync(
168
- [...dirtyFilePaths, ...genIndexResult.dirtyFilePaths].distinct(),
169
- watch
170
- );
171
- result.result.push(...genModuleResult.result);
172
- result.dirtyFilePaths.push(...genModuleResult.dirtyFilePaths);
173
-
174
- // 'Angular Module 및 RoutingModule 생성'중에 변경사항이 있다면, index.ts 다시 생성
175
- if (genModuleResult.dirtyFilePaths.length > 0) {
176
- const newGenIndexResult = await super._generateIndexFileAsync(watch);
177
- result.result.push(...newGenIndexResult.result);
178
- result.dirtyFilePaths.push(...newGenIndexResult.dirtyFilePaths);
179
- }
180
-
181
- return {
182
- dirtyFilePaths: result.dirtyFilePaths.distinct(),
183
- result: result.result.distinct()
184
- };
185
- }
186
-
187
- private async _generateModuleFilesAsync(dirtyFilePaths: string[], watch: boolean): Promise<ITsGenResult> {
188
- this._logger.debug("Angular Module, RoutingModule 생성", dirtyFilePaths);
189
-
190
- const result: ITsGenResult = { dirtyFilePaths: [], result: [] };
191
- if (this.skipProcesses.includes("genNgModule")) return result;
192
-
193
- const reloadResult = await this._moduleFilesGenerator.reloadSourceFilesAsync(
194
- dirtyFilePaths,
195
- this._cacheCompilerHost!,
196
- this._moduleResolutionCache!,
197
- this._ngProgram!
198
- );
199
- result.result.push(...reloadResult.result);
200
-
201
- if (!reloadResult.changed) return result;
202
-
203
- const generateResult = await this._moduleFilesGenerator.generateAsync();
204
- result.result.push(...generateResult.result);
205
- if (generateResult.changedFilePaths.length > 0) {
206
- const reloadChangedProgramResult = await this.reloadChangedProgramAsync(generateResult.changedFilePaths, watch);
207
- result.dirtyFilePaths = reloadChangedProgramResult.dirtyFilePaths;
208
- result.result.push(...reloadChangedProgramResult.result);
209
- }
210
-
211
- this._logger.debug("Angular Module, RoutingModule 생성 결과", result);
212
-
213
- return result;
214
- }
215
-
216
- protected override async _createCacheCompilerHostAsync(parsedTsconfig: ts.ParsedCommandLine, moduleResolutionCache: ts.ModuleResolutionCache): Promise<ts.CompilerHost> {
217
- const tsCacheCompilerHost = await super._createCacheCompilerHostAsync(parsedTsconfig, moduleResolutionCache);
218
-
219
- const ngccProcessor = new NgccProcessor(
220
- this._ngccProcessingCache,
221
- this.tsconfigFilePath,
222
- parsedTsconfig.options,
223
- parsedTsconfig.fileNames.map((item) => ({ url: item }) as EntryPointNode)
224
- );
225
-
226
- await ngccProcessor.process();
227
-
228
- const ngCompilerHost = ngccTransformCompilerHost(
229
- tsCacheCompilerHost,
230
- parsedTsconfig.options,
231
- ngccProcessor,
232
- moduleResolutionCache
233
- );
234
-
235
- const resultCompilerHost = { ...ngCompilerHost };
236
-
237
- resultCompilerHost.getSourceFile = (fileName: string, languageVersion: ts.ScriptTarget) => {
238
- const cache = this._fileCache.getOrCreate(PathUtil.posix(fileName), {});
239
- if (!cache.sourceFile) {
240
- const orgContent = ngCompilerHost.readFile.call(resultCompilerHost, fileName);
241
- if (StringUtil.isNullOrEmpty(orgContent)) {
242
- cache.sourceFile = undefined;
243
- cache.scssDependencies = undefined;
244
- }
245
- else {
246
- const scssResult = this._replaceScssToCss(fileName, orgContent);
247
- cache.sourceFile = ts.createSourceFile(fileName, scssResult.content, languageVersion);
248
- cache.scssDependencies = scssResult.dependencies;
249
- }
250
- }
251
- return cache.sourceFile;
252
- };
253
-
254
- return resultCompilerHost;
255
- }
256
-
257
- private _replaceScssToCss(filePath: string, content: string): { content: string; dependencies: string[] } {
258
- const scssRegex = /\/\* *language=SCSS *\*\/ *[`"'](((?!['"`]\)?[\],][,;]?[\r\n\\])(.|\r|\n))*)['"`]/;
259
-
260
- const matches = content.match(new RegExp(scssRegex, "gi"));
261
- if (!matches) {
262
- return { content, dependencies: [] };
263
- }
264
-
265
- try {
266
- const results = matches.map((match) => nodeSass.renderSync({
267
- file: filePath,
268
- data: scssRegex.exec(match)?.[1],
269
- precision: 8,
270
- includePaths: [],
271
- outputStyle: "expanded",
272
- sourceMapEmbed: false,
273
- sourceMap: false
274
- }));
275
-
276
- const deps = results.mapMany((result) => result.stats.includedFiles).map((item) => path.resolve(item));
277
-
278
- let i = 0;
279
- const newContent = content.replace(new RegExp(scssRegex, "gi"), () => {
280
- let result = "`" + results[i].css.toString() + "`";
281
- const prev = matches[i];
282
-
283
- const diffCount = Array.from(prev).filter((item) => item === "\n").length
284
- - Array.from(result).filter((item) => item === "\n").length;
285
-
286
- for (let j = 0; j < diffCount; j++) {
287
- result += os.EOL;
288
- }
289
-
290
- i += 1;
291
- return result;
292
- });
293
-
294
- return { content: newContent, dependencies: deps };
295
- }
296
- catch (err) {
297
- this._logger.error(filePath, err);
298
- return { content, dependencies: [] };
299
- }
300
- }
301
- }
@@ -1,144 +0,0 @@
1
- import { ISdFtpPublishConfig, TSdPublishConfig } from "../commons";
2
- import * as path from "path";
3
- import { NumberUtil, StringUtil } from "@simplysm/sd-core-common";
4
- import { FsUtil, PathUtil } from "@simplysm/sd-core-node";
5
- import { SdFtpStorage, SdSFtpStorage } from "@simplysm/sd-storage";
6
- import * as msRestNodeAuth from "@azure/ms-rest-nodeauth";
7
- import { WebSiteManagementClient } from "@azure/arm-appservice";
8
- import * as xml2js from "xml2js";
9
- import * as URL from "url";
10
-
11
- export class SdCliPublisher {
12
- public constructor(private readonly _config: TSdPublishConfig,
13
- private readonly _distPath: string,
14
- private readonly _version?: string) {
15
- }
16
-
17
- public async runAsync(): Promise<void> {
18
- if (this._config.type === "sftp") {
19
- const publishConfig = this._config;
20
- const sftp = new SdSFtpStorage();
21
- await sftp.connectAsync({
22
- host: publishConfig.host,
23
- port: publishConfig.port,
24
- username: publishConfig.username,
25
- password: publishConfig.password
26
- });
27
-
28
- try {
29
- // 결과 파일 업로드
30
- await sftp.uploadDirAsync(this._distPath, publishConfig.path);
31
- await sftp.closeAsync();
32
- }
33
- catch (err) {
34
- try {
35
- await sftp.closeAsync();
36
- }
37
- catch {
38
- }
39
- throw err;
40
- }
41
- }
42
- else if (this._config.type === "local-directory") {
43
- const targetRootPath = this._config.path.replace(/%([^%]*)%/g, (item) => {
44
- const envName = item.replace(/%/g, "");
45
- if (!StringUtil.isNullOrEmpty(this._version) && envName === "SD_VERSION") {
46
- return this._version;
47
- }
48
- return process.env[envName] ?? item;
49
- });
50
-
51
- const filePaths = await FsUtil.globAsync(path.resolve(this._distPath, "**", "*"), { dot: true, nodir: true });
52
-
53
- await filePaths.parallelAsync(async (filePath) => {
54
- const relativeFilePath = path.relative(this._distPath, filePath);
55
- const targetPath = PathUtil.posix(targetRootPath, relativeFilePath);
56
-
57
- await FsUtil.copyAsync(filePath, targetPath);
58
- });
59
- }
60
- else if (this._config.type === "ftp") {
61
- const publishConfig = this._config;
62
- const ftp = new SdFtpStorage();
63
- await ftp.connectAsync({
64
- host: publishConfig.host,
65
- port: publishConfig.port,
66
- username: publishConfig.username,
67
- password: publishConfig.password,
68
- secure: publishConfig.secure
69
- });
70
-
71
- try {
72
- // 결과 파일 업로드
73
- await ftp.uploadDirAsync(this._distPath, publishConfig.path);
74
-
75
- await ftp.closeAsync();
76
- }
77
- catch (err) {
78
- try {
79
- await ftp.closeAsync();
80
- }
81
- catch {
82
- }
83
- throw err;
84
- }
85
- }
86
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
87
- else if (this._config.type === "azure-app-service") {
88
- const creds = await msRestNodeAuth.loginWithUsernamePassword(this._config.username, this._config.password);
89
- const client = new WebSiteManagementClient(creds, this._config.subscriptionId);
90
-
91
- await client.webApps.stop(this._config.resourceGroupName, this._config.serviceName);
92
-
93
- try {
94
- const webappFtpXmlStream = await client.webApps.listPublishingProfileXmlWithSecrets(this._config.resourceGroupName, this._config.serviceName, {
95
- format: "Ftp"
96
- });
97
- const xmlObj = await xml2js.parseStringPromise(webappFtpXmlStream.readableStreamBody!.read());
98
- const xmlFtpConfig = xmlObj.publishData.publishProfile.find((item: any) => item.$.publishMethod === "FTP")!.$;
99
-
100
- const urlObj = URL.parse(xmlFtpConfig.publishUrl, false);
101
-
102
- const ftpConfig: ISdFtpPublishConfig = {
103
- type: "ftp",
104
- host: urlObj.host!,
105
- port: NumberUtil.parseInt(urlObj.port),
106
- path: this._config.path.startsWith("/") ? this._config.path : path.join(urlObj.pathname ?? "", this._config.path),
107
- username: xmlFtpConfig.userName,
108
- password: xmlFtpConfig.userPWD,
109
- secure: true
110
- };
111
-
112
- const ftp = new SdFtpStorage();
113
- await ftp.connectAsync({
114
- host: ftpConfig.host,
115
- port: ftpConfig.port,
116
- username: ftpConfig.username,
117
- password: ftpConfig.password,
118
- secure: ftpConfig.secure
119
- });
120
-
121
- try {
122
- // 결과 파일 업로드
123
- await ftp.uploadDirAsync(this._distPath, ftpConfig.path);
124
-
125
- await ftp.closeAsync();
126
- }
127
- catch (err) {
128
- try {
129
- await ftp.closeAsync();
130
- }
131
- catch {
132
- }
133
- throw err;
134
- }
135
-
136
- await client.webApps.start(this._config.resourceGroupName, this._config.serviceName);
137
- }
138
- catch (err) {
139
- await client.webApps.start(this._config.resourceGroupName, this._config.serviceName);
140
- throw err;
141
- }
142
- }
143
- }
144
- }