@simplysm/sd-cli 11.0.3 → 11.0.5

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 (50) hide show
  1. package/dist/build-cluster.js +1 -1
  2. package/dist/build-cluster.js.map +1 -1
  3. package/dist/build-tools/SdLinter.js +2 -2
  4. package/dist/build-tools/SdLinter.js.map +1 -1
  5. package/dist/build-tools/SdNgBundler.d.ts +23 -0
  6. package/dist/build-tools/SdNgBundler.js +331 -0
  7. package/dist/build-tools/SdNgBundler.js.map +1 -0
  8. package/dist/build-tools/SdTsBundler.d.ts +15 -0
  9. package/dist/build-tools/SdTsBundler.js +96 -0
  10. package/dist/build-tools/SdTsBundler.js.map +1 -0
  11. package/dist/build-tools/SdTsCompiler.d.ts +28 -0
  12. package/dist/build-tools/SdTsCompiler.js +212 -0
  13. package/dist/build-tools/SdTsCompiler.js.map +1 -0
  14. package/dist/builders/SdCliClientBuilder.d.ts +4 -2
  15. package/dist/builders/SdCliClientBuilder.js +60 -297
  16. package/dist/builders/SdCliClientBuilder.js.map +1 -1
  17. package/dist/builders/SdCliServerBuilder.js +79 -216
  18. package/dist/builders/SdCliServerBuilder.js.map +1 -1
  19. package/dist/builders/SdCliTsLibBuilder.d.ts +0 -1
  20. package/dist/builders/SdCliTsLibBuilder.js +35 -33
  21. package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
  22. package/dist/commons.d.ts +7 -0
  23. package/dist/entry/SdCliProject.js +13 -10
  24. package/dist/entry/SdCliProject.js.map +1 -1
  25. package/dist/index.d.ts +3 -1
  26. package/dist/index.js +3 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/server-worker.js +3 -0
  29. package/dist/server-worker.js.map +1 -1
  30. package/dist/utils/SdCliBuildResultUtil.d.ts +1 -1
  31. package/dist/utils/SdCliBuildResultUtil.js +4 -4
  32. package/dist/utils/SdCliBuildResultUtil.js.map +1 -1
  33. package/package.json +14 -12
  34. package/src/build-cluster.ts +1 -1
  35. package/src/build-tools/SdLinter.ts +2 -2
  36. package/src/build-tools/SdNgBundler.ts +404 -0
  37. package/src/build-tools/SdTsBundler.ts +106 -0
  38. package/src/build-tools/SdTsCompiler.ts +304 -0
  39. package/src/builders/SdCliClientBuilder.ts +75 -322
  40. package/src/builders/SdCliServerBuilder.ts +95 -243
  41. package/src/builders/SdCliTsLibBuilder.ts +39 -40
  42. package/src/commons.ts +6 -0
  43. package/src/entry/SdCliProject.ts +17 -12
  44. package/src/index.ts +3 -1
  45. package/src/server-worker.ts +3 -0
  46. package/src/utils/SdCliBuildResultUtil.ts +4 -4
  47. package/dist/build-tools/SdTsIncrementalBuilder.d.ts +0 -31
  48. package/dist/build-tools/SdTsIncrementalBuilder.js +0 -126
  49. package/dist/build-tools/SdTsIncrementalBuilder.js.map +0 -1
  50. package/src/build-tools/SdTsIncrementalBuilder.ts +0 -207
@@ -0,0 +1,212 @@
1
+ import path from "path";
2
+ import ts from "typescript";
3
+ import { SdCliBuildResultUtil } from "../utils/SdCliBuildResultUtil";
4
+ import { FsUtil, Logger, PathUtil } from "@simplysm/sd-core-node";
5
+ import { NgtscProgram } from "@angular/compiler-cli";
6
+ import { createHash } from "crypto";
7
+ import { fileURLToPath, pathToFileURL } from "url";
8
+ import * as sass from "sass";
9
+ export class SdTsCompiler {
10
+ get program() {
11
+ if (!this._program) {
12
+ throw new Error("TS 프로그램 NULL");
13
+ }
14
+ return this._program;
15
+ }
16
+ constructor(_opt) {
17
+ this._opt = _opt;
18
+ this._logger = Logger.get(["simplysm", "sd-cli", "SdTsCompiler"]);
19
+ this._writeFileCache = new Map();
20
+ this._styleDepsCache = new Map();
21
+ this._markedChanges = [];
22
+ //-- tsconfig
23
+ const tsConfigFilePath = path.resolve(_opt.pkgPath, "tsconfig.json");
24
+ const tsConfig = FsUtil.readJson(tsConfigFilePath);
25
+ this._parsedTsConfig = ts.parseJsonConfigFileContent(tsConfig, ts.sys, _opt.pkgPath, {
26
+ ...tsConfig.angularCompilerOptions ?? {},
27
+ ..._opt.emitDts !== undefined ? { declaration: _opt.emitDts } : {}
28
+ });
29
+ //-- vars
30
+ this._isForAngular = Boolean(tsConfig.angularCompilerOptions);
31
+ //-- host
32
+ this._compilerHost = ts.createIncrementalCompilerHost(this._parsedTsConfig.options);
33
+ if (tsConfig.angularCompilerOptions) {
34
+ this._compilerHost["readResource"] = (fileName) => {
35
+ return this._compilerHost.readFile(fileName);
36
+ };
37
+ this._compilerHost["transformResource"] = async (data, context) => {
38
+ if (context.resourceFile != null || context.type !== "style") {
39
+ return null;
40
+ }
41
+ try {
42
+ const scssResult = await sass.compileStringAsync(data, {
43
+ url: new URL(context.containingFile + ".scss"),
44
+ importer: {
45
+ findFileUrl: (url) => pathToFileURL(url)
46
+ },
47
+ logger: sass.Logger.silent
48
+ });
49
+ const styleContent = scssResult.css.toString();
50
+ const deps = scssResult.loadedUrls.slice(1).map((item) => path.resolve(fileURLToPath(item.href)));
51
+ for (const dep of deps) {
52
+ const depCache = this._styleDepsCache.getOrCreate(dep, new Set());
53
+ depCache.add(path.resolve(context.containingFile));
54
+ }
55
+ return { content: styleContent };
56
+ }
57
+ catch (err) {
58
+ this._logger.error("scss 파싱 에러", err);
59
+ return null;
60
+ }
61
+ };
62
+ }
63
+ }
64
+ markChanges(changes) {
65
+ this._markedChanges.push(...changes);
66
+ }
67
+ async buildAsync() {
68
+ const markedChanges = this._markedChanges;
69
+ this._markedChanges = [];
70
+ const distPath = path.resolve(this._opt.pkgPath, "dist");
71
+ const srcFilePaths = await FsUtil.globAsync(path.resolve(this._opt.pkgPath, "src/**/*.{ts,tsx}"));
72
+ const srcFilePathSet = new Set(srcFilePaths);
73
+ if (this._isForAngular) {
74
+ this._ngProgram = new NgtscProgram(srcFilePaths, this._parsedTsConfig.options, this._compilerHost, this._ngProgram);
75
+ this._program = this._ngProgram.getTsProgram();
76
+ const baseGetSourceFiles = this._program.getSourceFiles;
77
+ this._program.getSourceFiles = function (...parameters) {
78
+ const files = baseGetSourceFiles(...parameters);
79
+ for (const file of files) {
80
+ if (file.version === undefined) {
81
+ file.version = createHash("sha256").update(file.text).digest("hex");
82
+ }
83
+ }
84
+ return files;
85
+ };
86
+ }
87
+ else {
88
+ this._program = ts.createProgram(srcFilePaths, this._parsedTsConfig.options, this._compilerHost, this._program);
89
+ }
90
+ this._builder = ts.createSemanticDiagnosticsBuilderProgram(this._program, this._compilerHost, this._builder);
91
+ const diagnostics = [];
92
+ const affectedFilePaths = [];
93
+ if (this._ngProgram) {
94
+ diagnostics.push(...this._ngProgram.compiler.getOptionDiagnostics());
95
+ }
96
+ diagnostics.push(...this._builder.getOptionsDiagnostics(), ...this._builder.getGlobalDiagnostics());
97
+ if (this._ngProgram) {
98
+ await this._ngProgram.compiler.analyzeAsync();
99
+ }
100
+ this._logger.debug(`[${path.basename(this._opt.pkgPath)}] 영향받는 파일 확인중...`);
101
+ while (true) {
102
+ let affectedSourceFile;
103
+ const semanticResult = this._builder.getSemanticDiagnosticsOfNextAffectedFile(undefined, (sourceFile) => {
104
+ //-- ngtypecheck의 org파일 포함 (ngtypecheck 파일는 무시)
105
+ if (this._ngProgram?.compiler.ignoreForDiagnostics.has(sourceFile) && sourceFile.fileName.endsWith(".ngtypecheck.ts")) {
106
+ const orgFileName = sourceFile.fileName.slice(0, -15) + ".ts";
107
+ const orgSourceFile = this._builder.getSourceFile(orgFileName);
108
+ if (orgSourceFile) {
109
+ affectedSourceFile = orgSourceFile;
110
+ }
111
+ return true;
112
+ }
113
+ //-- 소스폴더 파일 포함
114
+ else if (srcFilePathSet.has(path.resolve(sourceFile.fileName))) {
115
+ affectedSourceFile = sourceFile;
116
+ return false;
117
+ }
118
+ //-- 나머지 무시
119
+ else {
120
+ return true;
121
+ }
122
+ });
123
+ if (!semanticResult || !affectedSourceFile)
124
+ break;
125
+ diagnostics.push(...semanticResult.result);
126
+ if ("fileName" in affectedSourceFile) {
127
+ affectedFilePaths.push(path.resolve(affectedSourceFile.fileName));
128
+ }
129
+ }
130
+ if (this._isForAngular) {
131
+ for (const markedChange of markedChanges) {
132
+ const depsSet = this._styleDepsCache.get(markedChange);
133
+ if (depsSet) {
134
+ affectedFilePaths.push(...depsSet);
135
+ }
136
+ }
137
+ affectedFilePaths.distinctThis();
138
+ }
139
+ const globalStyleFilePath = path.resolve(this._opt.pkgPath, "src/styles.scss");
140
+ if (this._opt.globalStyle && FsUtil.exists(globalStyleFilePath) && markedChanges.includes(globalStyleFilePath)) {
141
+ affectedFilePaths.push(globalStyleFilePath);
142
+ affectedFilePaths.distinctThis();
143
+ }
144
+ this._logger.debug(`[${path.basename(this._opt.pkgPath)}] 영향받는 파일 ${this._opt.emit ? "EMIT" : "CHECK"}...`);
145
+ for (const affectedFilePath of affectedFilePaths) {
146
+ if (this._opt.globalStyle && affectedFilePath === globalStyleFilePath) {
147
+ try {
148
+ const content = await FsUtil.readFileAsync(affectedFilePath);
149
+ const scssResult = await sass.compileStringAsync(content, {
150
+ url: new URL(affectedFilePath),
151
+ importer: {
152
+ findFileUrl: (url) => pathToFileURL(url)
153
+ },
154
+ logger: sass.Logger.silent
155
+ });
156
+ const deps = scssResult.loadedUrls.slice(1).map((item) => path.resolve(fileURLToPath(item.href)));
157
+ for (const dep of deps) {
158
+ const depCache = this._styleDepsCache.getOrCreate(dep, new Set());
159
+ depCache.add(affectedFilePath);
160
+ }
161
+ if (this._opt.emit) {
162
+ const outFilePath = path.resolve(this._opt.pkgPath, path.basename(affectedFilePath, path.extname(affectedFilePath)) + ".css");
163
+ this._writeFile(outFilePath, scssResult.css.toString());
164
+ }
165
+ }
166
+ catch (err) {
167
+ this._logger.error(err);
168
+ }
169
+ }
170
+ else {
171
+ const affectedSourceFile = this._builder.getSourceFile(affectedFilePath);
172
+ if (!affectedSourceFile)
173
+ continue;
174
+ const emitResult = this._builder.emit(affectedSourceFile, (filePath, data) => {
175
+ let realFilePath = filePath;
176
+ let realData = data;
177
+ if (PathUtil.isChildPath(realFilePath, path.resolve(distPath, path.basename(this._opt.pkgPath), "src"))) {
178
+ realFilePath = path.resolve(distPath, path.relative(path.resolve(distPath, path.basename(this._opt.pkgPath), "src"), realFilePath));
179
+ if (filePath.endsWith(".js.map")) {
180
+ const sourceMapContents = JSON.parse(realData);
181
+ // remove "../../"
182
+ sourceMapContents.sources[0] = sourceMapContents.sources[0].slice(6);
183
+ realData = JSON.stringify(sourceMapContents);
184
+ }
185
+ }
186
+ this._writeFile(realFilePath, realData);
187
+ }, undefined, !this._opt.emit, { ...this._ngProgram?.compiler.prepareEmit().transformers ?? {} });
188
+ diagnostics.push(...emitResult.diagnostics);
189
+ diagnostics.push(...this._builder.getSyntacticDiagnostics(affectedSourceFile));
190
+ if (this._ngProgram &&
191
+ !affectedSourceFile.isDeclarationFile &&
192
+ !this._ngProgram.compiler.ignoreForEmit.has(affectedSourceFile) &&
193
+ !this._ngProgram.compiler.incrementalCompilation.safeToSkipEmit(affectedSourceFile)) {
194
+ diagnostics.push(...this._ngProgram.compiler.getDiagnosticsForFile(affectedSourceFile, 1));
195
+ }
196
+ }
197
+ }
198
+ this._logger.debug(`[${path.basename(this._opt.pkgPath)}] 영향받는 파일 ${this._opt.emit ? "EMIT" : "CHECK"} 완료`, affectedFilePaths);
199
+ const buildResults = diagnostics.map((item) => SdCliBuildResultUtil.convertFromTsDiag(item, this._opt.emit ? "build" : "check"));
200
+ return {
201
+ affectedFilePaths: affectedFilePaths.filter((item) => !item.endsWith(".scss")),
202
+ results: buildResults
203
+ };
204
+ }
205
+ _writeFile(filePath, data) {
206
+ if (this._writeFileCache.get(filePath) !== data) {
207
+ this._compilerHost.writeFile(filePath, data, false);
208
+ }
209
+ this._writeFileCache.set(filePath, data);
210
+ }
211
+ }
212
+ //# sourceMappingURL=SdTsCompiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SdTsCompiler.js","sourceRoot":"","sources":["../../src/build-tools/SdTsCompiler.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EA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IAAI,EAAE;YAC/C,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;SACrD;QACD,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;CACF"}
@@ -6,11 +6,13 @@ export declare class SdCliClientBuilder extends EventEmitter {
6
6
  private readonly _pkgPath;
7
7
  private readonly _logger;
8
8
  private readonly _pkgConf;
9
+ private _builders?;
10
+ private _checker?;
9
11
  constructor(_projConf: ISdCliConfig, _pkgPath: string);
10
12
  on(event: "change", listener: () => void): this;
11
13
  on(event: "complete", listener: (result: ISdCliBuilderResult) => void): this;
12
- watchAsync(): Promise<void>;
13
14
  buildAsync(): Promise<ISdCliBuilderResult>;
14
- private _getEsBuildOptionsAsync;
15
+ watchAsync(): Promise<void>;
16
+ private _runAsync;
15
17
  private _debug;
16
18
  }
@@ -1,17 +1,9 @@
1
1
  import { EventEmitter } from "events";
2
2
  import { FsUtil, Logger, PathUtil, SdFsWatcher } from "@simplysm/sd-core-node";
3
- import { FunctionQueue, NotImplementError } from "@simplysm/sd-core-common";
3
+ import { FunctionQueue, Wait } from "@simplysm/sd-core-common";
4
4
  import path from "path";
5
- import esbuild from "esbuild";
6
- import { createVirtualModulePlugin } from "@angular-devkit/build-angular/src/tools/esbuild/virtual-module-plugin";
7
- import { createSourcemapIgnorelistPlugin } from "@angular-devkit/build-angular/src/tools/esbuild/sourcemap-ignorelist-plugin";
8
- import { createCompilerPlugin, SourceFileCache } from "@angular-devkit/build-angular/src/tools/esbuild/angular/compiler-plugin";
9
- import { createCompilerPluginOptions } from "@angular-devkit/build-angular/src/tools/esbuild/compiler-plugin-options";
10
- import { CrossOrigin } from "@angular-devkit/build-angular/src/builders/application/schema";
11
- import nodeStdLibBrowserPlugin from "node-stdlib-browser/helpers/esbuild/plugin";
12
- import nodeStdLibBrowser from "node-stdlib-browser";
13
- import { fileURLToPath } from "url";
14
- import { SdTsIncrementalBuilder } from "../build-tools/SdTsIncrementalBuilder";
5
+ import { SdTsCompiler } from "../build-tools/SdTsCompiler";
6
+ import { SdNgBundler } from "../build-tools/SdNgBundler";
15
7
  import { SdLinter } from "../build-tools/SdLinter";
16
8
  export class SdCliClientBuilder extends EventEmitter {
17
9
  constructor(_projConf, _pkgPath) {
@@ -25,306 +17,77 @@ export class SdCliClientBuilder extends EventEmitter {
25
17
  super.on(event, listener);
26
18
  return this;
27
19
  }
28
- async watchAsync() {
29
- this._debug("빌드 준비...");
30
- const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, () => ({ emitJs: false }));
20
+ async buildAsync() {
31
21
  this._debug("dist 초기화...");
32
22
  await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
23
+ return await this._runAsync({ dev: false, genConf: true });
24
+ }
25
+ async watchAsync() {
33
26
  this.emit("change");
34
- if (this._pkgConf.server !== undefined) {
35
- this._debug("GEN .config...");
36
- const confDistPath = path.resolve(this._pkgPath, "../../packages", this._pkgConf.server, "dist/www", path.basename(this._pkgPath), ".config.json");
37
- await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
38
- }
39
- this._debug("BUILD...");
40
- const builderTypes = Object.keys(this._pkgConf.builder ?? { web: {} });
41
- const cache = new SourceFileCache();
42
- const options = await Promise.all(builderTypes.map((builderType) => this._getEsBuildOptionsAsync({
43
- dev: true,
44
- builderType,
45
- cache
46
- })));
47
- const contexts = await Promise.all(options.map((esbuildOption) => esbuild.context(esbuildOption)));
48
- const results = await Promise.all(contexts.map(async (ctx) => {
49
- try {
50
- return await ctx.rebuild();
51
- }
52
- catch (err) {
53
- if (typeof err === "object" && "errors" in err && "warnings" in err) {
54
- return {
55
- errors: err.errors,
56
- warnings: err.warnings
57
- };
58
- }
59
- throw new err;
60
- }
61
- }));
62
- const buildResults = results.mapMany((esbuildResult) => [
63
- ...esbuildResult.warnings.map((warn) => ({
64
- filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
65
- line: warn.location?.line,
66
- char: warn.location?.column,
67
- code: undefined,
68
- severity: "warning",
69
- message: warn.text,
70
- type: "build"
71
- })),
72
- ...esbuildResult.errors.map((err) => ({
73
- filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
74
- line: err.location?.line,
75
- char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
76
- code: undefined,
77
- severity: "warning",
78
- message: err.text,
79
- type: "build"
80
- }))
81
- ]);
82
- this._debug("CHECK...");
83
- const checkResult = await sdTsProgram.buildAsync();
84
- this._debug("LINT...");
85
- const lintResults = await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram.getProgram());
86
- this._debug(`빌드 완료`);
87
- this.emit("complete", {
88
- affectedFilePaths: checkResult.affectedFilePaths,
89
- buildResults: [...buildResults, ...checkResult.results, ...lintResults]
90
- });
27
+ this._debug("dist 초기화...");
28
+ await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
29
+ const result = await this._runAsync({ dev: true, genConf: true });
30
+ this.emit("complete", result);
91
31
  this._debug("WATCH...");
92
32
  const fnQ = new FunctionQueue();
93
- SdFsWatcher
33
+ const watcher = SdFsWatcher
94
34
  .watch([
95
- ...sdTsProgram.builderProgram.getSourceFiles().map((item) => item.fileName),
96
- path.resolve(this._pkgPath, "src/**/*.{ts,tsx}")
35
+ ...result.watchFilePaths,
36
+ path.resolve(this._pkgPath, "src/**/*.*")
97
37
  ])
98
- .onChange({
99
- delay: 100
100
- }, (changeInfos) => {
101
- for (const changeInfo of changeInfos) {
102
- cache.delete(PathUtil.posix(changeInfo.path));
38
+ .onChange({ delay: 100 }, (changeInfos) => {
39
+ for (const builder of this._builders) {
40
+ builder.removeCache(changeInfos.map((item) => item.path));
103
41
  }
104
42
  fnQ.runLast(async () => {
105
43
  this.emit("change");
106
- this._debug(`BUILD...`);
107
- const watchResults = await Promise.all(contexts.map(async (ctx) => {
108
- try {
109
- return await ctx.rebuild();
110
- }
111
- catch (err) {
112
- if (typeof err === "object" && "errors" in err && "warnings" in err) {
113
- return {
114
- errors: err.errors,
115
- warnings: err.warnings
116
- };
117
- }
118
- throw new err;
119
- }
120
- }));
121
- const watchBuildResults = watchResults.mapMany((esbuildResult) => [
122
- ...esbuildResult.warnings.map((warn) => ({
123
- filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
124
- line: warn.location?.line,
125
- char: warn.location?.column,
126
- code: undefined,
127
- severity: "warning",
128
- message: warn.text,
129
- type: "build"
130
- })),
131
- ...esbuildResult.errors.map((err) => ({
132
- filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
133
- line: err.location?.line,
134
- char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
135
- code: undefined,
136
- severity: "warning",
137
- message: err.text,
138
- type: "build"
139
- }))
140
- ]);
141
- this._debug("CHECK...");
142
- const watchCheckResult = await sdTsProgram.buildAsync();
143
- this._debug(`LINT...`);
144
- const watchLintResults = await SdLinter.lintAsync(watchCheckResult.affectedFilePaths, sdTsProgram.builderProgram.getProgram());
145
- this._debug(`빌드 완료`);
146
- this.emit("complete", {
147
- affectedFilePaths: watchCheckResult.affectedFilePaths,
148
- buildResults: [...watchBuildResults, ...watchCheckResult.results, ...watchLintResults]
149
- });
44
+ const watchResult = await this._runAsync({ dev: true, genConf: false });
45
+ this.emit("complete", watchResult);
46
+ watcher.add(watchResult.watchFilePaths);
150
47
  });
151
48
  });
152
49
  }
153
- // eslint-disable-next-line @typescript-eslint/require-await
154
- async buildAsync() {
155
- throw new NotImplementError();
156
- }
157
- async _getEsBuildOptionsAsync(opt) {
158
- // const projPath = path.resolve(this._pkgPath, "../../");
159
- const tsconfigFilePath = path.resolve(this._pkgPath, "tsconfig.json");
160
- const mainFilePath = path.resolve(this._pkgPath, "src/main.ts");
161
- const indexHtmlFilePath = path.resolve(this._pkgPath, "src/index.html");
162
- const cacheBasePath = path.resolve(this._pkgPath, ".cache");
163
- const distBasePath = path.resolve(this._pkgPath, "dist");
164
- const { pluginOptions, styleOptions } = createCompilerPluginOptions({
165
- advancedOptimizations: true,
166
- allowedCommonJsDependencies: [],
167
- baseHref: undefined,
168
- cacheOptions: {
169
- enabled: true,
170
- basePath: cacheBasePath,
171
- path: path.resolve(cacheBasePath, opt.builderType)
172
- },
173
- crossOrigin: CrossOrigin.None,
174
- deleteOutputPath: true,
175
- externalDependencies: [],
176
- extractLicenses: false,
177
- inlineStyleLanguage: 'scss',
178
- jit: false,
179
- stats: false,
180
- polyfills: ["./src/polyfills.ts"],
181
- poll: undefined,
182
- progress: true,
183
- externalPackages: true,
184
- preserveSymlinks: true,
185
- stylePreprocessorOptions: { includePaths: [] },
186
- subresourceIntegrity: false,
187
- serverEntryPoint: undefined,
188
- prerenderOptions: undefined,
189
- appShellOptions: undefined,
190
- ssrOptions: undefined,
191
- verbose: false,
192
- watch: true,
193
- workspaceRoot: this._pkgPath,
194
- entryPoints: { main: mainFilePath },
195
- optimizationOptions: {
196
- scripts: false,
197
- styles: { minify: false, inlineCritical: false },
198
- fonts: { inline: false }
199
- },
200
- outputPath: distBasePath,
201
- outExtension: undefined,
202
- sourcemapOptions: { vendor: false, hidden: false, scripts: true, styles: true },
203
- tsconfig: tsconfigFilePath,
204
- projectRoot: this._pkgPath,
205
- assets: [
206
- { glob: 'favicon.ico', input: 'src', output: '' },
207
- { glob: '**/*', input: 'src\\assets', output: 'assets' }
208
- ],
209
- outputNames: { bundles: '[name]', media: 'media/[name]' },
210
- fileReplacements: undefined,
211
- globalStyles: [{ name: 'styles', files: ["src/styles.scss"], initial: true }],
212
- globalScripts: [],
213
- serviceWorker: undefined,
214
- indexHtmlOptions: {
215
- input: indexHtmlFilePath,
216
- output: 'index.html',
217
- insertionOrder: [
218
- ['runtime', true],
219
- ['polyfills', true],
220
- ['styles', false],
221
- ['vendor', true],
222
- ['main', true]
223
- ]
224
- },
225
- tailwindConfiguration: undefined
226
- }, [
227
- 'chrome117.0', 'chrome116.0',
228
- 'edge117.0', 'edge116.0',
229
- 'firefox118.0', 'firefox115.0',
230
- 'ios17.0', 'ios16.6',
231
- 'ios16.5', 'ios16.4',
232
- 'ios16.3', 'ios16.2',
233
- 'ios16.1', 'ios16.0',
234
- 'safari17.0', 'safari16.6',
235
- 'safari16.5', 'safari16.4',
236
- 'safari16.3', 'safari16.2',
237
- 'safari16.1', 'safari16.0'
238
- ], opt.cache);
50
+ async _runAsync(opt) {
51
+ this._debug(`BUILD 준비...`);
52
+ const builderTypes = Object.keys(this._pkgConf.builder ?? { web: {} });
53
+ this._builders = this._builders ?? builderTypes.map((builderType) => new SdNgBundler({
54
+ dev: opt.dev,
55
+ builderType: builderType,
56
+ pkgPath: this._pkgPath
57
+ }));
58
+ this._checker = this._checker ?? new SdTsCompiler({
59
+ pkgPath: this._pkgPath,
60
+ emit: false,
61
+ emitDts: false,
62
+ globalStyle: false
63
+ });
64
+ this._debug(`BUILD...`);
65
+ const buildResults = await Promise.all(this._builders.map((builder) => builder.bundleAsync()));
66
+ this._debug("CHECK...");
67
+ const checkResult = await this._checker.buildAsync();
68
+ this._debug(`LINT...`);
69
+ const lintResults = await SdLinter.lintAsync(checkResult.affectedFilePaths, this._checker.program);
70
+ if (opt.genConf) {
71
+ this._debug("GEN .config...");
72
+ if (opt.dev && this._pkgConf.server !== undefined) {
73
+ const serverDistPath = path.resolve(this._pkgPath, "../", this._pkgConf.server, "dist");
74
+ await Wait.until(() => FsUtil.exists(serverDistPath));
75
+ await FsUtil.writeJsonAsync(path.resolve(serverDistPath, "www", path.basename(this._pkgPath), ".config.json"), this._pkgConf.configs ?? {}, { space: 2 });
76
+ }
77
+ else {
78
+ await FsUtil.writeJsonAsync(path.resolve(this._pkgPath, "dist/.config.json"), this._pkgConf.configs ?? {}, { space: 2 });
79
+ }
80
+ }
81
+ const localUpdatePaths = Object.keys(this._projConf.localUpdates ?? {})
82
+ .mapMany((key) => FsUtil.glob(path.resolve(this._pkgPath, "../../node_modules", key)));
83
+ const watchFilePaths = buildResults.mapMany((item) => item.filePaths)
84
+ .filter((item) => PathUtil.isChildPath(item, path.resolve(this._pkgPath, "../")) ||
85
+ localUpdatePaths.some((lu) => PathUtil.isChildPath(item, lu)));
86
+ this._debug(`빌드 완료`);
239
87
  return {
240
- absWorkingDir: this._pkgPath,
241
- bundle: true,
242
- format: 'esm',
243
- assetNames: 'media/[name]',
244
- conditions: ['es2020', 'es2015', 'module'],
245
- resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
246
- metafile: true,
247
- legalComments: 'eof',
248
- logLevel: 'silent',
249
- minifyIdentifiers: false,
250
- minifySyntax: false,
251
- minifyWhitespace: false,
252
- pure: ['forwardRef'],
253
- outdir: distBasePath,
254
- outExtension: undefined,
255
- sourcemap: true,
256
- splitting: true,
257
- chunkNames: 'chunk-[hash]',
258
- tsconfig: tsconfigFilePath,
259
- external: [],
260
- write: true,
261
- preserveSymlinks: true,
262
- define: {
263
- ngJitMode: 'false',
264
- global: 'global',
265
- process: 'process',
266
- Buffer: 'Buffer'
267
- },
268
- platform: 'browser',
269
- mainFields: ['es2020', 'es2015', 'browser', 'module', 'main'],
270
- entryNames: '[name]',
271
- entryPoints: {
272
- main: mainFilePath,
273
- polyfills: 'angular:polyfills'
274
- },
275
- target: [
276
- 'chrome117.0', 'chrome116.0',
277
- 'edge117.0', 'edge116.0',
278
- 'firefox118.0', 'firefox115.0',
279
- 'ios17.0', 'ios16.6',
280
- 'ios16.5', 'ios16.4',
281
- 'ios16.3', 'ios16.2',
282
- 'ios16.1', 'ios16.0',
283
- 'safari17.0', 'safari16.6',
284
- 'safari16.5', 'safari16.4',
285
- 'safari16.3', 'safari16.2',
286
- 'safari16.1', 'safari16.0'
287
- ],
288
- supported: { 'async-await': false, 'object-rest-spread': false },
289
- loader: {
290
- ".png": "file",
291
- ".jpeg": "file",
292
- ".jpg": "file",
293
- ".jfif": "file",
294
- ".gif": "file",
295
- ".svg": "file",
296
- ".woff": "file",
297
- ".woff2": "file",
298
- ".ttf": "file",
299
- ".eot": "file",
300
- ".ico": "file",
301
- ".otf": "file",
302
- ".csv": "file",
303
- ".xlsx": "file",
304
- ".xls": "file",
305
- ".pptx": "file",
306
- ".ppt": "file",
307
- ".docx": "file",
308
- ".doc": "file",
309
- ".zip": "file",
310
- ".pfx": "file",
311
- ".pkl": "file"
312
- },
313
- inject: [PathUtil.posix(fileURLToPath(await import.meta.resolve("node-stdlib-browser/helpers/esbuild/shim")))],
314
- plugins: [
315
- createVirtualModulePlugin({
316
- namespace: "angular:polyfills",
317
- loadContent: () => ({
318
- contents: `import "./src/polyfills.ts";`,
319
- loader: 'js',
320
- resolveDir: this._pkgPath
321
- })
322
- }),
323
- createSourcemapIgnorelistPlugin(),
324
- createCompilerPlugin(pluginOptions, styleOptions),
325
- // createExternalPackagesPlugin() as esbuild.Plugin,
326
- nodeStdLibBrowserPlugin(nodeStdLibBrowser)
327
- ]
88
+ watchFilePaths: watchFilePaths,
89
+ affectedFilePaths: checkResult.affectedFilePaths,
90
+ buildResults: [...buildResults.mapMany((item) => item.results), ...checkResult.results, ...lintResults]
328
91
  };
329
92
  }
330
93
  _debug(msg) {