@simplysm/sd-cli 12.11.9 → 12.11.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/entry/sd-cli-cordova.js +2 -2
  2. package/dist/entry/sd-cli-cordova.js.map +1 -1
  3. package/dist/entry/sd-cli-electron.js +1 -1
  4. package/dist/entry/sd-cli-electron.js.map +1 -1
  5. package/dist/entry/sd-cli-project.js +12 -0
  6. package/dist/entry/sd-cli-project.js.map +1 -1
  7. package/dist/fix/core/get-ts-morph-source-files.js +1 -1
  8. package/dist/fix/core/get-ts-morph-source-files.js.map +1 -1
  9. package/dist/pkg-builders/client/sd-cli-ng-routes.file-generator.d.ts +3 -2
  10. package/dist/pkg-builders/client/sd-cli-ng-routes.file-generator.js +15 -13
  11. package/dist/pkg-builders/client/sd-cli-ng-routes.file-generator.js.map +1 -1
  12. package/dist/pkg-builders/client/sd-client.build-runner.js +8 -6
  13. package/dist/pkg-builders/client/sd-client.build-runner.js.map +1 -1
  14. package/dist/pkg-builders/client/sd-ng.bundler.js +9 -9
  15. package/dist/pkg-builders/client/sd-ng.bundler.js.map +1 -1
  16. package/dist/pkg-builders/commons/build-runner.base.js +4 -5
  17. package/dist/pkg-builders/commons/build-runner.base.js.map +1 -1
  18. package/dist/pkg-builders/lib/sd-cli-db-context.file-generator.d.ts +3 -2
  19. package/dist/pkg-builders/lib/sd-cli-db-context.file-generator.js +14 -13
  20. package/dist/pkg-builders/lib/sd-cli-db-context.file-generator.js.map +1 -1
  21. package/dist/pkg-builders/lib/sd-cli-index.file-generator.d.ts +3 -2
  22. package/dist/pkg-builders/lib/sd-cli-index.file-generator.js +17 -12
  23. package/dist/pkg-builders/lib/sd-cli-index.file-generator.js.map +1 -1
  24. package/dist/pkg-builders/lib/sd-js-lib.build-runner.js +1 -1
  25. package/dist/pkg-builders/lib/sd-js-lib.build-runner.js.map +1 -1
  26. package/dist/pkg-builders/lib/sd-ts-lib.build-runner.js +9 -5
  27. package/dist/pkg-builders/lib/sd-ts-lib.build-runner.js.map +1 -1
  28. package/dist/pkg-builders/lib/sd-ts-lib.builder.js +20 -11
  29. package/dist/pkg-builders/lib/sd-ts-lib.builder.js.map +1 -1
  30. package/dist/pkg-builders/server/sd-server.build-runner.js +2 -2
  31. package/dist/pkg-builders/server/sd-server.build-runner.js.map +1 -1
  32. package/dist/pkg-builders/server/sd-server.bundler.js +1 -1
  33. package/dist/pkg-builders/server/sd-server.bundler.js.map +1 -1
  34. package/dist/ts-compiler/sd-dependency-cache.d.ts +56 -0
  35. package/dist/ts-compiler/sd-dependency-cache.js +183 -118
  36. package/dist/ts-compiler/sd-dependency-cache.js.map +1 -1
  37. package/dist/ts-compiler/sd-ts-compiler.js +5 -1
  38. package/dist/ts-compiler/sd-ts-compiler.js.map +1 -1
  39. package/dist/types/config.types.d.ts +2 -1
  40. package/package.json +5 -5
  41. package/src/entry/sd-cli-cordova.ts +2 -2
  42. package/src/entry/sd-cli-electron.ts +1 -1
  43. package/src/entry/sd-cli-project.ts +15 -0
  44. package/src/fix/core/get-ts-morph-source-files.ts +2 -2
  45. package/src/pkg-builders/client/sd-cli-ng-routes.file-generator.ts +23 -18
  46. package/src/pkg-builders/client/sd-client.build-runner.ts +16 -11
  47. package/src/pkg-builders/client/sd-ng.bundler-context.ts +1 -1
  48. package/src/pkg-builders/client/sd-ng.bundler.ts +9 -9
  49. package/src/pkg-builders/commons/build-runner.base.ts +19 -16
  50. package/src/pkg-builders/lib/sd-cli-db-context.file-generator.ts +16 -13
  51. package/src/pkg-builders/lib/sd-cli-index.file-generator.ts +21 -13
  52. package/src/pkg-builders/lib/sd-js-lib.build-runner.ts +1 -1
  53. package/src/pkg-builders/lib/sd-ts-lib.build-runner.ts +8 -7
  54. package/src/pkg-builders/lib/sd-ts-lib.builder.ts +23 -13
  55. package/src/pkg-builders/server/sd-server.build-runner.ts +2 -2
  56. package/src/pkg-builders/server/sd-server.bundler.ts +11 -11
  57. package/src/ts-compiler/sd-dependency-cache.ts +208 -171
  58. package/src/ts-compiler/sd-ts-compiler.ts +6 -2
  59. package/src/types/config.types.ts +8 -4
  60. package/tests/deps/sd-dependency-cache.spec.ts +12 -0
@@ -62,6 +62,11 @@ export class SdCliProject {
62
62
  });
63
63
 
64
64
  await pkgPaths.parallelAsync(async (pkgPath) => {
65
+ const pkgConf = projConf.packages[path.basename(pkgPath)];
66
+ if (pkgConf?.type === "library" && pkgConf.noBuild) {
67
+ return;
68
+ }
69
+
65
70
  await multiBuildRunner.runAsync({
66
71
  cmd: "watch",
67
72
  pkgPath,
@@ -103,6 +108,11 @@ export class SdCliProject {
103
108
  const multiBuildRunner = new SdMultiBuildRunner();
104
109
 
105
110
  const messages = await pkgPaths.parallelAsync(async (pkgPath) => {
111
+ const pkgConf = projConf.packages[path.basename(pkgPath)];
112
+ if (pkgConf?.type === "library" && pkgConf.noBuild) {
113
+ return [];
114
+ }
115
+
106
116
  return await multiBuildRunner.runAsync({
107
117
  cmd: "build",
108
118
  pkgPath,
@@ -164,6 +174,11 @@ export class SdCliProject {
164
174
  const multiBuildRunner = new SdMultiBuildRunner();
165
175
 
166
176
  const messages = await pkgPaths.parallelAsync(async (pkgPath) => {
177
+ const pkgConf = projConf.packages[path.basename(pkgPath)];
178
+ if (pkgConf?.type === "library" && pkgConf.noBuild) {
179
+ return [];
180
+ }
181
+
167
182
  return await multiBuildRunner.runAsync({
168
183
  cmd: "build",
169
184
  pkgPath,
@@ -5,5 +5,5 @@ export default function getTsMortphSourceFiles() {
5
5
  tsConfigFilePath: "tsconfig.base.json",
6
6
  });
7
7
 
8
- return project.getSourceFiles("packages/*/src/**/*.ts");
9
- }
8
+ return project.getSourceFiles("packages/*/dist/**/*.ts");
9
+ }
@@ -1,22 +1,24 @@
1
1
  import path from "path";
2
- import { FsUtils, PathUtils, SdFsWatcher } from "@simplysm/sd-core-node";
2
+ import { FsUtils, HashUtils, PathUtils, SdFsWatcher } from "@simplysm/sd-core-node";
3
3
  import { StringUtils } from "@simplysm/sd-core-common";
4
4
 
5
5
  export class SdCliNgRoutesFileGenerator {
6
- static watch(pkgPath: string, noLazyRoute?: boolean) {
7
- const routesFilePath = path.resolve(pkgPath, "src/routes.ts");
8
- let cache = FsUtils.exists(routesFilePath) ? FsUtils.readFile(routesFilePath) : undefined;
6
+ cachedHash?: string;
7
+
8
+ watch(pkgPath: string, noLazyRoute?: boolean) {
9
+ const routesFilePath = path.resolve(pkgPath, "dist/routes.ts");
10
+ this.cachedHash = FsUtils.exists(routesFilePath) ? HashUtils.get(FsUtils.readFile(routesFilePath)) : undefined;
9
11
 
10
12
  SdFsWatcher.watch([path.resolve(pkgPath, "src")]).onChange({ delay: 50 }, () => {
11
- cache = this.run(pkgPath, noLazyRoute, cache);
13
+ this.run(pkgPath, noLazyRoute);
12
14
  });
13
15
 
14
- cache = this.run(pkgPath, noLazyRoute, cache);
16
+ this.run(pkgPath, noLazyRoute);
15
17
  }
16
18
 
17
- static run(pkgPath: string, noLazyRoute?: boolean, cache?: string): string {
18
- const appDirPath = path.resolve(pkgPath, "src/app");
19
- const routesFilePath = path.resolve(pkgPath, "src/routes.ts");
19
+ run(pkgPath: string, noLazyRoute?: boolean) {
20
+ const appDirPath = path.resolve(pkgPath, "dist/app");
21
+ const routesFilePath = path.resolve(pkgPath, "dist/routes.ts");
20
22
 
21
23
  // 내부 파일들 import
22
24
  const result: TInfo = new Map();
@@ -52,16 +54,18 @@ export class SdCliNgRoutesFileGenerator {
52
54
  cont += indentStr + ` path: "${key}",\n`;
53
55
  if (val.relModulePath != null) {
54
56
  if (noLazyRoute) {
55
- cont += indentStr
56
- + ` component: ${StringUtils.toPascalCase(path.basename(val.relModulePath))},\n`;
57
- imports.push(`import { ${StringUtils.toPascalCase(path.basename(val.relModulePath))} } from "./app/${val.relModulePath}";`);
58
- }
59
- else {
57
+ cont +=
58
+ indentStr +
59
+ ` component: ${StringUtils.toPascalCase(path.basename(val.relModulePath))},\n`;
60
+ imports.push(
61
+ `import { ${StringUtils.toPascalCase(path.basename(val.relModulePath))} } from "./app/${val.relModulePath}";`,
62
+ );
63
+ } else {
60
64
  cont +=
61
65
  indentStr +
62
66
  ` loadComponent: () => import("./app/${val.relModulePath}").then((m) => m.${StringUtils.toPascalCase(
63
- path.basename(
64
- val.relModulePath))}),\n`;
67
+ path.basename(val.relModulePath),
68
+ )}),\n`;
65
69
  }
66
70
  }
67
71
  if (val.children.size > 0) {
@@ -82,10 +86,11 @@ ${imports.join("\n")}
82
86
  export const routes: Routes = [
83
87
  ${routes}
84
88
  ];`.trim();
85
- if (content !== cache) {
89
+ const currHash = HashUtils.get(content);
90
+ if (currHash !== this.cachedHash) {
86
91
  FsUtils.writeFile(routesFilePath, content);
92
+ this.cachedHash = currHash;
87
93
  }
88
- return content;
89
94
  }
90
95
  }
91
96
 
@@ -10,6 +10,7 @@ import { INpmConfig } from "../../types/common-configs.types";
10
10
  export class SdClientBuildRunner extends BuildRunnerBase<"client"> {
11
11
  protected override _logger = SdLogger.get(["simplysm", "sd-cli", "SdClientBuildRunner"]);
12
12
 
13
+ #routeGenerator = new SdCliNgRoutesFileGenerator();
13
14
  #ngBundlers?: SdNgBundler[];
14
15
  #cordova?: SdCliCordova;
15
16
 
@@ -17,6 +18,7 @@ export class SdClientBuildRunner extends BuildRunnerBase<"client"> {
17
18
  dev: boolean,
18
19
  modifiedFileSet?: Set<TNormPath>,
19
20
  ): Promise<IBuildRunnerRunResult> {
21
+ // 최초
20
22
  if (!modifiedFileSet) {
21
23
  this._debug("GEN .config...");
22
24
  const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
@@ -27,14 +29,14 @@ export class SdClientBuildRunner extends BuildRunnerBase<"client"> {
27
29
  if ("@angular/router" in (npmConf.dependencies ?? {})) {
28
30
  if (!dev) {
29
31
  this._debug(`GEN routes.ts...`);
30
- SdCliNgRoutesFileGenerator.run(this._pkgPath, this._pkgConf.noLazyRoute);
31
- }
32
- else {
32
+ this.#routeGenerator.run(this._pkgPath, this._pkgConf.noLazyRoute);
33
+ } else {
33
34
  this._debug(`Watch for GEN routes.ts...`);
34
- SdCliNgRoutesFileGenerator.watch(this._pkgPath, this._pkgConf.noLazyRoute);
35
+ this.#routeGenerator.watch(this._pkgPath, this._pkgConf.noLazyRoute);
35
36
  }
36
37
  }
37
38
  }
39
+ // watch
38
40
  else {
39
41
  for (const ngBundler of this.#ngBundlers!) {
40
42
  ngBundler.markForChanges(Array.from(modifiedFileSet));
@@ -45,7 +47,7 @@ export class SdClientBuildRunner extends BuildRunnerBase<"client"> {
45
47
  | "web"
46
48
  | "electron"
47
49
  | "cordova"
48
- )[];
50
+ )[];
49
51
  if (this._pkgConf.builder?.cordova && !this.#cordova) {
50
52
  this._debug("CORDOVA 준비...");
51
53
  this.#cordova = new SdCliCordova({
@@ -68,7 +70,7 @@ export class SdClientBuildRunner extends BuildRunnerBase<"client"> {
68
70
  ngBundlerBuilderType === "web"
69
71
  ? PathUtils.norm(this._pkgPath, "dist")
70
72
  : ngBundlerBuilderType === "electron" && !dev
71
- ? PathUtils.norm(this._pkgPath, ".electron/src")
73
+ ? PathUtils.norm(this._pkgPath, ".electron/dist")
72
74
  : ngBundlerBuilderType === "cordova" && !dev
73
75
  ? PathUtils.norm(this._pkgPath, ".cordova/www")
74
76
  : PathUtils.norm(this._pkgPath, "dist", ngBundlerBuilderType),
@@ -80,18 +82,21 @@ export class SdClientBuildRunner extends BuildRunnerBase<"client"> {
80
82
  ngBundlerBuilderType === "electron"
81
83
  ? (this._pkgConf.builder?.electron?.reinstallDependencies ?? [])
82
84
  : [],
83
- cordovaConfig: ngBundlerBuilderType === "cordova"
84
- ? this._pkgConf.builder!.cordova
85
- : undefined,
85
+ cordovaConfig:
86
+ ngBundlerBuilderType === "cordova" ? this._pkgConf.builder!.cordova : undefined,
86
87
  watchScopePathSet: this._watchScopePathSet,
87
88
  }),
88
89
  );
89
90
  }
90
91
 
91
92
  this._debug(`BUILD...`);
92
- const buildResults = await Promise.all(this.#ngBundlers.map((builder) => builder.bundleAsync()));
93
+ const buildResults = await Promise.all(
94
+ this.#ngBundlers.map((builder) => builder.bundleAsync()),
95
+ );
93
96
  const watchFileSet = new Set(buildResults.mapMany((item) => Array.from(item.watchFileSet)));
94
- const affectedFileSet = new Set(buildResults.mapMany((item) => Array.from(item.affectedFileSet)));
97
+ const affectedFileSet = new Set(
98
+ buildResults.mapMany((item) => Array.from(item.affectedFileSet)),
99
+ );
95
100
  const emitFileSet = new Set(buildResults.mapMany((item) => Array.from(item.emitFileSet)));
96
101
  const results = buildResults.mapMany((item) => item.results).distinct();
97
102
 
@@ -3,7 +3,7 @@ import path from "path";
3
3
  import { SdLogger } from "@simplysm/sd-core-node";
4
4
  import { SdCliConvertMessageUtils } from "../../utils/sd-cli-convert-message.utils";
5
5
 
6
- // import { InitialFileRecord } from "@angular/build/src/tools/esbuild/bundler-context";
6
+ // import { InitialFileRecord } from "@angular/build/dist/tools/esbuild/bundler-context";
7
7
 
8
8
  interface InitialFileRecord {
9
9
  entrypoint: boolean;
@@ -83,11 +83,11 @@ export class SdNgBundler {
83
83
  },
84
84
  ) {
85
85
  this.#pkgNpmConf = FsUtils.readJson(path.resolve(this._opt.pkgPath, "package.json"));
86
- this.#mainFilePath = path.resolve(this._opt.pkgPath, "src/main.ts");
86
+ this.#mainFilePath = path.resolve(this._opt.pkgPath, "dist/main.ts");
87
87
  this.#tsConfigFilePath = path.resolve(this._opt.pkgPath, "tsconfig.json");
88
88
  this.#swConfFilePath = path.resolve(this._opt.pkgPath, "ngsw-config.json");
89
89
  this.#browserTarget = transformSupportedBrowsersToTargets(browserslist(["Chrome > 78"]));
90
- this.#indexHtmlFilePath = path.resolve(this._opt.pkgPath, "src/index.html");
90
+ this.#indexHtmlFilePath = path.resolve(this._opt.pkgPath, "dist/index.html");
91
91
  this.#pkgName = path.basename(this._opt.pkgPath);
92
92
  this.#baseHref =
93
93
  this._opt.builderType === "web"
@@ -118,7 +118,7 @@ export class SdNgBundler {
118
118
  if (!this.#contexts) {
119
119
  this.#contexts = perf.run("get contexts", () => [
120
120
  this.#getAppContext(),
121
- ...FsUtils.exists(path.resolve(this._opt.pkgPath, "src/styles.scss")) ? [
121
+ ...FsUtils.exists(path.resolve(this._opt.pkgPath, "dist/styles.scss")) ? [
122
122
  this.#getStyleContext(),
123
123
  ] : [],
124
124
  ...(this._opt.builderType === "electron" ? [this.#getElectronMainContext()] : []),
@@ -253,7 +253,7 @@ export class SdNgBundler {
253
253
  }
254
254
  for (const assetFile of assetFiles) {
255
255
  const prevHash = this.#outputHashCache.get(PathUtils.norm(assetFile.source));
256
- const currHash = FsUtils.hash(assetFile.source);
256
+ const currHash = HashUtils.get(FsUtils.readFileBuffer(assetFile.source));
257
257
  if (prevHash !== currHash) {
258
258
  FsUtils.copy(assetFile.source, path.resolve(this._opt.outputPath, assetFile.destination));
259
259
  this.#outputHashCache.set(PathUtils.norm(assetFile.source), currHash);
@@ -413,7 +413,7 @@ export class SdNgBundler {
413
413
  }
414
414
 
415
415
  #getAppContext() {
416
- const workerEntries = FsUtils.glob(path.resolve(this._opt.pkgPath, "src/workers/*.ts"))
416
+ const workerEntries = FsUtils.glob(path.resolve(this._opt.pkgPath, "dist/workers/*.ts"))
417
417
  .toObject(
418
418
  (p) => "workers/" + path.basename(p, path.extname(p)),
419
419
  );
@@ -458,8 +458,8 @@ export class SdNgBundler {
458
458
  entryNames: "[dir]/[name]",
459
459
  entryPoints: {
460
460
  main: this.#mainFilePath,
461
- ...FsUtils.exists(path.resolve(this._opt.pkgPath, "src/polyfills.ts")) ? {
462
- polyfills: path.resolve(this._opt.pkgPath, "src/polyfills.ts"),
461
+ ...FsUtils.exists(path.resolve(this._opt.pkgPath, "dist/polyfills.ts")) ? {
462
+ polyfills: path.resolve(this._opt.pkgPath, "dist/polyfills.ts"),
463
463
  } : {},
464
464
 
465
465
  ...(this._opt.builderType === "cordova"
@@ -571,7 +571,7 @@ export class SdNgBundler {
571
571
  mainFields: ["style", "sass"],
572
572
  legalComments: !this._opt.dev ? "none" : "eof",
573
573
  entryPoints: {
574
- styles: path.resolve(this._opt.pkgPath, "src/styles.scss"),
574
+ styles: path.resolve(this._opt.pkgPath, "dist/styles.scss"),
575
575
  },
576
576
  plugins: [
577
577
  pluginFactory.create(SassStylesheetLanguage),
@@ -612,7 +612,7 @@ export class SdNgBundler {
612
612
  },
613
613
  platform: "node",
614
614
  entryPoints: {
615
- "electron-main": path.resolve(this._opt.pkgPath, "src/electron-main.ts"),
615
+ "electron-main": path.resolve(this._opt.pkgPath, "dist/electron-main.ts"),
616
616
  },
617
617
  });
618
618
  }
@@ -12,7 +12,9 @@ import { ISdBuildMessage, ISdBuildRunnerResult } from "../../types/build.types";
12
12
  import path from "path";
13
13
  import { ScopePathSet } from "./scope-path";
14
14
 
15
- export abstract class BuildRunnerBase<T extends "server" | "library" | "client"> extends EventEmitter {
15
+ export abstract class BuildRunnerBase<
16
+ T extends "server" | "library" | "client",
17
+ > extends EventEmitter {
16
18
  protected abstract _logger: SdLogger;
17
19
 
18
20
  protected _pkgName: string;
@@ -38,8 +40,8 @@ export abstract class BuildRunnerBase<T extends "server" | "library" | "client">
38
40
  this._pkgConf = projConf.packages[this._pkgName] as TSdPackageConfig<T>;
39
41
 
40
42
  const workspacePaths = workspaceGlobs
41
- .map(item => PathUtils.posix(this._pkgPath, "../../", item))
42
- .mapMany(item => FsUtils.glob(item));
43
+ .map((item) => PathUtils.posix(this._pkgPath, "../../", item))
44
+ .mapMany((item) => FsUtils.glob(item));
43
45
  const localUpdatePaths = Object.keys(projConf.localUpdates ?? {}).mapMany((key) =>
44
46
  FsUtils.glob(path.resolve(this._pkgPath, "../../node_modules", key)),
45
47
  );
@@ -81,10 +83,12 @@ export abstract class BuildRunnerBase<T extends "server" | "library" | "client">
81
83
  this.emit("complete", res);
82
84
 
83
85
  this._debug("WATCH...");
84
- let lastWatchFileSet = result.watchFileSet;
85
- SdFsWatcher.watch(this._watchScopePathSet.toArray())
86
- .onChange({ delay: 100 }, async (changeInfos) => {
86
+ let lastWatchFileSet = result.watchFileSet!;
87
+ SdFsWatcher.watch(this._watchScopePathSet.toArray()).onChange(
88
+ { delay: 100 },
89
+ async (changeInfos) => {
87
90
  const modifiedFileSet = this._getModifiedFileSet(changeInfos, lastWatchFileSet);
91
+
88
92
  if (modifiedFileSet.size < 1) return;
89
93
 
90
94
  this.emit("change");
@@ -93,9 +97,8 @@ export abstract class BuildRunnerBase<T extends "server" | "library" | "client">
93
97
  try {
94
98
  watchResult = await this._runAsync(!this._pkgConf.forceProductionMode, modifiedFileSet);
95
99
 
96
- lastWatchFileSet = watchResult.watchFileSet;
97
- }
98
- catch (err) {
100
+ lastWatchFileSet = watchResult.watchFileSet!;
101
+ } catch (err) {
99
102
  watchResult = {
100
103
  affectedFileSet: modifiedFileSet,
101
104
  buildMessages: [
@@ -119,7 +122,8 @@ export abstract class BuildRunnerBase<T extends "server" | "library" | "client">
119
122
  buildMessages: watchResult.buildMessages,
120
123
  emitFileSet: watchResult.emitFileSet,
121
124
  });
122
- });
125
+ },
126
+ );
123
127
  }
124
128
 
125
129
  protected _getModifiedFileSet(
@@ -127,11 +131,10 @@ export abstract class BuildRunnerBase<T extends "server" | "library" | "client">
127
131
  lastWatchFileSet?: Set<TNormPath>,
128
132
  ) {
129
133
  return new Set(
130
- (
131
- lastWatchFileSet
132
- ? changeInfos.filter((item) => lastWatchFileSet.has(item.path))
133
- : changeInfos
134
- ).map(item => item.path),
134
+ (lastWatchFileSet
135
+ ? changeInfos.filter((item) => lastWatchFileSet.has(item.path))
136
+ : changeInfos
137
+ ).map((item) => item.path),
135
138
  );
136
139
  }
137
140
 
@@ -150,4 +153,4 @@ export interface IBuildRunnerRunResult {
150
153
  affectedFileSet: Set<TNormPath>;
151
154
  buildMessages: ISdBuildMessage[];
152
155
  emitFileSet: Set<TNormPath>;
153
- }
156
+ }
@@ -1,21 +1,23 @@
1
- import { FsUtils, PathUtils, SdFsWatcher } from "@simplysm/sd-core-node";
1
+ import { FsUtils, HashUtils, PathUtils, SdFsWatcher } from "@simplysm/sd-core-node";
2
2
  import path from "path";
3
3
  import { StringUtils } from "@simplysm/sd-core-common";
4
4
  import { INpmConfig } from "../../types/common-configs.types";
5
5
 
6
6
  export class SdCliDbContextFileGenerator {
7
- static watch(pkgPath: string, kebabName: string) {
7
+ cachedHash?: string;
8
+
9
+ watch(pkgPath: string, kebabName: string) {
8
10
  const targetFilePath = path.resolve(pkgPath, `src/${kebabName}.ts`);
9
- let cache = FsUtils.exists(targetFilePath) ? FsUtils.readFile(targetFilePath) : undefined;
11
+ this.cachedHash = FsUtils.exists(targetFilePath) ? HashUtils.get(FsUtils.readFile(targetFilePath)) : undefined;
10
12
 
11
13
  SdFsWatcher.watch([path.resolve(pkgPath, "src")]).onChange({ delay: 50 }, () => {
12
- cache = this.run(pkgPath, kebabName, cache);
14
+ this.run(pkgPath, kebabName);
13
15
  });
14
16
 
15
- cache = this.run(pkgPath, kebabName, cache);
17
+ this.run(pkgPath, kebabName);
16
18
  }
17
19
 
18
- static run(pkgPath: string, kebabName: string, cache?: string): string {
20
+ run(pkgPath: string, kebabName: string) {
19
21
  const npmConfig = FsUtils.readJson(path.resolve(pkgPath, "package.json")) as INpmConfig;
20
22
  const useExt = npmConfig.dependencies?.["@simplysm/sd-orm-common-ext"] != null;
21
23
 
@@ -32,7 +34,7 @@ export class SdCliDbContextFileGenerator {
32
34
  // Migrations
33
35
  const migTexts: string[] = [];
34
36
  {
35
- const filePaths = FsUtils.glob(path.resolve(pkgPath, "src/migrations/**/*.ts"), {
37
+ const filePaths = FsUtils.glob(path.resolve(pkgPath, "dist/migrations/**/*.ts"), {
36
38
  nodir: true,
37
39
  });
38
40
 
@@ -52,7 +54,7 @@ export class SdCliDbContextFileGenerator {
52
54
  // Models
53
55
  const modelTexts: string[] = [];
54
56
  {
55
- const filePaths = FsUtils.glob(path.resolve(pkgPath, "src/models/**/*.ts"), { nodir: true });
57
+ const filePaths = FsUtils.glob(path.resolve(pkgPath, "dist/models/**/*.ts"), { nodir: true });
56
58
 
57
59
  for (const filePath of filePaths.orderBy()) {
58
60
  const requirePath = PathUtils.posix(path.relative(path.dirname(targetFilePath), filePath))
@@ -68,7 +70,7 @@ export class SdCliDbContextFileGenerator {
68
70
  useExt &&
69
71
  [
70
72
  "systemDataLog",
71
- "systemErrorLog",
73
+ "systemLog",
72
74
  "authentication",
73
75
  "user",
74
76
  "userConfig",
@@ -85,7 +87,7 @@ export class SdCliDbContextFileGenerator {
85
87
  // Views
86
88
  const viewTexts: string[] = [];
87
89
  {
88
- const filePaths = FsUtils.glob(path.resolve(pkgPath, "src/views/**/*.ts"), { nodir: true });
90
+ const filePaths = FsUtils.glob(path.resolve(pkgPath, "dist/views/**/*.ts"), { nodir: true });
89
91
 
90
92
  for (const filePath of filePaths.orderBy()) {
91
93
  const requirePath = PathUtils.posix(path.relative(path.dirname(targetFilePath), filePath))
@@ -104,7 +106,7 @@ export class SdCliDbContextFileGenerator {
104
106
  // Stored Procedures
105
107
  const spTexts: string[] = [];
106
108
  {
107
- const filePaths = FsUtils.glob(path.resolve(pkgPath, "src/stored-procedures/**/*.ts"), {
109
+ const filePaths = FsUtils.glob(path.resolve(pkgPath, "dist/stored-procedures/**/*.ts"), {
108
110
  nodir: true,
109
111
  });
110
112
 
@@ -145,9 +147,10 @@ ${viewTexts.length > 0 ? "\n // Views\n" + viewTexts.map((item) => " " + item)
145
147
  ${spTexts.length > 0 ? "\n // StoredProcedures\n" + spTexts.map((item) => " " + item).join("\n") : ""}
146
148
  }
147
149
  `.trim();
148
- if (content.trim() !== cache?.trim()) {
150
+ const currHash = HashUtils.get(content);
151
+ if (currHash !== this.cachedHash) {
149
152
  FsUtils.writeFile(targetFilePath, content);
153
+ this.cachedHash = currHash;
150
154
  }
151
- return content;
152
155
  }
153
156
  }
@@ -1,20 +1,22 @@
1
- import { FsUtils, PathUtils, SdFsWatcher } from "@simplysm/sd-core-node";
1
+ import { FsUtils, HashUtils, PathUtils, SdFsWatcher } from "@simplysm/sd-core-node";
2
2
  import path from "path";
3
3
 
4
4
  export class SdCliIndexFileGenerator {
5
- static watch(pkgPath: string, polyfills?: string[]) {
6
- const indexFilePath = path.resolve(pkgPath, "src/index.ts");
7
- let cache = FsUtils.exists(indexFilePath) ? FsUtils.readFile(indexFilePath) : undefined;
5
+ cachedHash?: string;
6
+
7
+ watch(pkgPath: string, polyfills?: string[]) {
8
+ const indexFilePath = path.resolve(pkgPath, "dist/index.ts");
9
+ this.cachedHash = FsUtils.exists(indexFilePath) ? FsUtils.readFile(indexFilePath) : undefined;
8
10
 
9
11
  SdFsWatcher.watch([path.resolve(pkgPath, "src")]).onChange({ delay: 50 }, () => {
10
- cache = this.run(pkgPath, polyfills, cache);
12
+ this.run(pkgPath, polyfills);
11
13
  });
12
14
 
13
- cache = this.run(pkgPath, polyfills, cache);
15
+ this.run(pkgPath, polyfills);
14
16
  }
15
17
 
16
- static run(pkgPath: string, polyfills?: string[], cache?: string): string {
17
- const indexFilePath = path.resolve(pkgPath, "src/index.ts");
18
+ run(pkgPath: string, polyfills?: string[]): string {
19
+ const indexFilePath = path.resolve(pkgPath, "dist/index.ts");
18
20
 
19
21
  const importTexts: string[] = [];
20
22
 
@@ -41,19 +43,25 @@ export class SdCliIndexFileGenerator {
41
43
  }
42
44
 
43
45
  const content = importTexts.join("\n") + "\n";
44
- if (content.trim() !== cache?.trim()) {
46
+ const currHash = HashUtils.get(content);
47
+ if (currHash !== this.cachedHash) {
45
48
  FsUtils.writeFile(indexFilePath, content);
49
+ this.cachedHash = currHash;
46
50
  }
47
51
  return content;
48
52
  }
49
53
 
50
- static #getFilePaths(pkgPath: string): string[] {
51
- const indexFilePath = path.resolve(pkgPath, "src/index.ts");
54
+ #getFilePaths(pkgPath: string): string[] {
55
+ const indexFilePath = path.resolve(pkgPath, "dist/index.ts");
52
56
 
53
57
  const tsconfig = FsUtils.readJson(path.resolve(pkgPath, "tsconfig.json"));
54
- const entryFilePaths: string[] = tsconfig.files?.map((item) => path.resolve(pkgPath, item)) ?? [];
58
+ const entryFilePaths: string[] =
59
+ tsconfig.files?.map((item) => path.resolve(pkgPath, item)) ?? [];
55
60
 
56
- return FsUtils.glob(path.resolve(pkgPath, "src/**/*{.ts,.tsx}"), { nodir: true, ignore: tsconfig.excludes }).filter(
61
+ return FsUtils.glob(path.resolve(pkgPath, "dist/**/*{.ts,.tsx}"), {
62
+ nodir: true,
63
+ ignore: tsconfig.excludes,
64
+ }).filter(
57
65
  (item) => !entryFilePaths.includes(item) && item !== indexFilePath && !item.endsWith(".d.ts"),
58
66
  );
59
67
  }
@@ -19,7 +19,7 @@ export class SdJsLibBuildRunner extends BuildRunnerBase<"library"> {
19
19
  modifiedFileSet?: Set<TNormPath>,
20
20
  ): Promise<IBuildRunnerRunResult> {
21
21
  const filePathSet = modifiedFileSet ?? new Set(
22
- FsUtils.glob(path.resolve(this._pkgPath, "src/**/*.js")).map(item => PathUtils.norm(item)),
22
+ FsUtils.glob(path.resolve(this._pkgPath, "dist/**/*.js")).map(item => PathUtils.norm(item)),
23
23
  );
24
24
 
25
25
  this._debug("LINT...");
@@ -5,8 +5,10 @@ import { SdCliIndexFileGenerator } from "./sd-cli-index.file-generator";
5
5
  import { SdCliDbContextFileGenerator } from "./sd-cli-db-context.file-generator";
6
6
 
7
7
  export class SdTsLibBuildRunner extends BuildRunnerBase<"library"> {
8
- protected override _logger = SdLogger.get(["simplysm", "sd-cli", "SdCliTsLibBuilder"]);
8
+ protected override _logger = SdLogger.get(["simplysm", "sd-cli", "SdTsLibBuildRunner"]);
9
9
 
10
+ #indexFileGenerator = new SdCliIndexFileGenerator();
11
+ #dbContextGenerator = new SdCliDbContextFileGenerator();
10
12
  #builder?: SdTsLibBuilder;
11
13
 
12
14
  protected override async _runAsync(
@@ -17,23 +19,22 @@ export class SdTsLibBuildRunner extends BuildRunnerBase<"library"> {
17
19
  if (!dev) {
18
20
  if (!this._pkgConf.noGenIndex) {
19
21
  this._debug("GEN index.ts...");
20
- SdCliIndexFileGenerator.run(this._pkgPath, this._pkgConf.polyfills);
22
+ this.#indexFileGenerator.run(this._pkgPath, this._pkgConf.polyfills);
21
23
  }
22
24
 
23
25
  if (this._pkgConf.dbContext != null) {
24
26
  this._debug(`GEN ${this._pkgConf.dbContext}.ts...`);
25
- SdCliDbContextFileGenerator.run(this._pkgPath, this._pkgConf.dbContext);
27
+ this.#dbContextGenerator.run(this._pkgPath, this._pkgConf.dbContext);
26
28
  }
27
- }
28
- else {
29
+ } else {
29
30
  if (!this._pkgConf.noGenIndex) {
30
31
  this._debug("Watch for GEN index.ts...");
31
- SdCliIndexFileGenerator.watch(this._pkgPath, this._pkgConf.polyfills);
32
+ this.#indexFileGenerator.watch(this._pkgPath, this._pkgConf.polyfills);
32
33
  }
33
34
 
34
35
  if (this._pkgConf.dbContext != null) {
35
36
  this._debug(`Watch for GEN ${this._pkgConf.dbContext}.ts...`);
36
- SdCliDbContextFileGenerator.watch(this._pkgPath, this._pkgConf.dbContext);
37
+ this.#dbContextGenerator.watch(this._pkgPath, this._pkgConf.dbContext);
37
38
  }
38
39
  }
39
40
  }
@@ -1,12 +1,13 @@
1
1
  import path from "path";
2
2
  import { SdCliConvertMessageUtils } from "../../utils/sd-cli-convert-message.utils";
3
- import { FsUtils, PathUtils, TNormPath } from "@simplysm/sd-core-node";
3
+ import { FsUtils, HashUtils, 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
6
  import { ScopePathSet } from "../commons/scope-path";
7
7
 
8
8
  export class SdTsLibBuilder {
9
9
  #tsCompiler: SdTsCompiler;
10
+ #outputHashCache = new Map<TNormPath, string>();
10
11
 
11
12
  constructor(
12
13
  private readonly _pkgPath: TNormPath,
@@ -17,7 +18,7 @@ export class SdTsLibBuilder {
17
18
  pkgPath: this._pkgPath,
18
19
  additionalOptions: { declaration: true },
19
20
  isDevMode: dev,
20
- globalStyleFilePath: PathUtils.norm(this._pkgPath, "src/styles.scss"),
21
+ globalStyleFilePath: PathUtils.norm(this._pkgPath, "dist/styles.scss"),
21
22
  isForBundle: false,
22
23
  watchScopePathSet,
23
24
  });
@@ -37,15 +38,20 @@ export class SdTsLibBuilder {
37
38
  if (emitFileInfos) {
38
39
  for (const emitFileInfo of emitFileInfos) {
39
40
  if (emitFileInfo.outAbsPath != null) {
40
- FsUtils.writeFile(emitFileInfo.outAbsPath, emitFileInfo.text);
41
- emitFileSet.add(emitFileInfo.outAbsPath);
41
+ const emitFilePath = PathUtils.norm(emitFileInfo.outAbsPath);
42
+ const prevHash = this.#outputHashCache.get(emitFilePath);
43
+ const currHash = HashUtils.get(Buffer.from(emitFileInfo.text));
44
+ if (prevHash !== currHash) {
45
+ FsUtils.writeFile(emitFilePath, emitFileInfo.text);
46
+ this.#outputHashCache.set(emitFilePath, currHash);
47
+ emitFileSet.add(emitFilePath);
48
+ }
42
49
  }
43
50
  }
44
51
  }
45
52
 
46
- const globalStylesheetBundlingResult = tsCompileResult
47
- .stylesheetBundlingResultMap
48
- .get(emitFile);
53
+ const globalStylesheetBundlingResult =
54
+ tsCompileResult.stylesheetBundlingResultMap.get(emitFile);
49
55
  if (globalStylesheetBundlingResult && "outputFiles" in globalStylesheetBundlingResult) {
50
56
  for (const outputFile of globalStylesheetBundlingResult.outputFiles) {
51
57
  const distPath = PathUtils.norm(
@@ -54,17 +60,21 @@ export class SdTsLibBuilder {
54
60
  path.relative(this._pkgPath, outputFile.path),
55
61
  );
56
62
  if (PathUtils.isChildPath(distPath, path.resolve(this._pkgPath, "dist"))) {
57
- FsUtils.writeFile(distPath, outputFile.text);
58
- emitFileSet.add(distPath);
63
+ const prevHash = this.#outputHashCache.get(distPath);
64
+ const currHash = HashUtils.get(Buffer.from(outputFile.text));
65
+ if (prevHash !== currHash) {
66
+ FsUtils.writeFile(distPath, outputFile.text);
67
+ this.#outputHashCache.set(distPath, currHash);
68
+ emitFileSet.add(distPath);
69
+ }
59
70
  }
60
71
  }
61
72
  }
62
73
  }
63
74
 
64
- const styleResults = Array.from(tsCompileResult.stylesheetBundlingResultMap.values())
65
- .mapMany((item) =>
66
- SdCliConvertMessageUtils.convertToBuildMessagesFromEsbuild(item, this._pkgPath),
67
- );
75
+ const styleResults = Array.from(tsCompileResult.stylesheetBundlingResultMap.values()).mapMany(
76
+ (item) => SdCliConvertMessageUtils.convertToBuildMessagesFromEsbuild(item, this._pkgPath),
77
+ );
68
78
 
69
79
  return {
70
80
  watchFileSet: tsCompileResult.watchFileSet,
@@ -40,8 +40,8 @@ export class SdServerBuildRunner extends BuildRunnerBase<"server"> {
40
40
  entryPoints: tsConfig.files
41
41
  ? tsConfig.files.map((item) => path.resolve(this._pkgPath, item))
42
42
  : [
43
- path.resolve(this._pkgPath, "src/main.ts"),
44
- ...FsUtils.glob(path.resolve(this._pkgPath, "src/workers/*.ts")),
43
+ path.resolve(this._pkgPath, "dist/main.ts"),
44
+ ...FsUtils.glob(path.resolve(this._pkgPath, "dist/workers/*.ts")),
45
45
  ],
46
46
  external: this.#extModules.map((item) => item.name),
47
47
  watchScopePathSet: this._watchScopePathSet,