@simplysm/sd-cli 12.9.16 → 12.9.18

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 (105) hide show
  1. package/dist/entry/sd-cli-cordova.d.ts +1 -1
  2. package/dist/entry/sd-cli-cordova.js +3 -3
  3. package/dist/entry/sd-cli-cordova.js.map +1 -1
  4. package/dist/entry/sd-cli-electron.d.ts +2 -2
  5. package/dist/entry/sd-cli-local-update.d.ts +2 -2
  6. package/dist/entry/sd-cli-local-update.js.map +1 -1
  7. package/dist/entry/sd-cli-project.d.ts +3 -3
  8. package/dist/entry/sd-cli-project.js +4 -4
  9. package/dist/entry/sd-cli-project.js.map +1 -1
  10. package/dist/entry/utils/loadProjConfAsync.d.ts +1 -1
  11. package/dist/entry/utils/loadProjConfAsync.js +1 -1
  12. package/dist/entry/utils/loadProjConfAsync.js.map +1 -1
  13. package/dist/fix/convert-private-underscore.d.ts +1 -0
  14. package/dist/fix/convert-private-underscore.js +49 -0
  15. package/dist/fix/convert-private-underscore.js.map +1 -0
  16. package/dist/fix/convert-private.d.ts +1 -0
  17. package/dist/fix/convert-private.js +60 -0
  18. package/dist/fix/convert-private.js.map +1 -0
  19. package/dist/pkg-builders/client/sd-cli-ng-routes.file-generator.d.ts +1 -1
  20. package/dist/pkg-builders/client/sd-cli-ng-routes.file-generator.js +3 -3
  21. package/dist/pkg-builders/client/sd-cli-ng-routes.file-generator.js.map +1 -1
  22. package/dist/pkg-builders/client/sd-client.build-runner.d.ts +5 -18
  23. package/dist/pkg-builders/client/sd-client.build-runner.js +32 -90
  24. package/dist/pkg-builders/client/sd-client.build-runner.js.map +1 -1
  25. package/dist/pkg-builders/client/sd-ng.bundler.d.ts +2 -1
  26. package/dist/pkg-builders/client/sd-ng.bundler.js +2 -2
  27. package/dist/pkg-builders/client/sd-ng.bundler.js.map +1 -1
  28. package/dist/pkg-builders/client/sd-ng.plugin-creator.d.ts +2 -1
  29. package/dist/pkg-builders/client/sd-ng.plugin-creator.js +1 -1
  30. package/dist/pkg-builders/client/sd-ng.plugin-creator.js.map +1 -1
  31. package/dist/pkg-builders/commons/build-runner.base.d.ts +27 -0
  32. package/dist/pkg-builders/commons/build-runner.base.js +93 -0
  33. package/dist/pkg-builders/commons/build-runner.base.js.map +1 -0
  34. package/dist/pkg-builders/commons/scope-path.d.ts +7 -0
  35. package/dist/pkg-builders/commons/scope-path.js +13 -0
  36. package/dist/pkg-builders/commons/scope-path.js.map +1 -0
  37. package/dist/pkg-builders/lib/sd-cli-index.file-generator.d.ts +1 -1
  38. package/dist/pkg-builders/lib/sd-cli-index.file-generator.js +2 -2
  39. package/dist/pkg-builders/lib/sd-cli-index.file-generator.js.map +1 -1
  40. package/dist/pkg-builders/lib/sd-js-lib.build-runner.d.ts +7 -15
  41. package/dist/pkg-builders/lib/sd-js-lib.build-runner.js +15 -54
  42. package/dist/pkg-builders/lib/sd-js-lib.build-runner.js.map +1 -1
  43. package/dist/pkg-builders/lib/sd-ts-lib.build-runner.d.ts +5 -16
  44. package/dist/pkg-builders/lib/sd-ts-lib.build-runner.js +31 -85
  45. package/dist/pkg-builders/lib/sd-ts-lib.build-runner.js.map +1 -1
  46. package/dist/pkg-builders/lib/sd-ts-lib.builder.d.ts +2 -1
  47. package/dist/pkg-builders/lib/sd-ts-lib.builder.js +2 -2
  48. package/dist/pkg-builders/lib/sd-ts-lib.builder.js.map +1 -1
  49. package/dist/pkg-builders/sd-multi.build-runner.d.ts +2 -1
  50. package/dist/pkg-builders/sd-multi.build-runner.js +4 -4
  51. package/dist/pkg-builders/sd-multi.build-runner.js.map +1 -1
  52. package/dist/pkg-builders/server/sd-server.build-runner.d.ts +6 -17
  53. package/dist/pkg-builders/server/sd-server.build-runner.js +87 -137
  54. package/dist/pkg-builders/server/sd-server.build-runner.js.map +1 -1
  55. package/dist/pkg-builders/server/sd-server.bundler.d.ts +2 -1
  56. package/dist/pkg-builders/server/sd-server.bundler.js +2 -2
  57. package/dist/pkg-builders/server/sd-server.bundler.js.map +1 -1
  58. package/dist/pkg-builders/server/sd-server.plugin-creator.d.ts +2 -1
  59. package/dist/pkg-builders/server/sd-server.plugin-creator.js +3 -2
  60. package/dist/pkg-builders/server/sd-server.plugin-creator.js.map +1 -1
  61. package/dist/sd-cli-entry.js +69 -61
  62. package/dist/sd-cli-entry.js.map +1 -1
  63. package/dist/sd-cli.js +33 -28
  64. package/dist/sd-cli.js.map +1 -1
  65. package/dist/ts-compiler/sd-dependency-analyzer.d.ts +3 -3
  66. package/dist/ts-compiler/sd-dependency-analyzer.js +9 -16
  67. package/dist/ts-compiler/sd-dependency-analyzer.js.map +1 -1
  68. package/dist/ts-compiler/sd-ts-compiler.d.ts +1 -2
  69. package/dist/ts-compiler/sd-ts-compiler.js +70 -19
  70. package/dist/ts-compiler/sd-ts-compiler.js.map +1 -1
  71. package/dist/types/config.types.d.ts +3 -2
  72. package/dist/types/ts-compiler.types.d.ts +2 -1
  73. package/package.json +8 -7
  74. package/src/entry/sd-cli-cordova.ts +4 -4
  75. package/src/entry/sd-cli-electron.ts +2 -2
  76. package/src/entry/sd-cli-local-update.ts +2 -2
  77. package/src/entry/sd-cli-project.ts +6 -6
  78. package/src/entry/utils/loadProjConfAsync.ts +2 -2
  79. package/src/fix/convert-private-underscore.ts +69 -0
  80. package/src/fix/convert-private.ts +74 -0
  81. package/src/pkg-builders/client/sd-cli-ng-routes.file-generator.ts +3 -3
  82. package/src/pkg-builders/client/sd-client.build-runner.ts +39 -126
  83. package/src/pkg-builders/client/sd-ng.bundler.ts +4 -3
  84. package/src/pkg-builders/client/sd-ng.plugin-creator.ts +3 -2
  85. package/src/pkg-builders/commons/build-runner.base.ts +149 -0
  86. package/src/pkg-builders/commons/scope-path.ts +17 -0
  87. package/src/pkg-builders/lib/sd-cli-index.file-generator.ts +2 -2
  88. package/src/pkg-builders/lib/sd-js-lib.build-runner.ts +29 -74
  89. package/src/pkg-builders/lib/sd-ts-lib.build-runner.ts +35 -130
  90. package/src/pkg-builders/lib/sd-ts-lib.builder.ts +3 -2
  91. package/src/pkg-builders/sd-multi.build-runner.ts +4 -4
  92. package/src/pkg-builders/server/sd-server.build-runner.ts +99 -187
  93. package/src/pkg-builders/server/sd-server.bundler.ts +4 -3
  94. package/src/pkg-builders/server/sd-server.plugin-creator.ts +13 -8
  95. package/src/sd-cli-entry.ts +115 -81
  96. package/src/sd-cli.ts +14 -11
  97. package/src/ts-compiler/sd-dependency-analyzer.ts +10 -17
  98. package/src/ts-compiler/sd-ts-compiler.ts +79 -30
  99. package/src/types/config.types.ts +9 -2
  100. package/src/types/ts-compiler.types.ts +2 -1
  101. package/tests/deps/sd-dependency-analyzer.spec.ts +1 -1
  102. package/dist/workers/style-bundler.worker.d.ts +0 -1
  103. package/dist/workers/style-bundler.worker.js +0 -56
  104. package/dist/workers/style-bundler.worker.js.map +0 -1
  105. package/src/workers/style-bundler.worker.ts +0 -70
@@ -1,145 +1,54 @@
1
- import { FsUtils, PathUtils, SdFsWatcher, SdLogger, TNormPath } from "@simplysm/sd-core-node";
2
- import path from "path";
3
- import { EventEmitter } from "events";
4
- import { SdCliIndexFileGenerator } from "./sd-cli-index.file-generator";
1
+ import { PathUtils, SdLogger, TNormPath } from "@simplysm/sd-core-node";
5
2
  import { SdTsLibBuilder } from "./sd-ts-lib.builder";
6
- import { ISdLibPackageConfig, ISdProjectConfig } from "../../types/config.types";
7
- import { ISdBuildMessage, ISdBuildRunnerResult } from "../../types/build.types";
3
+ import { BuildRunnerBase, IBuildRunnerRunResult } from "../commons/build-runner.base";
4
+ import { SdCliIndexFileGenerator } from "./sd-cli-index.file-generator";
8
5
  import { SdCliDbContextFileGenerator } from "./sd-cli-db-context.file-generator";
9
6
 
10
- export class SdTsLibBuildRunner extends EventEmitter {
11
- private _logger = SdLogger.get(["simplysm", "sd-cli", "SdCliTsLibBuilder"]);
12
-
13
- private _projConf: ISdProjectConfig;
14
- private _pkgPath: string;
15
- private _pkgConf: ISdLibPackageConfig;
16
- private _watchScopePathSet: Set<TNormPath>;
7
+ export class SdTsLibBuildRunner extends BuildRunnerBase<"library"> {
8
+ protected override _logger = SdLogger.get(["simplysm", "sd-cli", "SdCliTsLibBuilder"]);
17
9
 
18
10
  private _builder?: SdTsLibBuilder;
19
11
 
20
- constructor(projConf: ISdProjectConfig, pkgPath: string) {
21
- super();
22
- this._projConf = projConf;
23
- this._pkgPath = pkgPath;
24
-
25
- this._pkgConf = projConf.packages[path.basename(pkgPath)] as ISdLibPackageConfig;
26
-
27
- const localUpdatePaths = Object.keys(this._projConf.localUpdates ?? {}).mapMany((key) =>
28
- FsUtils.glob(path.resolve(this._pkgPath, "../../node_modules", key)),
29
- );
30
- this._watchScopePathSet = new Set(
31
- [path.resolve(this._pkgPath, "../"), ...localUpdatePaths].map((item) => PathUtils.norm(item)),
32
- );
33
- }
34
-
35
- override on(event: "change", listener: () => void): this;
36
- override on(event: "complete", listener: (result: ISdBuildRunnerResult) => void): this;
37
- override on(event: string | symbol, listener: (...args: any[]) => void): this {
38
- super.on(event, listener);
39
- return this;
40
- }
41
-
42
- async buildAsync(): Promise<ISdBuildRunnerResult> {
43
- this._debug("dist 초기화...");
44
- FsUtils.remove(path.resolve(this._pkgPath, "dist"));
45
-
46
- if (!this._pkgConf.noGenIndex) {
47
- this._debug("GEN index.ts...");
48
- SdCliIndexFileGenerator.run(this._pkgPath, this._pkgConf.polyfills);
49
- }
50
-
51
- if (this._pkgConf.dbContext != null) {
52
- this._debug("WATCH GEN index.ts...");
53
- SdCliDbContextFileGenerator.run(this._pkgPath, this._pkgConf.dbContext);
54
- }
55
-
56
- const result = await this._runAsync(false, new Set<TNormPath>());
57
- return {
58
- affectedFilePathSet: result.affectedFileSet,
59
- buildMessages: result.buildMessages,
60
- emitFileSet: result.emitFileSet,
61
- };
62
- }
63
-
64
- async watchAsync(): Promise<void> {
65
- this.emit("change");
66
-
67
- this._debug("dist 초기화...");
68
- FsUtils.remove(path.resolve(this._pkgPath, "dist"));
69
-
70
- if (!this._pkgConf.noGenIndex) {
71
- this._debug("WATCH GEN index.ts...");
72
- SdCliIndexFileGenerator.watch(this._pkgPath, this._pkgConf.polyfills);
73
- }
74
-
75
- if (this._pkgConf.dbContext != null) {
76
- this._debug("WATCH GEN index.ts...");
77
- SdCliDbContextFileGenerator.watch(this._pkgPath, this._pkgConf.dbContext);
78
- }
79
-
80
- const result = await this._runAsync(true, new Set<TNormPath>());
81
- const res: ISdBuildRunnerResult = {
82
- affectedFilePathSet: result.affectedFileSet,
83
- buildMessages: result.buildMessages,
84
- emitFileSet: result.emitFileSet,
85
- };
86
- this.emit("complete", res);
87
-
88
- this._debug("WATCH...");
89
- let lastWatchFileSet = result.watchFileSet;
90
- SdFsWatcher.watch(Array.from(this._watchScopePathSet))
91
- .onChange({ delay: 100 }, async (changeInfos) => {
92
- const currentChangeInfos = changeInfos.filter((item) => lastWatchFileSet.has(item.path));
93
- if (currentChangeInfos.length < 1) return;
94
-
95
- this.emit("change");
96
-
97
- const changeFileSet = new Set(currentChangeInfos.map((item) => PathUtils.norm(item.path)));
98
-
99
- const watchResult = await this._runAsync(true, changeFileSet);
100
- const watchRes: ISdBuildRunnerResult = {
101
- affectedFilePathSet: watchResult.affectedFileSet,
102
- buildMessages: watchResult.buildMessages,
103
- emitFileSet: watchResult.emitFileSet,
104
- };
105
-
106
- this.emit("complete", watchRes);
107
-
108
- lastWatchFileSet = watchResult.watchFileSet;
109
- });
110
- }
111
-
112
- private async _runAsync(
12
+ protected override async _runAsync(
113
13
  dev: boolean,
114
- modifiedFileSet: Set<TNormPath>,
115
- ): Promise<{
116
- watchFileSet: Set<TNormPath>;
117
- affectedFileSet: Set<TNormPath>;
118
- buildMessages: ISdBuildMessage[];
119
- emitFileSet: Set<TNormPath>;
120
- }> {
121
- const localUpdatePaths = Object.keys(this._projConf.localUpdates ?? {})
122
- .mapMany((key) => FsUtils.glob(path.resolve(this._pkgPath, "../../node_modules", key)))
123
- .map((item) => PathUtils.norm(item));
14
+ modifiedFileSet?: Set<TNormPath>,
15
+ ): Promise<IBuildRunnerRunResult> {
16
+ if (!modifiedFileSet) {
17
+ if (!dev) {
18
+ if (!this._pkgConf.noGenIndex) {
19
+ this._debug("GEN index.ts...");
20
+ SdCliIndexFileGenerator.run(this._pkgPath, this._pkgConf.polyfills);
21
+ }
22
+
23
+ if (this._pkgConf.dbContext != null) {
24
+ this._debug(`GEN ${this._pkgConf.dbContext}.ts...`);
25
+ SdCliDbContextFileGenerator.run(this._pkgPath, this._pkgConf.dbContext);
26
+ }
27
+ }
28
+ else {
29
+ if (!this._pkgConf.noGenIndex) {
30
+ this._debug("Watch for GEN index.ts...");
31
+ SdCliIndexFileGenerator.watch(this._pkgPath, this._pkgConf.polyfills);
32
+ }
33
+
34
+ if (this._pkgConf.dbContext != null) {
35
+ this._debug(`Watch for GEN ${this._pkgConf.dbContext}.ts...`);
36
+ SdCliDbContextFileGenerator.watch(this._pkgPath, this._pkgConf.dbContext);
37
+ }
38
+ }
39
+ }
124
40
 
125
41
  this._debug(`BUILD...`);
126
42
  this._builder ??= new SdTsLibBuilder(
127
43
  PathUtils.norm(this._pkgPath),
128
44
  dev,
129
- [
130
- PathUtils.norm(this._pkgPath, "../"),
131
- ...localUpdatePaths,
132
- ].map((item) => PathUtils.norm(item)),
45
+ this._watchScopePathSet,
133
46
  );
134
- const buildResult = await this._builder.buildAsync(modifiedFileSet);
47
+ const buildResult = await this._builder.buildAsync(modifiedFileSet ?? new Set());
135
48
 
136
49
  this._debug(`빌드 완료`);
137
50
  const watchFileSet = new Set(
138
- Array.from(buildResult.watchFileSet).filter(
139
- (item) =>
140
- PathUtils.isChildPath(item, path.resolve(this._pkgPath, "../")) ||
141
- localUpdatePaths.some((lu) => PathUtils.isChildPath(item, lu)),
142
- ),
51
+ Array.from(buildResult.watchFileSet).filter((item) => this._watchScopePathSet.inScope(item)),
143
52
  );
144
53
 
145
54
  return {
@@ -149,8 +58,4 @@ export class SdTsLibBuildRunner extends EventEmitter {
149
58
  emitFileSet: buildResult.emitFileSet,
150
59
  };
151
60
  }
152
-
153
- protected _debug(msg: string): void {
154
- this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
155
- }
156
61
  }
@@ -3,6 +3,7 @@ import { SdCliConvertMessageUtils } from "../../utils/sd-cli-convert-message.uti
3
3
  import { FsUtils, PathUtils, TNormPath } from "@simplysm/sd-core-node";
4
4
  import { ISdBuildMessage } from "../../types/build.types";
5
5
  import { SdTsCompiler } from "../../ts-compiler/sd-ts-compiler";
6
+ import { ScopePathSet } from "../commons/scope-path";
6
7
 
7
8
  export class SdTsLibBuilder {
8
9
  private _tsCompiler: SdTsCompiler;
@@ -10,7 +11,7 @@ export class SdTsLibBuilder {
10
11
  constructor(
11
12
  private _pkgPath: TNormPath,
12
13
  dev: boolean,
13
- watchScopePaths: TNormPath[],
14
+ watchScopePathSet: ScopePathSet,
14
15
  ) {
15
16
  this._tsCompiler = new SdTsCompiler({
16
17
  pkgPath: this._pkgPath,
@@ -18,7 +19,7 @@ export class SdTsLibBuilder {
18
19
  isDevMode: dev,
19
20
  globalStyleFilePath: PathUtils.norm(this._pkgPath, "src/styles.scss"),
20
21
  isForBundle: false,
21
- watchScopePaths: watchScopePaths,
22
+ watchScopePathSet,
22
23
  });
23
24
  }
24
25
 
@@ -51,7 +51,7 @@ export class SdMultiBuildRunner extends EventEmitter {
51
51
  }
52
52
  this._busyCount++;
53
53
  })
54
- .on("complete", (result) => this.#onComplete(req, result));
54
+ .on("complete", (result) => this._onComplete(req, result));
55
55
 
56
56
  return await worker.run("run", [req]);
57
57
  /*const pkgConf = req.projConf.packages[path.basename(req.pkgPath)]!;
@@ -78,7 +78,7 @@ export class SdMultiBuildRunner extends EventEmitter {
78
78
  }*/
79
79
  }
80
80
 
81
- #onComplete(req: ISdBuildRunnerWorkerRequest, result: ISdBuildRunnerResult) {
81
+ private _onComplete(req: ISdBuildRunnerWorkerRequest, result: ISdBuildRunnerResult) {
82
82
  this._resultCache.delete(req.pkgPath);
83
83
  for (const affectedFilePath of result.affectedFilePathSet) {
84
84
  if (PathUtils.isChildPath(affectedFilePath, req.pkgPath)) {
@@ -152,7 +152,7 @@ export class SdMultiBuildRunner extends EventEmitter {
152
152
  if (serverInfo.pkgInfo && serverInfo.hasChanges) {
153
153
  this._logger.debug("서버 재시작...");
154
154
  try {
155
- const restartServerResult = await this.#restartServerAsync(
155
+ const restartServerResult = await this._restartServerAsync(
156
156
  serverInfo.pkgInfo,
157
157
  serverInfo.worker,
158
158
  );
@@ -212,7 +212,7 @@ export class SdMultiBuildRunner extends EventEmitter {
212
212
  }, 300);
213
213
  }
214
214
 
215
- async #restartServerAsync(
215
+ private async _restartServerAsync(
216
216
  pkgInfo: { path: string; conf: ISdServerPackageConfig } | { port: number },
217
217
  prevWorker?: SdWorker<TServerWorkerType>,
218
218
  ): Promise<{
@@ -1,121 +1,100 @@
1
- import { EventEmitter } from "events";
2
- import { FsUtils, PathUtils, SdFsWatcher, SdLogger, TNormPath } from "@simplysm/sd-core-node";
1
+ import { FsUtils, SdLogger, TNormPath } from "@simplysm/sd-core-node";
3
2
  import path from "path";
4
3
  import { StringUtils } from "@simplysm/sd-core-common";
5
4
  import { SdServerBundler } from "./sd-server.bundler";
6
- import { ISdProjectConfig, ISdServerPackageConfig } from "../../types/config.types";
7
- import { ISdBuildMessage, ISdBuildRunnerResult } from "../../types/build.types";
8
5
  import { INpmConfig, ITsConfig } from "../../types/common-configs.types";
6
+ import { BuildRunnerBase, IBuildRunnerRunResult } from "../commons/build-runner.base";
7
+
8
+ export class SdServerBuildRunner extends BuildRunnerBase<"server"> {
9
+ protected override _logger = SdLogger.get(["simplysm", "sd-cli", "SdCliServerBuildRunner"]);
9
10
 
10
- export class SdServerBuildRunner extends EventEmitter {
11
- private _logger = SdLogger.get(["simplysm", "sd-cli", "SdCliServerBuildRunner"]);
12
- private _pkgConf: ISdServerPackageConfig;
13
11
  private _serverBundler?: SdServerBundler;
14
12
  private _extModules?: { name: string; exists: boolean }[];
15
- private _watchScopePathSet: Set<TNormPath>;
16
13
 
17
- constructor(
18
- private readonly _projConf: ISdProjectConfig,
19
- private readonly _pkgPath: TNormPath,
20
- ) {
21
- super();
22
- this._pkgConf = this._projConf.packages[path.basename(_pkgPath)] as ISdServerPackageConfig;
14
+ protected override async _runAsync(
15
+ dev: boolean,
16
+ modifiedFileSet?: Set<TNormPath>,
17
+ ): Promise<IBuildRunnerRunResult> {
18
+ if (!dev) {
19
+ await this._generateProductionFilesAsync();
20
+ }
23
21
 
24
- const localUpdatePaths = Object.keys(this._projConf.localUpdates ?? {}).mapMany((key) =>
25
- FsUtils.glob(path.resolve(this._pkgPath, "../../node_modules", key)),
26
- );
27
- this._watchScopePathSet = new Set(
28
- [path.resolve(this._pkgPath, "../"), ...localUpdatePaths].map((item) => PathUtils.norm(item)),
29
- );
30
- }
22
+ if (!modifiedFileSet) {
23
+ this._debug("GEN .config...");
24
+ const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
25
+ FsUtils.writeFile(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
26
+ }
31
27
 
32
- override on(event: "change", listener: () => void): this;
33
- override on(event: "complete", listener: (result: ISdBuildRunnerResult) => void): this;
34
- override on(event: string | symbol, listener: (...args: any[]) => void): this {
35
- super.on(event, listener);
36
- return this;
37
- }
28
+ /*const localUpdatePaths = Object.keys(this._projConf.localUpdates ?? {}).mapMany((key) =>
29
+ FsUtils.glob(path.resolve(this._pkgPath, "../../node_modules", key)),
30
+ );*/
38
31
 
39
- async watchAsync(): Promise<void> {
40
- this.emit("change");
32
+ this._debug(`BUILD 준비...`);
33
+ const tsConfig = FsUtils.readJson(path.resolve(this._pkgPath, "tsconfig.json")) as ITsConfig;
34
+ this._extModules = this._extModules ?? (await this._getExternalModulesAsync());
35
+ this._serverBundler =
36
+ this._serverBundler ??
37
+ new SdServerBundler({
38
+ dev,
39
+ pkgPath: this._pkgPath,
40
+ entryPoints: tsConfig.files
41
+ ? tsConfig.files.map((item) => path.resolve(this._pkgPath, item))
42
+ : [
43
+ path.resolve(this._pkgPath, "src/main.ts"),
44
+ ...FsUtils.glob(path.resolve(this._pkgPath, "src/workers/*.ts")),
45
+ ],
46
+ external: this._extModules.map((item) => item.name),
47
+ watchScopePathSet: this._watchScopePathSet,
48
+ });
41
49
 
42
- this._debug("dist 초기화...");
43
- FsUtils.remove(path.resolve(this._pkgPath, "dist"));
50
+ this._debug(`BUILD...`);
51
+ const bundleResult = await this._serverBundler.bundleAsync(modifiedFileSet);
44
52
 
45
- this._debug("GEN .config...");
46
- const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
47
- FsUtils.writeFile(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
53
+ //-- filePaths
54
+ const watchFileSet = new Set(
55
+ Array.from(bundleResult.watchFileSet).filter((item) => this._watchScopePathSet.inScope(item)),
56
+ );
48
57
 
49
- const result = await this._runAsync(true);
50
- const res: ISdBuildRunnerResult = {
51
- affectedFilePathSet: result.affectedFileSet,
52
- buildMessages: result.buildMessages,
53
- emitFileSet: result.emitFileSet,
58
+ this._debug(`빌드 완료`);
59
+ return {
60
+ watchFileSet,
61
+ affectedFileSet: bundleResult.affectedFileSet,
62
+ buildMessages: bundleResult.results,
63
+ emitFileSet: bundleResult.emitFileSet,
54
64
  };
55
- this.emit("complete", res);
56
-
57
- this._debug("WATCH...");
58
- let lastWatchFileSet = result.watchFileSet;
59
- SdFsWatcher.watch(Array.from(this._watchScopePathSet))
60
- .onChange({ delay: 100 }, async (changeInfos) => {
61
- const currentChangeInfos = changeInfos.filter((item) => lastWatchFileSet.has(item.path));
62
- if (currentChangeInfos.length < 1) return;
63
-
64
- this.emit("change");
65
-
66
- const watchResult = await this._runAsync(
67
- true,
68
- new Set(currentChangeInfos.map((item) => PathUtils.norm(item.path))),
69
- );
70
- const watchRes: ISdBuildRunnerResult = {
71
- affectedFilePathSet: watchResult.affectedFileSet,
72
- buildMessages: watchResult.buildMessages,
73
- emitFileSet: watchResult.emitFileSet,
74
- };
75
-
76
- this.emit("complete", watchRes);
77
-
78
- lastWatchFileSet = watchResult.watchFileSet;
79
- });
80
65
  }
81
66
 
82
- async buildAsync(): Promise<ISdBuildRunnerResult> {
83
- const projNpmConfig = FsUtils.readJson(path.resolve(
84
- process.cwd(),
85
- "package.json",
86
- )) as INpmConfig;
87
- const npmConfig = FsUtils.readJson(path.resolve(this._pkgPath, "package.json")) as INpmConfig;
88
- const extModules = await this._getExternalModulesAsync();
89
-
90
- this._debug("dist 초기화...");
91
- FsUtils.remove(path.resolve(this._pkgPath, "dist"));
92
-
93
- this._debug("GEN .config.json...");
94
- const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
95
- FsUtils.writeJson(confDistPath, this._pkgConf.configs ?? {}, { space: 2 });
67
+ private async _generateProductionFilesAsync() {
68
+ const npmConf = FsUtils.readJson(path.resolve(this._pkgPath, "package.json")) as INpmConfig;
96
69
 
97
70
  this._debug("GEN package.json...");
98
71
  {
72
+ const projNpmConf = FsUtils.readJson(path.resolve(
73
+ process.cwd(),
74
+ "package.json",
75
+ )) as INpmConfig;
76
+ const extModules = await this._getExternalModulesAsync();
77
+
99
78
  const deps = extModules.filter((item) => item.exists).map((item) => item.name);
100
79
 
101
80
  const distNpmConfig: INpmConfig = {
102
- name: npmConfig.name,
103
- version: npmConfig.version,
104
- type: npmConfig.type,
81
+ name: npmConf.name,
82
+ version: npmConf.version,
83
+ type: npmConf.type,
105
84
  };
106
85
  distNpmConfig.dependencies = {};
107
86
  for (const dep of deps) {
108
87
  distNpmConfig.dependencies[dep] = "*";
109
88
  }
110
89
 
111
- distNpmConfig.scripts = {};
112
- if (this._pkgConf.pm2 && !this._pkgConf.pm2.noStartScript) {
113
- distNpmConfig.scripts["start"] = "pm2 start pm2.config.cjs";
114
- // distNpmConfig.scripts["stop"] = "pm2 stop ssipec-petrochem-server";
115
- // distNpmConfig.scripts["delete"] = "pm2 delete ssipec-petrochem-server";
116
- }
90
+ // distNpmConfig.scripts = {};
91
+ // if (this._pkgConf.pm2 && !this._pkgConf.pm2.noStartScript) {
92
+ // distNpmConfig.scripts["start"] = "pm2 start pm2.config.cjs";
93
+ // distNpmConfig.scripts["stop"] = "pm2 stop pm2.config.cjs";
94
+ // distNpmConfig.scripts["delete"] = "pm2 delete pm2.config.cjs";
95
+ // }
117
96
 
118
- distNpmConfig.volta = projNpmConfig.volta;
97
+ distNpmConfig.volta = projNpmConf.volta;
119
98
 
120
99
  FsUtils.writeJson(
121
100
  path.resolve(this._pkgPath, "dist/package.json"),
@@ -165,36 +144,36 @@ Options = UnsafeLegacyRenegotiation`.trim(),
165
144
  this._debug("GEN pm2.config.cjs...");
166
145
 
167
146
  const str = /* language=cjs */ `
168
- const cp = require("child_process");
169
-
170
- const npmConf = require("./package.json");
171
-
172
- const pm2Conf = ${JSON.stringify(this._pkgConf.pm2)};
173
- const env = ${JSON.stringify(this._pkgConf.env)};
174
-
175
- module.exports = {
176
- name: pm2Conf.name ?? npmConf.name.replace(/@/g, "").replace(/\\//g, "-"),
177
- script: "main.js",
178
- watch: true,
179
- watch_delay: 2000,
180
- ignore_watch: [
181
- "node_modules",
182
- "www",
183
- ...pm2Conf.ignoreWatchPaths ?? []
184
- ],
185
- ...pm2Conf.noInterpreter ? {} : {interpreter: cp.execSync("volta which node").toString().trim()},
186
- interpreter_args: "--openssl-config=openssl.cnf",
187
- env: {
188
- NODE_ENV: "production",
189
- TZ: "Asia/Seoul",
190
- SD_VERSION: npmConf.version,
191
- ...env ?? {}
192
- },
193
- arrayProcess: "concat",
194
- useDelTargetNull: true,
195
- exec_mode: pm2Conf.instances != null ? "cluster" : "fork",
196
- instances: pm2Conf.instances ?? 1
197
- };`
147
+ const cp = require("child_process");
148
+
149
+ const npmConf = require("./package.json");
150
+
151
+ const pm2Conf = ${JSON.stringify(this._pkgConf.pm2)};
152
+ const env = ${JSON.stringify(this._pkgConf.env)};
153
+
154
+ module.exports = {
155
+ name: pm2Conf.name ?? npmConf.name.replace(/@/g, "").replace(/\\//g, "-"),
156
+ script: "main.js",
157
+ watch: true,
158
+ watch_delay: 2000,
159
+ ignore_watch: [
160
+ "node_modules",
161
+ "www",
162
+ ...pm2Conf.ignoreWatchPaths ?? []
163
+ ],
164
+ ...pm2Conf.noInterpreter ? {} : {interpreter: cp.execSync("volta which node").toString().trim()},
165
+ interpreter_args: "--openssl-config=openssl.cnf",
166
+ env: {
167
+ NODE_ENV: "production",
168
+ TZ: "Asia/Seoul",
169
+ SD_VERSION: npmConf.version,
170
+ ...env ?? {}
171
+ },
172
+ arrayProcess: "concat",
173
+ useDelTargetNull: true,
174
+ exec_mode: pm2Conf.instances != null ? "cluster" : "fork",
175
+ instances: pm2Conf.instances ?? 1
176
+ };`
198
177
  .replaceAll("\n ", "\n")
199
178
  .trim();
200
179
 
@@ -214,7 +193,7 @@ Options = UnsafeLegacyRenegotiation`.trim(),
214
193
  <appSettings>
215
194
  <add key="NODE_ENV" value="production" />
216
195
  <add key="TZ" value="Asia/Seoul" />
217
- <add key="SD_VERSION" value="${npmConfig.version}" />
196
+ <add key="SD_VERSION" value="${npmConf.version}" />
218
197
  ${Object.keys(this._pkgConf.env ?? {})
219
198
  .map((key) => `<add key="${key}" value="${this._pkgConf.env![key]}"/>`)
220
199
  .join("\n ")}
@@ -236,71 +215,8 @@ Options = UnsafeLegacyRenegotiation`.trim(),
236
215
  </rewrite>
237
216
  <httpErrors errorMode="Detailed" />
238
217
  </system.webServer>
239
- </configuration>
240
- `.trim());
218
+ </configuration>`.trim());
241
219
  }
242
-
243
- const result = await this._runAsync(false);
244
- return {
245
- affectedFilePathSet: result.affectedFileSet,
246
- buildMessages: result.buildMessages,
247
- emitFileSet: result.emitFileSet,
248
- };
249
- }
250
-
251
- private async _runAsync(
252
- dev: boolean,
253
- modifiedFileSet?: Set<TNormPath>,
254
- ): Promise<{
255
- watchFileSet: Set<TNormPath>;
256
- affectedFileSet: Set<TNormPath>;
257
- buildMessages: ISdBuildMessage[];
258
- emitFileSet: Set<TNormPath>;
259
- }> {
260
- const localUpdatePaths = Object.keys(this._projConf.localUpdates ?? {}).mapMany((key) =>
261
- FsUtils.glob(path.resolve(this._pkgPath, "../../node_modules", key)),
262
- );
263
-
264
- this._debug(`BUILD 준비...`);
265
- const tsConfig = FsUtils.readJson(path.resolve(this._pkgPath, "tsconfig.json")) as ITsConfig;
266
- this._extModules = this._extModules ?? (await this._getExternalModulesAsync());
267
- this._serverBundler =
268
- this._serverBundler ??
269
- new SdServerBundler({
270
- dev,
271
- pkgPath: this._pkgPath,
272
- entryPoints: tsConfig.files
273
- ? tsConfig.files.map((item) => path.resolve(this._pkgPath, item))
274
- : [
275
- path.resolve(this._pkgPath, "src/main.ts"),
276
- ...FsUtils.glob(path.resolve(this._pkgPath, "src/workers/*.ts")),
277
- ],
278
- external: this._extModules.map((item) => item.name),
279
- watchScopePaths: [
280
- path.resolve(this._pkgPath, "../"),
281
- ...localUpdatePaths,
282
- ].map((item) => PathUtils.norm(item)),
283
- });
284
-
285
- this._debug(`BUILD...`);
286
- const bundleResult = await this._serverBundler.bundleAsync(modifiedFileSet);
287
-
288
- //-- filePaths
289
- const watchFileSet = new Set(
290
- Array.from(bundleResult.watchFileSet).filter(
291
- (item) =>
292
- PathUtils.isChildPath(item, path.resolve(this._pkgPath, "../")) ||
293
- localUpdatePaths.some((lu) => PathUtils.isChildPath(item, lu)),
294
- ),
295
- );
296
-
297
- this._debug(`빌드 완료`);
298
- return {
299
- watchFileSet,
300
- affectedFileSet: bundleResult.affectedFileSet,
301
- buildMessages: bundleResult.results,
302
- emitFileSet: bundleResult.emitFileSet,
303
- };
304
220
  }
305
221
 
306
222
  private async _getExternalModulesAsync(): Promise<
@@ -416,8 +332,4 @@ Options = UnsafeLegacyRenegotiation`.trim(),
416
332
 
417
333
  return results;
418
334
  }
419
-
420
- private _debug(msg: string): void {
421
- this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
422
- }
423
335
  }
@@ -11,6 +11,7 @@ import {
11
11
  } from "@angular/build/src/tools/esbuild/bundler-context";
12
12
  import { convertOutputFile } from "@angular/build/src/tools/esbuild/utils";
13
13
  import { resolveAssets } from "@angular/build/src/utils/resolve-assets";
14
+ import { ScopePathSet } from "../commons/scope-path";
14
15
 
15
16
  export class SdServerBundler {
16
17
  private _logger = SdLogger.get(["simplysm", "sd-cli", "SdServerBundler"]);
@@ -27,7 +28,7 @@ export class SdServerBundler {
27
28
  pkgPath: TNormPath;
28
29
  entryPoints: string[];
29
30
  external?: string[];
30
- watchScopePaths: TNormPath[];
31
+ watchScopePathSet: ScopePathSet;
31
32
  }) {
32
33
  }
33
34
 
@@ -108,7 +109,7 @@ const __dirname = __path__.dirname(__filename);`.trim(),
108
109
  dev: this._opt.dev,
109
110
  pkgPath: this._opt.pkgPath,
110
111
  result: this._resultCache,
111
- watchScopePaths: this._opt.watchScopePaths,
112
+ watchScopePathSet: this._opt.watchScopePathSet,
112
113
  }),
113
114
  ],
114
115
  });
@@ -125,7 +126,7 @@ const __dirname = __path__.dirname(__filename);`.trim(),
125
126
  for (const outputFile of outputFiles) {
126
127
  const distFilePath = PathUtils.norm(this._opt.pkgPath, outputFile.path);
127
128
  const prevHash = this._outputHashCache.get(distFilePath);
128
- const currHash = HashUtils.get(outputFile.contents);
129
+ const currHash = HashUtils.get(Buffer.from(outputFile.contents));
129
130
  if (prevHash !== currHash) {
130
131
  FsUtils.writeFile(distFilePath, outputFile.contents);
131
132
  this._outputHashCache.set(distFilePath, currHash);