@simplysm/sd-cli 6.0.19 → 6.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +1 -2
- package/dist-node/bin/sd-cli.js +25 -8
- package/dist-node/bin/sd-cli.js.map +1 -1
- package/dist-node/build-tools/SdCliIndexFileGenerator.js +51 -0
- package/dist-node/build-tools/SdCliIndexFileGenerator.js.map +1 -0
- package/dist-node/build-tools/SdCliNgModuleFilesGenerator.js +621 -0
- package/dist-node/build-tools/SdCliNgModuleFilesGenerator.js.map +1 -0
- package/dist-node/build-tools/metadata/SdAotMetadataReader.js +270 -0
- package/dist-node/build-tools/metadata/SdAotMetadataReader.js.map +1 -0
- package/dist-node/build-tools/metadata/SdIvyMetadataReader.js +101 -0
- package/dist-node/build-tools/metadata/SdIvyMetadataReader.js.map +1 -0
- package/dist-node/build-tools/metadata/SdMyMetadataReader.js +298 -0
- package/dist-node/build-tools/metadata/SdMyMetadataReader.js.map +1 -0
- package/dist-node/{build-tools → builders}/SdCliJavascriptLinter.js +1 -1
- package/dist-node/builders/SdCliJavascriptLinter.js.map +1 -0
- package/dist-node/{build-tools → builders}/SdCliNgClientBuilder.js +176 -102
- package/dist-node/builders/SdCliNgClientBuilder.js.map +1 -0
- package/dist-node/builders/SdCliNgLibraryBuilder.js +238 -0
- package/dist-node/builders/SdCliNgLibraryBuilder.js.map +1 -0
- package/dist-node/{build-tools → builders}/SdCliPublisher.js +0 -0
- package/dist-node/builders/SdCliPublisher.js.map +1 -0
- package/dist-node/{build-tools → builders}/SdCliServerBuilder.js +8 -6
- package/dist-node/builders/SdCliServerBuilder.js.map +1 -0
- package/dist-node/builders/SdCliTypescriptBuilder.js +304 -0
- package/dist-node/builders/SdCliTypescriptBuilder.js.map +1 -0
- package/dist-node/entry-points/SdCliLocalUpdater.js +9 -8
- package/dist-node/entry-points/SdCliLocalUpdater.js.map +1 -1
- package/dist-node/entry-points/SdCliProject.js +11 -9
- package/dist-node/entry-points/SdCliProject.js.map +1 -1
- package/dist-node/packages/SdCliClientPackage.js +12 -2
- package/dist-node/packages/SdCliClientPackage.js.map +1 -1
- package/dist-node/packages/SdCliLibraryPackage.js +17 -9
- package/dist-node/packages/SdCliLibraryPackage.js.map +1 -1
- package/dist-node/packages/SdCliServerPackage.js +2 -2
- package/dist-node/packages/SdCliServerPackage.js.map +1 -1
- package/dist-node/utils/SdCliFileCrypto.js +76 -0
- package/dist-node/utils/SdCliFileCrypto.js.map +1 -0
- package/dist-node/utils/SdProjectConfigUtil.js +1 -1
- package/dist-node/utils/SdProjectConfigUtil.js.map +1 -1
- package/dist-node/utils/SdWebpackUtil.js +12 -3
- package/dist-node/utils/SdWebpackUtil.js.map +1 -1
- package/dist-node/workers/lib-build-worker.js +7 -6
- package/dist-node/workers/lib-build-worker.js.map +1 -1
- package/dist-types/build-tools/SdCliIndexFileGenerator.d.ts +12 -0
- package/dist-types/build-tools/SdCliNgModuleFilesGenerator.d.ts +42 -0
- package/dist-types/build-tools/metadata/SdAotMetadataReader.d.ts +57 -0
- package/dist-types/build-tools/metadata/SdIvyMetadataReader.d.ts +41 -0
- package/dist-types/build-tools/metadata/SdMyMetadataReader.d.ts +57 -0
- package/dist-types/{build-tools → builders}/SdCliJavascriptLinter.d.ts +0 -0
- package/dist-types/{build-tools → builders}/SdCliNgClientBuilder.d.ts +1 -1
- package/dist-types/builders/SdCliNgLibraryBuilder.d.ts +27 -0
- package/dist-types/{build-tools → builders}/SdCliPublisher.d.ts +0 -0
- package/dist-types/{build-tools → builders}/SdCliServerBuilder.d.ts +0 -0
- package/dist-types/builders/SdCliTypescriptBuilder.d.ts +46 -0
- package/dist-types/commons.d.ts +11 -3
- package/dist-types/packages/SdCliClientPackage.d.ts +1 -1
- package/dist-types/utils/SdCliFileCrypto.d.ts +7 -0
- package/dist-types/utils/SdWebpackUtil.d.ts +1 -0
- package/package.json +10 -7
- package/schema/schema.json +247 -0
- package/src/bin/sd-cli.ts +37 -14
- package/src/build-tools/SdCliIndexFileGenerator.ts +61 -0
- package/src/build-tools/SdCliNgModuleFilesGenerator.ts +837 -0
- package/src/build-tools/metadata/SdAotMetadataReader.ts +368 -0
- package/src/build-tools/metadata/SdIvyMetadataReader.ts +152 -0
- package/src/build-tools/metadata/SdMyMetadataReader.ts +379 -0
- package/src/{build-tools → builders}/SdCliJavascriptLinter.ts +1 -1
- package/src/{build-tools → builders}/SdCliNgClientBuilder.ts +209 -111
- package/src/builders/SdCliNgLibraryBuilder.ts +336 -0
- package/src/{build-tools → builders}/SdCliPublisher.ts +0 -0
- package/src/{build-tools → builders}/SdCliServerBuilder.ts +14 -8
- package/src/builders/SdCliTypescriptBuilder.ts +488 -0
- package/src/commons.ts +11 -3
- package/src/entry-points/SdCliLocalUpdater.ts +9 -8
- package/src/entry-points/SdCliProject.ts +12 -9
- package/src/packages/SdCliClientPackage.ts +14 -3
- package/src/packages/SdCliLibraryPackage.ts +19 -11
- package/src/packages/SdCliServerPackage.ts +2 -2
- package/src/utils/SdCliFileCrypto.ts +87 -0
- package/src/utils/SdCliUtils.ts +56 -0
- package/src/utils/SdProjectConfigUtil.ts +1 -1
- package/src/utils/SdWebpackUtil.ts +13 -3
- package/src/workers/lib-build-worker.ts +8 -7
- package/dist-node/build-tools/SdCliJavascriptLinter.js.map +0 -1
- package/dist-node/build-tools/SdCliNgClientBuilder.js.map +0 -1
- package/dist-node/build-tools/SdCliNgLibraryBuilder.js +0 -164
- package/dist-node/build-tools/SdCliNgLibraryBuilder.js.map +0 -1
- package/dist-node/build-tools/SdCliPublisher.js.map +0 -1
- package/dist-node/build-tools/SdCliServerBuilder.js.map +0 -1
- package/dist-node/build-tools/SdCliTypescriptBuilder.js +0 -316
- package/dist-node/build-tools/SdCliTypescriptBuilder.js.map +0 -1
- package/dist-node/build-tools/SdCliTypescriptIndexFileGenerator.js +0 -75
- package/dist-node/build-tools/SdCliTypescriptIndexFileGenerator.js.map +0 -1
- package/dist-types/build-tools/SdCliNgLibraryBuilder.d.ts +0 -23
- package/dist-types/build-tools/SdCliTypescriptBuilder.d.ts +0 -37
- package/dist-types/build-tools/SdCliTypescriptIndexFileGenerator.d.ts +0 -12
- package/src/build-tools/SdCliNgLibraryBuilder.ts +0 -225
- package/src/build-tools/SdCliTypescriptBuilder.ts +0 -424
- package/src/build-tools/SdCliTypescriptIndexFileGenerator.ts +0 -93
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import * as ts from "typescript";
|
|
2
|
+
import { ISdAutoIndexConfig, ISdPackageBuildResult, ITsconfig } 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 { FsUtil, PathUtil } from "@simplysm/sd-core-node";
|
|
14
|
+
import * as os from "os";
|
|
15
|
+
import * as nodeSass from "node-sass";
|
|
16
|
+
import { createHash } from "crypto";
|
|
17
|
+
import { SdCliNgModuleFilesGenerator } from "../build-tools/SdCliNgModuleFilesGenerator";
|
|
18
|
+
import { OptimizeFor } from "@angular/compiler-cli/src/ngtsc/typecheck/api";
|
|
19
|
+
import { ModuleMetadata } from "@angular/compiler-cli/src/metadata/schema";
|
|
20
|
+
|
|
21
|
+
export class SdCliNgLibraryBuilder extends SdCliTypescriptBuilder {
|
|
22
|
+
protected _ngProgram?: NgtscProgram;
|
|
23
|
+
protected _ngCompiler?: NgCompiler;
|
|
24
|
+
private readonly _ngccProcessingCache = new NgccProcessingCache();
|
|
25
|
+
|
|
26
|
+
private readonly _moduleFilesGenerator = new SdCliNgModuleFilesGenerator(this.rootPath);
|
|
27
|
+
|
|
28
|
+
protected override readonly _fileCache = new Map<string, (ITsBuildFileCache & { scssDependencies?: string[] })>();
|
|
29
|
+
|
|
30
|
+
public constructor(public rootPath: string,
|
|
31
|
+
public tsconfigFilePath: string,
|
|
32
|
+
ignoreProcesses: ("emit" | "check" | "lint" | "genIndex" | "genNgModule")[],
|
|
33
|
+
public autoIndexConfig: ISdAutoIndexConfig | undefined) {
|
|
34
|
+
super(rootPath, tsconfigFilePath, ignoreProcesses as ("emit" | "check" | "lint" | "genIndex")[], autoIndexConfig);
|
|
35
|
+
this.ignoreProcesses = ignoreProcesses;
|
|
36
|
+
|
|
37
|
+
const tsconfig: ITsconfig = FsUtil.readJson(this.tsconfigFilePath);
|
|
38
|
+
this._parsedTsconfig = {
|
|
39
|
+
...this._parsedTsconfig,
|
|
40
|
+
options: {
|
|
41
|
+
baseUrl: path.dirname(this.tsconfigFilePath),
|
|
42
|
+
...this._parsedTsconfig.options,
|
|
43
|
+
...tsconfig.angularCompilerOptions
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
protected override async _runProgramAsync(dirtyFilePaths: string[]): Promise<ISdPackageBuildResult[]> {
|
|
49
|
+
this._logger.debug("빌드", dirtyFilePaths);
|
|
50
|
+
|
|
51
|
+
if (!this._ngCompiler) throw new NeverEntryError();
|
|
52
|
+
if (!this._builder) throw new NeverEntryError();
|
|
53
|
+
|
|
54
|
+
const diagnostics: ts.Diagnostic[] = [];
|
|
55
|
+
|
|
56
|
+
if (!this.ignoreProcesses.includes("check")) {
|
|
57
|
+
diagnostics.push(
|
|
58
|
+
...this._ngCompiler.getOptionDiagnostics(),
|
|
59
|
+
...this._builder.getOptionsDiagnostics(),
|
|
60
|
+
...this._builder.getGlobalDiagnostics()
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
await this._ngCompiler.analyzeAsync();
|
|
64
|
+
|
|
65
|
+
for (const filePath of dirtyFilePaths) {
|
|
66
|
+
const sourceFile = this._builder.getSourceFile(filePath);
|
|
67
|
+
if (!sourceFile) continue;
|
|
68
|
+
|
|
69
|
+
if (this._ngCompiler.ignoreForDiagnostics.has(sourceFile)) continue;
|
|
70
|
+
if (sourceFile.isDeclarationFile) continue;
|
|
71
|
+
|
|
72
|
+
diagnostics.push(
|
|
73
|
+
...this._builder.getSyntacticDiagnostics(sourceFile),
|
|
74
|
+
...this._builder.getSemanticDiagnostics(sourceFile),
|
|
75
|
+
...this._ngCompiler.getDiagnosticsForFile(sourceFile, OptimizeFor.WholeProgram)
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!this.ignoreProcesses.includes("emit")) {
|
|
81
|
+
const transformers = this._ngCompiler.prepareEmit().transformers;
|
|
82
|
+
|
|
83
|
+
for (const filePath of dirtyFilePaths) {
|
|
84
|
+
const sourceFile = this._builder.getSourceFile(filePath);
|
|
85
|
+
if (!sourceFile) continue;
|
|
86
|
+
if (this._ngCompiler.ignoreForEmit.has(sourceFile)) continue;
|
|
87
|
+
if (sourceFile.isDeclarationFile) continue;
|
|
88
|
+
|
|
89
|
+
this._builder.emit(sourceFile, undefined, undefined, undefined, transformers);
|
|
90
|
+
|
|
91
|
+
if (this._parsedTsconfig.options.declaration) {
|
|
92
|
+
if (sourceFile.fileName.endsWith(".ts") && !sourceFile.fileName.endsWith(".d.ts")) {
|
|
93
|
+
const metadata = this._getMetadata(sourceFile);
|
|
94
|
+
if (metadata) {
|
|
95
|
+
this._writeMetadataFile(sourceFile, metadata);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const result = diagnostics.map((item) => SdTsDiagnosticUtil.convertDiagnosticsToResult(item)).filterExists();
|
|
103
|
+
|
|
104
|
+
this._logger.debug("빌드 결과", result);
|
|
105
|
+
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private _writeMetadataFile(sourceFile: ts.SourceFile, metadata: ModuleMetadata): void {
|
|
110
|
+
const metadataText = JSON.stringify([metadata]);
|
|
111
|
+
const outFileName = path.resolve(
|
|
112
|
+
this._parsedTsconfig.options.declarationDir!,
|
|
113
|
+
path.relative(path.resolve(this.rootPath, "src"), sourceFile.fileName)
|
|
114
|
+
).replace(/\.ts$/, ".sd-metadata.json");
|
|
115
|
+
this._cacheCompilerHost!.writeFile(outFileName, metadataText, false, undefined, [sourceFile]);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private _getMetadata(sourceFile: ts.SourceFile): ModuleMetadata | undefined {
|
|
119
|
+
return new MetadataCollector().getMetadata(sourceFile, true);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public override async reloadProgramAsync(watch: boolean): Promise<string[]> {
|
|
123
|
+
this._logger.debug("프로그램 리로드");
|
|
124
|
+
|
|
125
|
+
this._moduleResolutionCache = ts.createModuleResolutionCache(this.rootPath, (s) => s, this._parsedTsconfig.options);
|
|
126
|
+
this._cacheCompilerHost = await this._createCacheCompilerHostAsync(this._parsedTsconfig, this._moduleResolutionCache);
|
|
127
|
+
|
|
128
|
+
this._ngProgram = new NgtscProgram(
|
|
129
|
+
this._parsedTsconfig.fileNames,
|
|
130
|
+
this._parsedTsconfig.options,
|
|
131
|
+
this._cacheCompilerHost,
|
|
132
|
+
this._ngProgram
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
this._ngCompiler = this._ngProgram.compiler;
|
|
136
|
+
this._program = this._ngProgram.getTsProgram();
|
|
137
|
+
|
|
138
|
+
const baseGetSourceFiles = this._program.getSourceFiles;
|
|
139
|
+
this._program.getSourceFiles = function (...parameters) {
|
|
140
|
+
const sourceFiles: readonly (ts.SourceFile & { version?: string })[] = baseGetSourceFiles(...parameters);
|
|
141
|
+
|
|
142
|
+
for (const sourceFile of sourceFiles) {
|
|
143
|
+
if (sourceFile.version === undefined) {
|
|
144
|
+
sourceFile.version = createHash("sha256").update(sourceFile.text).digest("hex");
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return sourceFiles;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
if (watch) {
|
|
152
|
+
const builder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(
|
|
153
|
+
this._program,
|
|
154
|
+
this._cacheCompilerHost,
|
|
155
|
+
this._builder as ts.EmitAndSemanticDiagnosticsBuilderProgram
|
|
156
|
+
);
|
|
157
|
+
this._builder = builder;
|
|
158
|
+
|
|
159
|
+
const affectedFilePaths: string[] = [];
|
|
160
|
+
while (true) {
|
|
161
|
+
const result = builder.getSemanticDiagnosticsOfNextAffectedFile(undefined, (sourceFile) => {
|
|
162
|
+
if (this._ngCompiler!.ignoreForDiagnostics.has(sourceFile) && sourceFile.fileName.endsWith(".ngtypecheck.ts")) {
|
|
163
|
+
const originalFilename = sourceFile.fileName.slice(0, -15) + ".ts";
|
|
164
|
+
const originalSourceFile = builder.getSourceFile(originalFilename);
|
|
165
|
+
if (originalSourceFile) {
|
|
166
|
+
affectedFilePaths.push(originalSourceFile.fileName);
|
|
167
|
+
}
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
if (!result) break;
|
|
174
|
+
|
|
175
|
+
if ("fileName" in result.affected) {
|
|
176
|
+
affectedFilePaths.push(result.affected.fileName);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const result = affectedFilePaths.distinct();
|
|
181
|
+
|
|
182
|
+
this._logger.debug("프로그램 리로드", result);
|
|
183
|
+
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
this._builder = ts.createAbstractBuilder(this._program, this._cacheCompilerHost);
|
|
188
|
+
const result = this._builder.getSourceFiles().map((item) => item.fileName).distinct();
|
|
189
|
+
|
|
190
|
+
this._logger.debug("프로그램 리로드", result);
|
|
191
|
+
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
protected override _deleteFileCaches(filePaths: string[]): void {
|
|
197
|
+
super._deleteFileCaches(filePaths);
|
|
198
|
+
this._moduleFilesGenerator.deleteFileCaches(filePaths);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
public async generateAdditionalFilesAsync(dirtyFilePaths: string[], watch: boolean): Promise<ITsGenResult> {
|
|
202
|
+
const result: ITsGenResult = { dirtyFilePaths: [], result: [] };
|
|
203
|
+
|
|
204
|
+
// index.ts 파일 생성
|
|
205
|
+
const genIndexResult = await super._generateIndexFileAsync(watch);
|
|
206
|
+
result.result.push(...genIndexResult.result);
|
|
207
|
+
result.dirtyFilePaths.push(...genIndexResult.dirtyFilePaths);
|
|
208
|
+
|
|
209
|
+
// Angular Module 및 RoutingModule 생성
|
|
210
|
+
const genModuleResult = await this._generateModuleFilesAsync(
|
|
211
|
+
[...dirtyFilePaths, ...genIndexResult.dirtyFilePaths].distinct()
|
|
212
|
+
, watch
|
|
213
|
+
);
|
|
214
|
+
result.result.push(...genModuleResult.result);
|
|
215
|
+
result.dirtyFilePaths.push(...genModuleResult.dirtyFilePaths);
|
|
216
|
+
|
|
217
|
+
// 'Angular Module 및 RoutingModule 생성'중에 변경사항이 있다면, index.ts 다시 생성
|
|
218
|
+
if (genModuleResult.dirtyFilePaths.length > 0) {
|
|
219
|
+
const newGenIndexResult = await super._generateIndexFileAsync(watch);
|
|
220
|
+
result.result.push(...newGenIndexResult.result);
|
|
221
|
+
result.dirtyFilePaths.push(...newGenIndexResult.dirtyFilePaths);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return {
|
|
225
|
+
dirtyFilePaths: result.dirtyFilePaths.distinct(),
|
|
226
|
+
result: result.result.distinct()
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
private async _generateModuleFilesAsync(dirtyFilePaths: string[], watch: boolean): Promise<ITsGenResult> {
|
|
231
|
+
this._logger.debug("Angular Module, RoutingModule 생성", dirtyFilePaths);
|
|
232
|
+
|
|
233
|
+
const result: ITsGenResult = { dirtyFilePaths: [], result: [] };
|
|
234
|
+
if (this.ignoreProcesses.includes("genNgModule")) return result;
|
|
235
|
+
|
|
236
|
+
const reloadResult = await this._moduleFilesGenerator.reloadSourceFilesAsync(
|
|
237
|
+
dirtyFilePaths,
|
|
238
|
+
this._cacheCompilerHost!,
|
|
239
|
+
this._moduleResolutionCache!,
|
|
240
|
+
this._ngProgram!
|
|
241
|
+
);
|
|
242
|
+
result.result.push(...reloadResult.result);
|
|
243
|
+
|
|
244
|
+
if (!reloadResult.changed) return result;
|
|
245
|
+
|
|
246
|
+
const generateResult = await this._moduleFilesGenerator.generateAsync();
|
|
247
|
+
result.result.push(...generateResult.result);
|
|
248
|
+
if (generateResult.changedFilePaths.length > 0) {
|
|
249
|
+
result.dirtyFilePaths = await this.reloadChangedProgramAsync(generateResult.changedFilePaths, watch);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
this._logger.debug("Angular Module, RoutingModule 생성 결과", result);
|
|
253
|
+
|
|
254
|
+
return result;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
protected override async _createCacheCompilerHostAsync(parsedTsconfig: ts.ParsedCommandLine, moduleResolutionCache: ts.ModuleResolutionCache): Promise<ts.CompilerHost> {
|
|
258
|
+
const tsCacheCompilerHost = await super._createCacheCompilerHostAsync(parsedTsconfig, moduleResolutionCache);
|
|
259
|
+
|
|
260
|
+
const ngccProcessor = new NgccProcessor(
|
|
261
|
+
this._ngccProcessingCache,
|
|
262
|
+
this.tsconfigFilePath,
|
|
263
|
+
parsedTsconfig.options,
|
|
264
|
+
parsedTsconfig.fileNames.map((item) => ({ url: item }) as EntryPointNode)
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
await ngccProcessor.process();
|
|
268
|
+
|
|
269
|
+
const ngCompilerHost = ngccTransformCompilerHost(
|
|
270
|
+
tsCacheCompilerHost,
|
|
271
|
+
parsedTsconfig.options,
|
|
272
|
+
ngccProcessor,
|
|
273
|
+
moduleResolutionCache
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
const resultCompilerHost = { ...ngCompilerHost };
|
|
277
|
+
|
|
278
|
+
resultCompilerHost.getSourceFile = (fileName: string, languageVersion: ts.ScriptTarget) => {
|
|
279
|
+
const cache = this._fileCache.getOrCreate(PathUtil.posix(fileName), {});
|
|
280
|
+
if (!cache.sourceFile) {
|
|
281
|
+
const orgContent = ngCompilerHost.readFile.call(resultCompilerHost, fileName);
|
|
282
|
+
if (StringUtil.isNullOrEmpty(orgContent)) {
|
|
283
|
+
cache.sourceFile = undefined;
|
|
284
|
+
cache.scssDependencies = undefined;
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
const scssResult = this._replaceScssToCss(fileName, orgContent);
|
|
288
|
+
cache.sourceFile = ts.createSourceFile(fileName, scssResult.content, languageVersion);
|
|
289
|
+
cache.scssDependencies = scssResult.dependencies;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return cache.sourceFile;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
return resultCompilerHost;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
private _replaceScssToCss(filePath: string, content: string): { content: string; dependencies: string[] } {
|
|
299
|
+
const scssRegex = /\/\* *language=SCSS *\*\/ *[`"'](((?!['"`]\)?[\],][,;]?[\r\n\\])(.|\r|\n))*)['"`]/;
|
|
300
|
+
|
|
301
|
+
const matches = content.match(new RegExp(scssRegex, "gi"));
|
|
302
|
+
if (!matches) {
|
|
303
|
+
return { content, dependencies: [] };
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const results = matches.map((match) => nodeSass.renderSync({
|
|
307
|
+
file: filePath,
|
|
308
|
+
data: scssRegex.exec(match)?.[1],
|
|
309
|
+
precision: 8,
|
|
310
|
+
includePaths: [],
|
|
311
|
+
outputStyle: "expanded",
|
|
312
|
+
sourceMapEmbed: false,
|
|
313
|
+
sourceMap: false
|
|
314
|
+
}));
|
|
315
|
+
|
|
316
|
+
const deps = results.mapMany((result) => result.stats.includedFiles).map((item) => path.resolve(item));
|
|
317
|
+
|
|
318
|
+
let i = 0;
|
|
319
|
+
const newContent = content.replace(new RegExp(scssRegex, "gi"), () => {
|
|
320
|
+
let result = "`" + results[i].css.toString() + "`";
|
|
321
|
+
const prev = matches[i];
|
|
322
|
+
|
|
323
|
+
const diffCount = Array.from(prev).filter((item) => item === "\n").length
|
|
324
|
+
- Array.from(result).filter((item) => item === "\n").length;
|
|
325
|
+
|
|
326
|
+
for (let j = 0; j < diffCount; j++) {
|
|
327
|
+
result += os.EOL;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
i += 1;
|
|
331
|
+
return result;
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
return { content: newContent, dependencies: deps };
|
|
335
|
+
}
|
|
336
|
+
}
|
|
File without changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
2
|
import { INpmConfig, ISdPackageBuildResult, ISdServerPackageConfig, ITsconfig } from "../commons";
|
|
3
3
|
import * as ts from "typescript";
|
|
4
|
-
import { FsUtil, PathUtil } from "@simplysm/sd-core-node";
|
|
4
|
+
import { FsUtil, Logger, PathUtil } from "@simplysm/sd-core-node";
|
|
5
5
|
import { ObjectUtil, StringUtil, Wait } from "@simplysm/sd-core-common";
|
|
6
6
|
import * as webpack from "webpack";
|
|
7
7
|
import * as path from "path";
|
|
@@ -10,7 +10,7 @@ import { DedupeModuleResolvePlugin } from "@angular-devkit/build-angular/src/web
|
|
|
10
10
|
import { LicenseWebpackPlugin } from "license-webpack-plugin";
|
|
11
11
|
import { SdWebpackUtil } from "../utils/SdWebpackUtil";
|
|
12
12
|
import { ErrorInfo } from "ts-loader/dist/interfaces";
|
|
13
|
-
import { LintResult
|
|
13
|
+
import { LintResult } from "eslint-webpack-plugin/declarations/options";
|
|
14
14
|
import * as os from "os";
|
|
15
15
|
import { SdServiceServer } from "@simplysm/sd-service-node";
|
|
16
16
|
import decache from "decache";
|
|
@@ -69,13 +69,13 @@ export class SdCliServerBuilder extends EventEmitter {
|
|
|
69
69
|
// .config.json 파일 쓰기
|
|
70
70
|
|
|
71
71
|
const targetPath = path.resolve(this.parsedTsconfig.options.outDir!, ".config.json");
|
|
72
|
-
FsUtil.
|
|
72
|
+
await FsUtil.writeFileAsync(targetPath, JSON.stringify(this.config.configs ?? {}, undefined, 2));
|
|
73
73
|
|
|
74
74
|
// pm2.json 파일 쓰기
|
|
75
75
|
if (this.config.pm2 !== undefined && this.config.pm2 !== false) {
|
|
76
76
|
const npmConfig = this._getNpmConfig(this.rootPath)!;
|
|
77
77
|
const pm2DistPath = path.resolve(this.parsedTsconfig.options.outDir!, "pm2.json");
|
|
78
|
-
FsUtil.
|
|
78
|
+
await FsUtil.writeFileAsync(pm2DistPath, JSON.stringify(ObjectUtil.merge(
|
|
79
79
|
{
|
|
80
80
|
"name": npmConfig.name.replace(/@/g, "").replace(/\//g, "-"),
|
|
81
81
|
"script": path.basename(path.resolve(this.parsedTsconfig.options.outDir!, "main.js")),
|
|
@@ -100,7 +100,7 @@ export class SdCliServerBuilder extends EventEmitter {
|
|
|
100
100
|
// iis 파일 쓰기
|
|
101
101
|
if (this.config.iis) {
|
|
102
102
|
const iisDistPath = path.resolve(this.parsedTsconfig.options.outDir!, "web.config");
|
|
103
|
-
FsUtil.
|
|
103
|
+
await FsUtil.writeFileAsync(iisDistPath, `
|
|
104
104
|
<configuration>
|
|
105
105
|
<system.webServer>
|
|
106
106
|
<webSocket enabled="false" />
|
|
@@ -135,7 +135,7 @@ export class SdCliServerBuilder extends EventEmitter {
|
|
|
135
135
|
|
|
136
136
|
// CopyWebpackPlugin 대신 직접 카피
|
|
137
137
|
|
|
138
|
-
for (const item of ["
|
|
138
|
+
for (const item of ["assets/"]) {
|
|
139
139
|
await FsUtil.copyAsync(path.resolve(this.rootPath, "src", item), path.resolve(this.parsedTsconfig.options.outDir!, item));
|
|
140
140
|
}
|
|
141
141
|
|
|
@@ -168,7 +168,7 @@ export class SdCliServerBuilder extends EventEmitter {
|
|
|
168
168
|
// .config.json 파일 쓰기
|
|
169
169
|
|
|
170
170
|
const configDistPath = path.resolve(this.parsedTsconfig.options.outDir!, ".config.json");
|
|
171
|
-
FsUtil.
|
|
171
|
+
await FsUtil.writeFileAsync(configDistPath, JSON.stringify(this.config.configs ?? {}, undefined, 2));
|
|
172
172
|
|
|
173
173
|
// 결과 변환
|
|
174
174
|
|
|
@@ -206,12 +206,18 @@ export class SdCliServerBuilder extends EventEmitter {
|
|
|
206
206
|
private async _startServerAsync(): Promise<void> {
|
|
207
207
|
await Wait.true(() => this._server === undefined);
|
|
208
208
|
|
|
209
|
+
|
|
209
210
|
const mainFilePath = path.resolve(this.parsedTsconfig.options.outDir!, "main.js");
|
|
211
|
+
|
|
212
|
+
const prevLoggerConfigs = ObjectUtil.clone(Logger.configs);
|
|
210
213
|
this._server = require(mainFilePath) as SdServiceServer | undefined;
|
|
214
|
+
Logger.configs = prevLoggerConfigs;
|
|
215
|
+
|
|
211
216
|
if (!this._server) {
|
|
212
217
|
throw new Error(`${mainFilePath}(0, 0): 'SdServiceServer'를 'export'해야 합니다.`);
|
|
213
218
|
}
|
|
214
219
|
|
|
220
|
+
|
|
215
221
|
await new Promise<void>((resolve) => {
|
|
216
222
|
this._server!.on("ready", () => {
|
|
217
223
|
resolve();
|
|
@@ -339,7 +345,7 @@ export class SdCliServerBuilder extends EventEmitter {
|
|
|
339
345
|
exclude: ["node_modules"],
|
|
340
346
|
fix: false,
|
|
341
347
|
threads: true,
|
|
342
|
-
formatter: (results: LintResult[]
|
|
348
|
+
formatter: (results: LintResult[]) => {
|
|
343
349
|
const resultMessages: string[] = [];
|
|
344
350
|
for (const result of results) {
|
|
345
351
|
for (const msg of result.messages) {
|