@simplysm/sd-cli 11.1.14 → 11.1.16

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-tools/SdLinter.d.ts +2 -2
  2. package/dist/build-tools/SdLinter.js +8 -17
  3. package/dist/build-tools/SdLinter.js.map +1 -1
  4. package/dist/build-tools/SdNgBundler.d.ts +2 -2
  5. package/dist/build-tools/SdNgBundler.js +97 -44
  6. package/dist/build-tools/SdNgBundler.js.map +1 -1
  7. package/dist/build-tools/SdTsBundler.js +19 -4
  8. package/dist/build-tools/SdTsBundler.js.map +1 -1
  9. package/dist/builders/SdCliClientBuilder.d.ts +1 -0
  10. package/dist/builders/SdCliClientBuilder.js +18 -21
  11. package/dist/builders/SdCliClientBuilder.js.map +1 -1
  12. package/dist/builders/SdCliJsLibLinter.js +3 -3
  13. package/dist/builders/SdCliJsLibLinter.js.map +1 -1
  14. package/dist/builders/SdCliServerBuilder.d.ts +1 -5
  15. package/dist/builders/SdCliServerBuilder.js +37 -30
  16. package/dist/builders/SdCliServerBuilder.js.map +1 -1
  17. package/dist/builders/SdCliTsLibBuilder.js +1 -2
  18. package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
  19. package/dist/bundle-plugins/sdLoadedFilesPlugin.d.ts +4 -0
  20. package/dist/bundle-plugins/sdLoadedFilesPlugin.js +15 -0
  21. package/dist/bundle-plugins/sdLoadedFilesPlugin.js.map +1 -0
  22. package/dist/bundle-plugins/sdNgPlugin.d.ts +13 -0
  23. package/dist/bundle-plugins/sdNgPlugin.js +267 -0
  24. package/dist/bundle-plugins/sdNgPlugin.js.map +1 -0
  25. package/dist/bundle-plugins/sdTscPlugin.d.ts +5 -0
  26. package/dist/bundle-plugins/sdTscPlugin.js +21 -0
  27. package/dist/bundle-plugins/sdTscPlugin.js.map +1 -0
  28. package/dist/commons.d.ts +1 -1
  29. package/dist/entry/SdCliProject.js +5 -1
  30. package/dist/entry/SdCliProject.js.map +1 -1
  31. package/dist/index.d.ts +3 -0
  32. package/dist/index.js +3 -0
  33. package/dist/index.js.map +1 -1
  34. package/dist/utils/SdCliBuildResultUtil.js +1 -1
  35. package/dist/utils/SdCliBuildResultUtil.js.map +1 -1
  36. package/package.json +16 -16
  37. package/src/build-tools/SdLinter.ts +10 -18
  38. package/src/build-tools/SdNgBundler.ts +103 -52
  39. package/src/build-tools/SdTsBundler.ts +24 -4
  40. package/src/builders/SdCliClientBuilder.ts +27 -26
  41. package/src/builders/SdCliJsLibLinter.ts +3 -3
  42. package/src/builders/SdCliServerBuilder.ts +40 -35
  43. package/src/builders/SdCliTsLibBuilder.ts +1 -3
  44. package/src/bundle-plugins/sdLoadedFilesPlugin.ts +19 -0
  45. package/src/bundle-plugins/sdNgPlugin.ts +408 -0
  46. package/src/bundle-plugins/sdTscPlugin.ts +25 -0
  47. package/src/commons.ts +1 -1
  48. package/src/entry/SdCliProject.ts +5 -2
  49. package/src/index.ts +3 -0
  50. package/src/utils/SdCliBuildResultUtil.ts +1 -1
@@ -1,12 +1,19 @@
1
1
  import {EventEmitter} from "events";
2
2
  import {FsUtil, Logger, PathUtil, SdFsWatcher} from "@simplysm/sd-core-node";
3
- import {ISdCliBuilderResult, ISdCliClientPackageConfig, ISdCliConfig, ISdCliPackageBuildResult} from "../commons";
3
+ import {
4
+ ISdCliBuilderResult,
5
+ ISdCliClientPackageConfig,
6
+ ISdCliConfig,
7
+ ISdCliPackageBuildResult,
8
+ ITsConfig
9
+ } from "../commons";
4
10
  import {FunctionQueue} from "@simplysm/sd-core-common";
5
11
  import path from "path";
6
12
  import {SdNgBundler} from "../build-tools/SdNgBundler";
7
- import {SdLinter} from "../build-tools/SdLinter";
8
13
  import {SdCliCordova} from "../build-tools/SdCliCordova";
9
14
  import {SdCliNgRoutesFileGenerator} from "../build-tools/SdCliNgRoutesFileGenerator";
15
+ import {SdLinter} from "../build-tools/SdLinter";
16
+ import ts from "typescript";
10
17
 
11
18
  export class SdCliClientBuilder extends EventEmitter {
12
19
  private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliClientBuilder"]);
@@ -14,6 +21,8 @@ export class SdCliClientBuilder extends EventEmitter {
14
21
  private _builders?: SdNgBundler[];
15
22
  private _cordova?: SdCliCordova;
16
23
 
24
+ #program?: ts.Program;
25
+
17
26
  public constructor(private readonly _projConf: ISdCliConfig,
18
27
  private readonly _pkgPath: string) {
19
28
  super();
@@ -31,7 +40,7 @@ export class SdCliClientBuilder extends EventEmitter {
31
40
  this._debug("dist 초기화...");
32
41
  await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
33
42
 
34
- this._debug(`GEN index.ts...`);
43
+ this._debug(`GEN routes.ts...`);
35
44
  await SdCliNgRoutesFileGenerator.runAsync(this._pkgPath);
36
45
 
37
46
  this._debug("GEN .config...");
@@ -41,13 +50,13 @@ export class SdCliClientBuilder extends EventEmitter {
41
50
  return await this._runAsync({dev: false});
42
51
  }
43
52
 
44
- public async watchAsync(): Promise<void> {
53
+ public async watchAsync() {
45
54
  this.emit("change");
46
55
 
47
56
  this._debug("dist 초기화...");
48
57
  await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
49
58
 
50
- this._debug(`WATCH GEN index.ts...`);
59
+ this._debug(`WATCH GEN routes.ts...`);
51
60
  await SdCliNgRoutesFileGenerator.watchAsync(this._pkgPath);
52
61
 
53
62
  this._debug("GEN .config...");
@@ -72,7 +81,8 @@ export class SdCliClientBuilder extends EventEmitter {
72
81
  this.emit("change");
73
82
 
74
83
  for (const builder of this._builders!) {
75
- builder.removeCache(currChangeFiles);
84
+ // builder.removeCache(currChangeFiles);
85
+ builder.markForChanges(currChangeFiles);
76
86
  }
77
87
 
78
88
  const watchResult = await this._runAsync({dev: true});
@@ -122,14 +132,19 @@ export class SdCliClientBuilder extends EventEmitter {
122
132
  this._debug(`BUILD & CHECK...`);
123
133
  const buildResults = await Promise.all(this._builders.map((builder) => builder.bundleAsync()));
124
134
  const filePaths = buildResults.mapMany(item => item.filePaths).distinct();
125
- const affectedFilePaths = buildResults.mapMany(item => item.affectedFilePaths).distinct();
135
+ // const affectedFilePaths = buildResults.mapMany(item => item.affectedFilePaths).distinct();
126
136
  const results = buildResults.mapMany((item) => item.results).distinct();
127
137
 
128
138
  this._debug(`LINT...`);
129
- const lintResults = await SdLinter.lintAsync(
130
- affectedFilePaths,
131
- this._pkgPath
132
- );
139
+ const tsConfig = FsUtil.readJson(path.resolve(this._pkgPath, "tsconfig.json")) as ITsConfig;
140
+ const parsedTsConfig = ts.parseJsonConfigFileContent(tsConfig, ts.sys, this._pkgPath);
141
+ this.#program = ts.createProgram({
142
+ rootNames: parsedTsConfig.fileNames,
143
+ options: parsedTsConfig.options,
144
+ oldProgram: this.#program
145
+ });
146
+ const pkgFilePaths = filePaths.filter(item => PathUtil.isChildPath(item, this._pkgPath));
147
+ const lintResults = await SdLinter.lintAsync(pkgFilePaths, this.#program);
133
148
 
134
149
  if (!opt.dev && this._cordova) {
135
150
  this._debug("CORDOVA BUILD...");
@@ -139,27 +154,13 @@ export class SdCliClientBuilder extends EventEmitter {
139
154
  this._debug(`빌드 완료`);
140
155
  const localUpdatePaths = Object.keys(this._projConf.localUpdates ?? {})
141
156
  .mapMany((key) => FsUtil.glob(path.resolve(this._pkgPath, "../../node_modules", key)));
142
- /*const watchFilePaths = filePaths
143
- .map((item) => {
144
- if (PathUtil.isChildPath(item, path.resolve(this._pkgPath, "../"))) {
145
- return path.resolve(this._pkgPath, "..", path.relative(path.resolve(this._pkgPath, "../"), item).split("\\").slice(0, 2).join("/"), "**!/!*.*");
146
- }
147
-
148
- const localUpdatePath = localUpdatePaths.single((lu) => PathUtil.isChildPath(item, lu));
149
- if (localUpdatePath != null) {
150
- return path.resolve(localUpdatePath, path.relative(localUpdatePath, item).split("\\").slice(0, 1).join("/"), "**!/!*.*");
151
- }
152
-
153
- return undefined;
154
- }).filterExists().distinct();
155
- console.log(watchFilePaths);*/
156
157
  const watchFilePaths = filePaths.filter(item =>
157
158
  PathUtil.isChildPath(item, path.resolve(this._pkgPath, "../")) ||
158
159
  localUpdatePaths.some((lu) => PathUtil.isChildPath(item, lu))
159
160
  );
160
161
  return {
161
162
  watchFilePaths: watchFilePaths,
162
- affectedFilePaths: affectedFilePaths,
163
+ affectedFilePaths: pkgFilePaths,
163
164
  buildResults: [...results, ...lintResults]
164
165
  };
165
166
  }
@@ -24,7 +24,7 @@ export class SdCliJsLibLinter extends EventEmitter {
24
24
  this._debug("LINT...");
25
25
  const srcGlobPath = path.resolve(this._pkgPath, "src/**/*.+(js|cjs|mjs)");
26
26
  const srcFilePaths = await FsUtil.globAsync(srcGlobPath);
27
- const lintResults = await SdLinter.lintAsync(srcFilePaths);
27
+ const lintResults = await SdLinter.lintAsync(srcFilePaths, undefined);
28
28
 
29
29
  this._debug(`LINT 완료`);
30
30
  return {
@@ -38,7 +38,7 @@ export class SdCliJsLibLinter extends EventEmitter {
38
38
  this._debug("LINT...");
39
39
  const srcGlobPath = path.resolve(this._pkgPath, "src/**/*.+(js|cjs|mjs)");
40
40
  const srcFilePaths = await FsUtil.globAsync(srcGlobPath);
41
- const lintResults = await SdLinter.lintAsync(srcFilePaths);
41
+ const lintResults = await SdLinter.lintAsync(srcFilePaths, undefined);
42
42
 
43
43
  this._debug(`LINT 완료`);
44
44
  this.emit("complete", {
@@ -56,7 +56,7 @@ export class SdCliJsLibLinter extends EventEmitter {
56
56
 
57
57
  this.emit("change");
58
58
  this._debug("LINT...");
59
- const watchLintResults = await SdLinter.lintAsync(watchFilePaths);
59
+ const watchLintResults = await SdLinter.lintAsync(watchFilePaths, undefined);
60
60
 
61
61
  this._debug(`LINT 완료`);
62
62
  this.emit("complete", {
@@ -15,16 +15,16 @@ import {FunctionQueue, ObjectUtil, StringUtil} from "@simplysm/sd-core-common";
15
15
  import {SdTsBundler} from "../build-tools/SdTsBundler";
16
16
 
17
17
  export class SdCliServerBuilder extends EventEmitter {
18
- private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliServerBuilder"]);
19
- private readonly _pkgConf: ISdCliServerPackageConfig;
20
- private _builder?: SdTsBundler;
21
- private _checker?: SdTsCompiler;
22
- private _extModules?: { name: string; exists: boolean }[];
18
+ #logger = Logger.get(["simplysm", "sd-cli", "SdCliServerBuilder"]);
19
+ #pkgConf: ISdCliServerPackageConfig;
20
+ #builder?: SdTsBundler;
21
+ #checker?: SdTsCompiler;
22
+ #extModules?: { name: string; exists: boolean }[];
23
23
 
24
24
  public constructor(private readonly _projConf: ISdCliConfig,
25
25
  private readonly _pkgPath: string) {
26
26
  super();
27
- this._pkgConf = this._projConf.packages[path.basename(_pkgPath)] as ISdCliServerPackageConfig;
27
+ this.#pkgConf = this._projConf.packages[path.basename(_pkgPath)] as ISdCliServerPackageConfig;
28
28
  }
29
29
 
30
30
  public override on(event: "change", listener: () => void): this;
@@ -42,7 +42,7 @@ export class SdCliServerBuilder extends EventEmitter {
42
42
 
43
43
  this._debug("GEN .config...");
44
44
  const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
45
- await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
45
+ await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this.#pkgConf.configs ?? {}, undefined, 2));
46
46
 
47
47
  const result = await this._runAsync({dev: true});
48
48
  this.emit("complete", result);
@@ -72,7 +72,7 @@ export class SdCliServerBuilder extends EventEmitter {
72
72
 
73
73
  this._debug("GEN .config.json...");
74
74
  const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
75
- await FsUtil.writeJsonAsync(confDistPath, this._pkgConf.configs ?? {}, {space: 2});
75
+ await FsUtil.writeJsonAsync(confDistPath, this.#pkgConf.configs ?? {}, {space: 2});
76
76
 
77
77
  this._debug("GEN package.json...");
78
78
  {
@@ -87,7 +87,7 @@ export class SdCliServerBuilder extends EventEmitter {
87
87
  delete distNpmConfig.devDependencies;
88
88
  delete distNpmConfig.peerDependencies;
89
89
 
90
- if (this._pkgConf.pm2 && !this._pkgConf.pm2.noStartScript) {
90
+ if (this.#pkgConf.pm2 && !this.#pkgConf.pm2.noStartScript) {
91
91
  distNpmConfig.scripts = {"start": "pm2 start pm2.json"};
92
92
  }
93
93
 
@@ -128,7 +128,7 @@ Options = UnsafeLegacyRenegotiation`.trim()
128
128
  }
129
129
 
130
130
 
131
- if (this._pkgConf.pm2) {
131
+ if (this.#pkgConf.pm2) {
132
132
  this._debug("GEN pm2.json...");
133
133
 
134
134
  await FsUtil.writeJsonAsync(
@@ -141,9 +141,9 @@ Options = UnsafeLegacyRenegotiation`.trim()
141
141
  ignore_watch: [
142
142
  "node_modules",
143
143
  "www",
144
- ...this._pkgConf.pm2.ignoreWatchPaths ?? []
144
+ ...this.#pkgConf.pm2.ignoreWatchPaths ?? []
145
145
  ],
146
- ...this._pkgConf.pm2.noInterpreter ? {} : {
146
+ ...this.#pkgConf.pm2.noInterpreter ? {} : {
147
147
  "interpreter": "node@" + process.versions.node,
148
148
  },
149
149
  interpreter_args: "--openssl-config=openssl.cnf",
@@ -151,7 +151,7 @@ Options = UnsafeLegacyRenegotiation`.trim()
151
151
  NODE_ENV: "production",
152
152
  TZ: "Asia/Seoul",
153
153
  SD_VERSION: npmConfig.version,
154
- ...this._pkgConf.env
154
+ ...this.#pkgConf.env
155
155
  },
156
156
  arrayProcess: "concat",
157
157
  useDelTargetNull: true
@@ -161,11 +161,11 @@ Options = UnsafeLegacyRenegotiation`.trim()
161
161
  );
162
162
  }
163
163
 
164
- if (this._pkgConf.iis) {
164
+ if (this.#pkgConf.iis) {
165
165
  this._debug("GEN web.config...");
166
166
 
167
167
  const iisDistPath = path.resolve(this._pkgPath, "dist/web.config");
168
- const serverExeFilePath = this._pkgConf.iis.nodeExeFilePath ?? "C:\\Program Files\\nodejs\\node.exe";
168
+ const serverExeFilePath = this.#pkgConf.iis.nodeExeFilePath ?? "C:\\Program Files\\nodejs\\node.exe";
169
169
  await FsUtil.writeFileAsync(iisDistPath, `
170
170
  <configuration>
171
171
  <system.webServer>
@@ -200,47 +200,52 @@ Options = UnsafeLegacyRenegotiation`.trim()
200
200
  }> {
201
201
  this._debug(`BUILD 준비...`);
202
202
 
203
- this._extModules = this._extModules ?? await this._getExternalModulesAsync();
203
+ this.#extModules = this.#extModules ?? await this._getExternalModulesAsync();
204
204
 
205
+
206
+ this._debug(`BUILD...`);
205
207
  const tsConfig = FsUtil.readJson(path.resolve(this._pkgPath, "tsconfig.json")) as ITsConfig;
206
- this._builder = this._builder ?? new SdTsBundler({
208
+ this.#builder = this.#builder ?? new SdTsBundler({
207
209
  dev: opt.dev,
208
210
  pkgPath: this._pkgPath,
209
211
  entryPoints: tsConfig.files ? tsConfig.files.map((item) => path.resolve(this._pkgPath, item)) : [
210
212
  path.resolve(this._pkgPath, "src/main.ts")
211
213
  ],
212
- external: this._extModules.map((item) => item.name)
214
+ external: this.#extModules.map((item) => item.name)
213
215
  });
216
+ const buildResult = await this.#builder.bundleAsync();
214
217
 
215
- this._checker = this._checker ?? new SdTsCompiler({
218
+ this._debug("CHECK...");
219
+ this.#checker = this.#checker ?? new SdTsCompiler({
216
220
  pkgPath: this._pkgPath,
217
221
  emit: false,
218
222
  emitDts: false,
219
223
  globalStyle: false
220
224
  });
225
+ const checkResult = await this.#checker.buildAsync();
221
226
 
222
- this._debug(`BUILD...`);
223
- const buildResult = await this._builder.bundleAsync();
227
+ //-- filePaths
224
228
 
225
- this._debug("CHECK...");
226
- const checkResult = await this._checker.buildAsync();
227
-
228
- this._debug(`LINT...`);
229
- const lintResults = await SdLinter.lintAsync(checkResult.affectedFilePaths, this._checker.program);
229
+ const filePaths = [
230
+ ...buildResult.filePaths,
231
+ ...checkResult.filePaths
232
+ ];
233
+ const pkgFilePaths = filePaths.filter(item => PathUtil.isChildPath(item, this._pkgPath));
230
234
 
231
- this._debug(`빌드 완료`);
232
235
  const localUpdatePaths = Object.keys(this._projConf.localUpdates ?? {})
233
236
  .mapMany((key) => FsUtil.glob(path.resolve(this._pkgPath, "../../node_modules", key)));
234
- const watchFilePaths = [
235
- ...buildResult.filePaths,
236
- ...checkResult.filePaths,
237
- ].filter(item =>
237
+ const watchFilePaths = filePaths.filter(item =>
238
238
  PathUtil.isChildPath(item, path.resolve(this._pkgPath, "../")) ||
239
239
  localUpdatePaths.some((lu) => PathUtil.isChildPath(item, lu))
240
240
  );
241
+
242
+ this._debug(`LINT...`);
243
+ const lintResults = await SdLinter.lintAsync(pkgFilePaths, this.#checker!.program);
244
+
245
+ this._debug(`빌드 완료`);
241
246
  return {
242
247
  watchFilePaths,
243
- affectedFilePaths: checkResult.affectedFilePaths,
248
+ affectedFilePaths: pkgFilePaths, //checkResult.affectedFilePaths,
244
249
  buildResults: [...buildResult.results, ...checkResult.results, ...lintResults]
245
250
  };
246
251
  }
@@ -287,7 +292,7 @@ Options = UnsafeLegacyRenegotiation`.trim()
287
292
  });
288
293
  }
289
294
 
290
- if (this._pkgConf.externals?.includes(moduleName)) {
295
+ if (this.#pkgConf.externals?.includes(moduleName)) {
291
296
  results.push({
292
297
  name: moduleName,
293
298
  exists: true
@@ -317,7 +322,7 @@ Options = UnsafeLegacyRenegotiation`.trim()
317
322
  });
318
323
  }
319
324
 
320
- if (this._pkgConf.externals?.includes(optModuleName)) {
325
+ if (this.#pkgConf.externals?.includes(optModuleName)) {
321
326
  results.push({
322
327
  name: optModuleName,
323
328
  exists: true
@@ -334,6 +339,6 @@ Options = UnsafeLegacyRenegotiation`.trim()
334
339
  }
335
340
 
336
341
  private _debug(msg: string): void {
337
- this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
342
+ this.#logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
338
343
  }
339
344
  }
@@ -75,15 +75,13 @@ export class SdCliTsLibBuilder extends EventEmitter {
75
75
  affectedFilePaths: string[];
76
76
  buildResults: ISdCliPackageBuildResult[];
77
77
  }> {
78
- this._debug(`BUILD 준비...`);
78
+ this._debug(`BUILD && CHECK...`);
79
79
  this._builder = this._builder ?? new SdTsCompiler({
80
80
  pkgPath: this._pkgPath,
81
81
  emit: true,
82
82
  emitDts: true,
83
83
  globalStyle: true
84
84
  });
85
-
86
- this._debug(`BUILD && CHECK...`);
87
85
  const buildAndCheckResult = await this._builder.buildAsync();
88
86
 
89
87
  this._debug("LINT...");
@@ -0,0 +1,19 @@
1
+ import esbuild from "esbuild";
2
+
3
+ export function sdLoadedFilesPlugin(conf: {
4
+ loadedFileSet: Set<string>;
5
+ }): esbuild.Plugin {
6
+ return {
7
+ name: "sd-loaded-files",
8
+ setup: (build: esbuild.PluginBuild) => {
9
+ build.onStart(() => {
10
+ conf.loadedFileSet.clear();
11
+ });
12
+
13
+ build.onLoad({filter: /.*/}, (args) => {
14
+ conf.loadedFileSet.add(args.path);
15
+ return null;
16
+ });
17
+ }
18
+ };
19
+ }