@simplysm/sd-cli 10.0.37 → 10.0.39

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 (84) hide show
  1. package/dist/SdLinter.js.map +1 -1
  2. package/dist/SdTsIncrementalBuilder.d.ts +17 -4
  3. package/dist/SdTsIncrementalBuilder.js +18 -32
  4. package/dist/SdTsIncrementalBuilder.js.map +1 -1
  5. package/dist/build-cluster.js +98 -30
  6. package/dist/build-cluster.js.map +1 -1
  7. package/dist/builders/SdCliClientBuilder.d.ts +6 -2
  8. package/dist/builders/SdCliClientBuilder.js +107 -114
  9. package/dist/builders/SdCliClientBuilder.js.map +1 -1
  10. package/dist/builders/SdCliServerBuilder.d.ts +2 -1
  11. package/dist/builders/SdCliServerBuilder.js +38 -12
  12. package/dist/builders/SdCliServerBuilder.js.map +1 -1
  13. package/dist/builders/SdCliTsLibBuilder.d.ts +5 -2
  14. package/dist/builders/SdCliTsLibBuilder.js +64 -10
  15. package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
  16. package/dist/commons.d.ts +28 -2
  17. package/dist/entry/SdCliElectron.d.ts +7 -0
  18. package/dist/entry/SdCliElectron.js +42 -0
  19. package/dist/entry/SdCliElectron.js.map +1 -0
  20. package/dist/entry/SdCliLocalUpdate.d.ts +12 -0
  21. package/dist/entry/SdCliLocalUpdate.js +94 -0
  22. package/dist/entry/SdCliLocalUpdate.js.map +1 -0
  23. package/dist/entry/SdCliProject.d.ts +3 -3
  24. package/dist/entry/SdCliProject.js +87 -31
  25. package/dist/entry/SdCliProject.js.map +1 -1
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.js +2 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/sd-cli.d.ts +1 -1
  30. package/dist/sd-cli.js +74 -13
  31. package/dist/sd-cli.js.map +1 -1
  32. package/dist/utils/SdCliBuildResultUtil.js +1 -1
  33. package/dist/utils/SdCliBuildResultUtil.js.map +1 -1
  34. package/dist/utils/SdCliViteElectronMainPlugin.d.ts +6 -0
  35. package/dist/utils/SdCliViteElectronMainPlugin.js +81 -0
  36. package/dist/utils/SdCliViteElectronMainPlugin.js.map +1 -0
  37. package/dist/utils/SdCliViteExternalPlugin.d.ts +7 -0
  38. package/dist/utils/SdCliViteExternalPlugin.js +98 -0
  39. package/dist/utils/SdCliViteExternalPlugin.js.map +1 -0
  40. package/dist/utils/SdCliViteLoggerPlugin.d.ts +6 -0
  41. package/dist/utils/SdCliViteLoggerPlugin.js +24 -0
  42. package/dist/utils/SdCliViteLoggerPlugin.js.map +1 -0
  43. package/dist/utils/SdCliViteNodeGlobalPlugin.d.ts +2 -0
  44. package/dist/utils/SdCliViteNodeGlobalPlugin.js +29 -0
  45. package/dist/utils/SdCliViteNodeGlobalPlugin.js.map +1 -0
  46. package/dist/utils/SdCliViteReactSwcPlugin.d.ts +2 -0
  47. package/dist/utils/SdCliViteReactSwcPlugin.js +141 -0
  48. package/dist/utils/SdCliViteReactSwcPlugin.js.map +1 -0
  49. package/dist/utils/SdCliViteWatchWithResolutionsPlugin.d.ts +2 -0
  50. package/dist/utils/SdCliViteWatchWithResolutionsPlugin.js +26 -0
  51. package/dist/utils/SdCliViteWatchWithResolutionsPlugin.js.map +1 -0
  52. package/dist/utils/getElectronReactExternals.d.ts +1 -0
  53. package/dist/utils/getElectronReactExternals.js +17 -0
  54. package/dist/utils/getElectronReactExternals.js.map +1 -0
  55. package/dist/utils/sdCliTsDefineTransformer.d.ts +4 -0
  56. package/dist/utils/sdCliTsDefineTransformer.js +26 -0
  57. package/dist/utils/sdCliTsDefineTransformer.js.map +1 -0
  58. package/package.json +25 -11
  59. package/src/SdLinter.ts +2 -2
  60. package/src/SdTsIncrementalBuilder.ts +116 -105
  61. package/src/build-cluster.ts +173 -111
  62. package/src/builders/SdCliClientBuilder.ts +226 -221
  63. package/src/builders/SdCliServerBuilder.ts +311 -275
  64. package/src/builders/SdCliTsLibBuilder.ts +160 -89
  65. package/src/commons.ts +66 -34
  66. package/src/entry/SdCliElectron.ts +55 -0
  67. package/src/entry/SdCliLocalUpdate.ts +125 -0
  68. package/src/entry/SdCliProject.ts +452 -395
  69. package/src/index.ts +1 -0
  70. package/src/sd-cli.ts +185 -122
  71. package/src/utils/SdCliBuildResultUtil.ts +1 -2
  72. package/src/utils/SdCliViteElectronMainPlugin.ts +86 -0
  73. package/src/utils/SdCliViteExternalPlugin.ts +112 -0
  74. package/src/utils/SdCliViteLoggerPlugin.ts +29 -0
  75. package/src/utils/SdCliViteNodeGlobalPlugin.ts +31 -0
  76. package/src/utils/SdCliViteReactSwcPlugin.ts +154 -0
  77. package/src/utils/SdCliViteWatchWithResolutionsPlugin.ts +29 -0
  78. package/src/utils/getElectronReactExternals.ts +19 -0
  79. package/src/utils/sdCliTsDefineTransformer.ts +31 -0
  80. package/.eslintrc.cjs +0 -18
  81. package/dist/utils/SdCliConfigUtil.d.ts +0 -7
  82. package/dist/utils/SdCliConfigUtil.js +0 -69
  83. package/dist/utils/SdCliConfigUtil.js.map +0 -1
  84. package/src/utils/SdCliConfigUtil.ts +0 -94
@@ -1,95 +1,166 @@
1
- import { FsUtil, Logger, SdFsWatcher } from "@simplysm/sd-core-node";
1
+ import {FsUtil, Logger, SdFsWatcher} from "@simplysm/sd-core-node";
2
2
  import path from "path";
3
- import { ISdCliBuilderResult } from "../commons";
4
- import { EventEmitter } from "events";
5
- import { FunctionQueue } from "@simplysm/sd-core-common";
6
- import { SdTsIncrementalBuilder } from "../SdTsIncrementalBuilder";
7
- import { SdLinter } from "../SdLinter";
3
+ import {ISdCliBuilderResult, ISdCliLibPackageConfig, ISdCliPackageBuildResult} from "../commons";
4
+ import {EventEmitter} from "events";
5
+ import {FunctionQueue, Uuid} from "@simplysm/sd-core-common";
6
+ import {SdTsIncrementalBuilder} from "../SdTsIncrementalBuilder";
7
+ import {SdLinter} from "../SdLinter";
8
+ import {pathToFileURL} from "url";
9
+ import less from "less";
10
+ import ts from "typescript";
11
+ import transformKeys from "ts-transformer-keys/transformer";
8
12
 
9
13
  export class SdCliTsLibBuilder extends EventEmitter {
10
- private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliTsLibBuilder"]);
11
-
12
- public constructor(private readonly _pkgPath: string) {
13
- super();
14
- }
15
-
16
- public override on(event: "change", listener: () => void): this;
17
- public override on(event: "complete", listener: (result: ISdCliBuilderResult) => void): this;
18
- public override on(event: string | symbol, listener: (...args: any[]) => void): this {
19
- super.on(event, listener);
20
- return this;
21
- }
22
-
23
- public async buildAsync(): Promise<ISdCliBuilderResult> {
24
- this._debug("빌드 준비...");
25
- const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, true, false);
26
-
27
- this._debug("dist 초기화...");
28
- await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
29
-
30
- this._debug("BUILD...");
31
- const buildResult = await sdTsProgram.buildAsync();
32
-
33
- this._debug("LINT...");
34
- const lintResults = await SdLinter.lintAsync(buildResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
35
-
36
- this._debug(`빌드 완료`);
37
- return {
38
- affectedFilePaths: buildResult.affectedFilePaths,
39
- buildResults: [...buildResult.results, ...lintResults]
40
- };
41
- }
42
-
43
- public async watchAsync(): Promise<void> {
44
- this._debug("빌드 준비...");
45
- const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, true, true);
46
-
47
- this._debug("dist 초기화...");
48
- await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
49
-
50
- this.emit("change");
51
-
52
- this._debug("BUILD...");
53
- const buildResult = await sdTsProgram.buildAsync();
54
-
55
- this._debug("LINT...");
56
- const lintResults = await SdLinter.lintAsync(buildResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
57
-
58
- this._debug(`빌드 완료`);
59
- this.emit("complete", {
60
- affectedFilePaths: buildResult.affectedFilePaths,
61
- buildResults: [...buildResult.results, ...lintResults]
62
- });
63
-
64
- this._debug("WATCH...");
65
- const fnQ = new FunctionQueue();
66
- SdFsWatcher
67
- .watch([
68
- ...sdTsProgram.builderProgram!.getSourceFiles().map((item) => item.fileName),
69
- path.resolve(this._pkgPath, "src/**/*.{ts,tsx}")
70
- ])
71
- .onChange({
72
- delay: 100
73
- }, () => {
74
- fnQ.runLast(async () => {
75
- this.emit("change");
76
-
77
- this._debug(`BUILD...`);
78
- const watchBuildResult = await sdTsProgram.buildAsync();
79
-
80
- this._debug(`LINT...`);
81
- const watchLintResults = await SdLinter.lintAsync(watchBuildResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
82
-
83
- this._debug(`빌드 완료`);
84
- this.emit("complete", {
85
- affectedFilePaths: watchBuildResult.affectedFilePaths,
86
- buildResults: [...watchBuildResult.results, ...watchLintResults]
87
- });
14
+ private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliTsLibBuilder"]);
15
+
16
+ public constructor(private readonly _pkgPath: string,
17
+ private readonly _pkgConf: ISdCliLibPackageConfig,
18
+ private readonly _withLint: boolean) {
19
+ super();
20
+ }
21
+
22
+ public override on(event: "change", listener: () => void): this;
23
+ public override on(event: "complete", listener: (result: ISdCliBuilderResult) => void): this;
24
+ public override on(event: string | symbol, listener: (...args: any[]) => void): this {
25
+ super.on(event, listener);
26
+ return this;
27
+ }
28
+
29
+ public async buildAsync(): Promise<ISdCliBuilderResult> {
30
+ this._debug("빌드 준비...");
31
+ const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, (opt) => ({
32
+ emitJs: true,
33
+ transforms: opt.jsx === ts.JsxEmit.ReactJSX ? [{fn: transformKeys, args: undefined}] : undefined
34
+ }));
35
+
36
+ this._debug("dist 초기화...");
37
+ await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
38
+
39
+ this._debug("BUILD...");
40
+ const buildResult = await sdTsProgram.buildAsync();
41
+
42
+ this._debug("LINT...");
43
+ const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(buildResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
44
+
45
+ let styleResult: ISdCliPackageBuildResult | undefined;
46
+ if (this._pkgConf.style !== undefined) {
47
+ this._debug("STYLE...");
48
+ styleResult = await this._genStyleAsync();
49
+ }
50
+
51
+ this._debug("COPY...");
52
+ await FsUtil.copyAsync(
53
+ path.resolve(this._pkgPath, "src/assets"),
54
+ path.resolve(this._pkgPath, "dist/assets")
55
+ );
56
+
57
+
58
+ this._debug(`빌드 완료`);
59
+ return {
60
+ affectedFilePaths: buildResult.affectedFilePaths,
61
+ buildResults: [...buildResult.results, ...lintResults, ...styleResult ? [styleResult] : []]
62
+ };
63
+ }
64
+
65
+ public async watchAsync(): Promise<void> {
66
+ this._debug("빌드 준비...");
67
+ const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, (opt) => ({
68
+ emitJs: true,
69
+ compilerOptions: opt.jsx === ts.JsxEmit.ReactJSX ? {jsx: ts.JsxEmit.ReactJSXDev} : undefined,
70
+ transforms: opt.jsx === ts.JsxEmit.ReactJSX ? [{fn: transformKeys, args: undefined},] : undefined
71
+ }));
72
+
73
+ this._debug("dist 초기화...");
74
+ await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
75
+
76
+ this.emit("change");
77
+
78
+ this._debug("BUILD...");
79
+ const buildResult = await sdTsProgram.buildAsync();
80
+
81
+ this._debug("LINT...");
82
+ const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(buildResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
83
+
84
+ let styleResult: ISdCliPackageBuildResult | undefined;
85
+ if (this._pkgConf.style !== undefined) {
86
+ this._debug("STYLE...");
87
+ styleResult = await this._genStyleAsync();
88
+ }
89
+
90
+ this._debug("COPY...");
91
+ await FsUtil.copyAsync(
92
+ path.resolve(this._pkgPath, "src/assets"),
93
+ path.resolve(this._pkgPath, "dist/assets")
94
+ );
95
+
96
+ this._debug(`빌드 완료`);
97
+ this.emit("complete", {
98
+ affectedFilePaths: buildResult.affectedFilePaths,
99
+ buildResults: [...buildResult.results, ...lintResults, ...styleResult ? [styleResult] : []]
88
100
  });
89
- });
90
- }
91
101
 
92
- private _debug(msg: string): void {
93
- this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
94
- }
102
+ this._debug("WATCH...");
103
+ const fnQ = new FunctionQueue();
104
+ SdFsWatcher
105
+ .watch([
106
+ ...sdTsProgram.builderProgram!.getSourceFiles().map((item) => item.fileName),
107
+ path.resolve(this._pkgPath, "src/**/*.{ts,tsx}")
108
+ ])
109
+ .onChange({
110
+ delay: 100
111
+ }, () => {
112
+ fnQ.runLast(async () => {
113
+ this.emit("change");
114
+
115
+ this._debug(`BUILD...`);
116
+ const watchBuildResult = await sdTsProgram.buildAsync();
117
+
118
+ this._debug(`LINT...`);
119
+ const watchLintResults = !this._withLint ? [] : await SdLinter.lintAsync(watchBuildResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
120
+
121
+ let watchStyleResult: ISdCliPackageBuildResult | undefined;
122
+ if (this._pkgConf.style !== undefined && watchBuildResult.affectedFilePaths.some((item) => item.endsWith(this._pkgConf.style!))) {
123
+ this._debug("STYLE...");
124
+ watchStyleResult = await this._genStyleAsync();
125
+ }
126
+
127
+ this._debug("COPY...");
128
+ await FsUtil.copyAsync(
129
+ path.resolve(this._pkgPath, "src/assets"),
130
+ path.resolve(this._pkgPath, "dist/assets")
131
+ );
132
+
133
+ this._debug(`빌드 완료`);
134
+ this.emit("complete", {
135
+ affectedFilePaths: watchBuildResult.affectedFilePaths,
136
+ buildResults: [...watchBuildResult.results, ...watchLintResults, ...watchStyleResult ? [watchStyleResult] : []]
137
+ });
138
+ });
139
+ });
140
+ }
141
+
142
+ private _debug(msg: string): void {
143
+ this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
144
+ }
145
+
146
+ private async _genStyleAsync(): Promise<ISdCliPackageBuildResult | undefined> {
147
+ const srcFilePath = path.resolve(this._pkgPath, "dist", this._pkgConf.style! + ".js");
148
+ try {
149
+ const styleImport = await import(pathToFileURL(srcFilePath).href + "?token=" + Uuid.new().toString());
150
+ const styleText = styleImport.default.join("");
151
+ const styleRendered = await less.render(styleText);
152
+ await FsUtil.writeFileAsync(path.resolve(this._pkgPath, "style.css"), styleRendered.css);
153
+ } catch (err) {
154
+ return {
155
+ code: undefined,
156
+ message: err.message,
157
+ severity: "error",
158
+ char: undefined,
159
+ line: undefined,
160
+ filePath: srcFilePath
161
+ };
162
+ }
163
+
164
+ return;
165
+ }
95
166
  }
package/src/commons.ts CHANGED
@@ -1,64 +1,96 @@
1
1
  export interface INpmConfig {
2
- name: string;
3
- version: string;
4
- workspaces?: string[];
2
+ name: string;
3
+ description?: string;
4
+ version: string;
5
+ workspaces?: string[];
5
6
 
6
- dependencies?: Record<string, string>;
7
- optionalDependencies?: Record<string, string>;
8
- devDependencies?: Record<string, string>;
9
- peerDependencies?: Record<string, string>;
10
- peerDependenciesMeta?: Record<string, { optional?: boolean }>;
7
+ dependencies?: Record<string, string>;
8
+ optionalDependencies?: Record<string, string>;
9
+ devDependencies?: Record<string, string>;
10
+ peerDependencies?: Record<string, string>;
11
+ peerDependenciesMeta?: Record<string, {
12
+ optional?: boolean
13
+ }>;
11
14
 
12
- resolutions?: Record<string, string>;
15
+ resolutions?: Record<string, string>;
13
16
  }
14
17
 
15
18
  export interface ISdCliBuildClusterReqMessage {
16
- cmd: "watch" | "build";
17
- pkgPath: string;
18
- pkgConf: TSdCliPackageConfig
19
+ cmd: "watch" | "build";
20
+ pkgPath: string;
21
+ pkgConf: TSdCliPackageConfig;
22
+ builderKey?: "web" | "electron";
23
+ withLint: boolean;
19
24
  }
20
25
 
21
26
  export interface ISdCliBuildClusterResMessage {
22
- req: ISdCliBuildClusterReqMessage;
23
- type: "change" | "complete" | "ready";
24
- result?: ISdCliBuilderResult;
27
+ req: ISdCliBuildClusterReqMessage;
28
+ type: "change" | "complete" | "ready";
29
+ result?: ISdCliBuilderResult;
25
30
  }
26
31
 
27
32
  export interface ISdCliBuilderResult {
28
- port?: number;
29
- affectedFilePaths: string[];
30
- buildResults: ISdCliPackageBuildResult[];
33
+ port?: number;
34
+ affectedFilePaths: string[];
35
+ buildResults: ISdCliPackageBuildResult[];
31
36
  }
32
37
 
33
38
  export interface ISdCliPackageBuildResult {
34
- filePath: string | undefined;
35
- line: number | undefined;
36
- char: number | undefined;
37
- code: string | undefined;
38
- severity: "error" | "warning" | "suggestion" | "message";
39
- message: string;
39
+ filePath: string | undefined;
40
+ line: number | undefined;
41
+ char: number | undefined;
42
+ code: string | undefined;
43
+ severity: "error" | "warning" | "suggestion" | "message";
44
+ message: string;
40
45
  }
41
46
 
42
47
  export interface ISdCliConfig {
43
- packages: Record<string, TSdCliPackageConfig | undefined>;
44
- localUpdates?: Record<string, string>;
48
+ packages: Record<string, TSdCliPackageConfig | undefined>;
49
+ localUpdates?: Record<string, string>;
45
50
  }
51
+ export type TSdCliConfigFn = (isDev: boolean, opts?: string[]) => ISdCliConfig;
46
52
 
47
53
  export type TSdCliPackageConfig = ISdCliLibPackageConfig | ISdCliServerPackageConfig | ISdCliClientPackageConfig;
48
54
 
49
55
  export interface ISdCliLibPackageConfig {
50
- type: "library";
51
- publish?: "npm";
56
+ type: "library";
57
+ style?: string;
58
+ publish?: "npm";
52
59
  }
53
60
 
54
61
  export interface ISdCliServerPackageConfig {
55
- type: "server";
56
- externals?: string[];
57
- publish?: any;
62
+ type: "server";
63
+ externals?: string[];
64
+ publish?: ISdCliLocalDirectoryPublishConfig;
65
+ configs?: Record<string, any>;
58
66
  }
59
67
 
60
68
  export interface ISdCliClientPackageConfig {
61
- type: "client";
62
- server?: string;
63
- publish?: any;
69
+ type: "client";
70
+ server?: string;
71
+ publish?: ISdCliLocalDirectoryPublishConfig;
72
+ env?: Record<string, string>;
73
+ configs?: Record<string, any>;
74
+
75
+ builder?: {
76
+ web?: ISdCliClientBuilderWebConfig;
77
+ electron?: ISdCliClientBuilderElectronConfig;
78
+ }
79
+ }
80
+
81
+ export interface ISdCliLocalDirectoryPublishConfig {
82
+ type: "local-directory";
83
+ path: string;
84
+ }
85
+
86
+ export interface ISdCliClientBuilderElectronConfig {
87
+ appId: string;
88
+ installerIcon?: string;
89
+ postInstallScript?: string;
90
+ devServerPort?: number;
91
+ reinstallDependencies?: string[];
92
+ }
93
+
94
+ export interface ISdCliClientBuilderWebConfig {
95
+ devServerPort?: number;
64
96
  }
@@ -0,0 +1,55 @@
1
+ import {FsUtil, Logger, SdProcess} from "@simplysm/sd-core-node";
2
+ import {pathToFileURL} from "url";
3
+ import path from "path";
4
+ import {INpmConfig, ISdCliConfig} from "../commons";
5
+
6
+ export class SdCliElectron {
7
+ public static async runAsync(opt: {
8
+ confFileRelPath: string;
9
+ optNames: string[];
10
+ pkgName: string;
11
+ }): Promise<void> {
12
+ const logger = Logger.get(["simplysm", "sd-cli", "SdCliElectron", "runAsync"]);
13
+
14
+ const pkgPath = path.resolve(process.cwd(), `packages/${opt.pkgName}`);
15
+ const electronPath = path.resolve(pkgPath, ".cache/dev/electron/src");
16
+
17
+ logger.log("설정 가져오기...");
18
+ const projConf = (await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)).default(true, opt.optNames) as ISdCliConfig;
19
+ const pkgConf = projConf.packages[opt.pkgName];
20
+ if (pkgConf?.type !== "client" || pkgConf.builder?.electron === undefined) {
21
+ throw new Error();
22
+ }
23
+
24
+ logger.log("package.json 파일 쓰기...");
25
+ const npmConfig = (await FsUtil.readJsonAsync(path.resolve(pkgPath, `package.json`))) as INpmConfig;
26
+
27
+ const externalPkgNames = pkgConf.builder.electron.reinstallDependencies ?? [];
28
+
29
+ await FsUtil.writeJsonAsync(path.resolve(electronPath, `package.json`), {
30
+ name: npmConfig.name,
31
+ version: npmConfig.version,
32
+ description: npmConfig.description,
33
+ main: "electron-main.js",
34
+ ...pkgConf.builder.electron.postInstallScript !== undefined ? {
35
+ scripts: {
36
+ "postinstall": pkgConf.builder.electron.postInstallScript
37
+ },
38
+ } : {},
39
+ dependencies: externalPkgNames.toObject((item) => item, (item) => npmConfig.dependencies![item])
40
+ });
41
+
42
+ logger.log("npm install...");
43
+ await SdProcess.spawnAsync(`npm install`, {cwd: electronPath}, true);
44
+
45
+ for (const externalPkgName of externalPkgNames) {
46
+ if (FsUtil.exists(path.resolve(electronPath, "node_modules", externalPkgName, "binding.gyp"))) {
47
+ logger.log(`electron rebuild (${externalPkgName})...`);
48
+ await SdProcess.spawnAsync(`electron-rebuild -m ./node_modules/${externalPkgName}`, {cwd: electronPath}, true);
49
+ }
50
+ }
51
+
52
+ logger.log("electron...");
53
+ await SdProcess.spawnAsync(`electron .`, {cwd: electronPath}, true);
54
+ }
55
+ }
@@ -0,0 +1,125 @@
1
+ import {FsUtil, Logger, PathUtil, SdFsWatcher} from "@simplysm/sd-core-node";
2
+ import path from "path";
3
+ import {pathToFileURL} from "url";
4
+ import {ISdCliConfig} from "../commons";
5
+
6
+ export class SdCliLocalUpdate {
7
+ public static async runAsync(opt: {
8
+ confFileRelPath: string;
9
+ optNames: string[];
10
+ }): Promise<void> {
11
+ const logger = Logger.get(["simplysm", "sd-cli", "SdCliLocalUpdate", "runAsync"]);
12
+
13
+ logger.debug("프로젝트 설정 가져오기...");
14
+ const projConf = (await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)).default(true, opt.optNames) as ISdCliConfig;
15
+ if (!projConf.localUpdates) return;
16
+
17
+ logger.debug("로컬 업데이트 구성...");
18
+ const updatePathInfos = await this._getUpdatePathInfosAsync(projConf.localUpdates);
19
+
20
+ logger.log("로컬 라이브러리 업데이트...");
21
+ for (const updatePathInfo of updatePathInfos) {
22
+ if (!FsUtil.exists(updatePathInfo.source)) {
23
+ logger.warn(`소스경로를 찾을 수 없어 무시됩니다(${updatePathInfo.source})`);
24
+ return;
25
+ }
26
+
27
+ // 소스경로에서 대상경로로 파일 복사
28
+ await FsUtil.copyAsync(updatePathInfo.source, updatePathInfo.target, (src) => {
29
+ return !src.includes("node_modules") && !src.endsWith("package.json");
30
+ });
31
+ }
32
+ logger.info("로컬 라이브러리 업데이트 완료");
33
+ }
34
+
35
+ public static async watchAsync(opt: {
36
+ confFileRelPath: string;
37
+ optNames: string[];
38
+ }): Promise<void> {
39
+ const logger = Logger.get(["simplysm", "sd-cli", "SdCliLocalUpdate", "watchAsync"]);
40
+
41
+ logger.debug("프로젝트 설정 가져오기...");
42
+ const projConf = (await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)).default(true, opt.optNames) as ISdCliConfig;
43
+ if (!projConf.localUpdates) return;
44
+
45
+ logger.debug("로컬 업데이트 구성...");
46
+ const updatePathInfos = await this._getUpdatePathInfosAsync(projConf.localUpdates);
47
+
48
+ const watchPaths = (await updatePathInfos.mapManyAsync(async (item) => await this._getWatchPathsAsync(item.source))).distinct();
49
+
50
+ const watcher = SdFsWatcher.watch(watchPaths);
51
+ watcher.onChange({delay: 1000}, async (changedInfos) => {
52
+ const changeFilePaths = changedInfos.filter((item) => ["add", "change", "unlink"].includes(item.event)).map((item) => item.path);
53
+ if (changeFilePaths.length === 0) return;
54
+
55
+ logger.log("로컬 라이브러리 변경감지...");
56
+ for (const changedFilePath of changeFilePaths) {
57
+ if (!FsUtil.exists(changedFilePath)) continue;
58
+
59
+ for (const updatePathInfo of updatePathInfos) {
60
+ if (!PathUtil.isChildPath(changedFilePath, updatePathInfo.source)) continue;
61
+
62
+ const sourceRelPath = path.relative(updatePathInfo.source, changedFilePath);
63
+
64
+ const targetFilePath = path.resolve(updatePathInfo.target, sourceRelPath);
65
+
66
+ logger.debug(`변경파일감지(복사): ${changedFilePath} => ${targetFilePath}`);
67
+ await FsUtil.copyAsync(changedFilePath, targetFilePath);
68
+ }
69
+ }
70
+
71
+ const watchWatchPaths = (await updatePathInfos.mapManyAsync(async (item) => await this._getWatchPathsAsync(item.source))).distinct();
72
+ watcher.add(watchWatchPaths);
73
+
74
+ logger.info("로컬 라이브러리 복사 완료");
75
+ });
76
+ }
77
+
78
+ private static async _getUpdatePathInfosAsync(record: Record<string, string>): Promise<IUpdatePathInfo[]> {
79
+ const result: IUpdatePathInfo[] = [];
80
+ for (const pkgGlobPath of Object.keys(record)) {
81
+ // "node_modules'에서 로컬업데이트 설정에 맞는 패키지를 "glob"하여 대상 패키지경로 목록 가져오기
82
+ const targetPaths = [
83
+ ...await FsUtil.globAsync(path.resolve(process.cwd(), "node_modules", pkgGlobPath)),
84
+ ...await FsUtil.globAsync(path.resolve(process.cwd(), "packages", "*", "node_modules", pkgGlobPath))
85
+ ];
86
+
87
+ result.push(
88
+ ...targetPaths
89
+ .map((targetPath) => {
90
+ // 대상의 명칭 추출
91
+ const regexpText = pkgGlobPath.replace(/[\\/.*]/g, (item) => (
92
+ item === "/" ? "[\\\\\\/]"
93
+ : item === "." ? "\\."
94
+ : item === "*" ? "(.*)"
95
+ : item
96
+ ));
97
+ const targetNameMatch = new RegExp(regexpText).exec(targetPath);
98
+ if (!targetNameMatch || typeof targetNameMatch[1] === "undefined") return undefined;
99
+ const targetName = targetNameMatch[1];
100
+
101
+ // 가져올 소스 경로 추출
102
+ const sourcePath = path.resolve(record[pkgGlobPath].replace(/\*/g, targetName));
103
+ return {source: sourcePath, target: targetPath};
104
+ })
105
+ .filterExists()
106
+ );
107
+ }
108
+
109
+ return result;
110
+ }
111
+
112
+ private static async _getWatchPathsAsync(sourcePath: string): Promise<string[]> {
113
+ return await FsUtil.globAsync(path.resolve(sourcePath, "**"), {
114
+ ignore: [
115
+ "**/node_modules/**",
116
+ "**/package.json"
117
+ ]
118
+ });
119
+ }
120
+ }
121
+
122
+ interface IUpdatePathInfo {
123
+ source: string;
124
+ target: string;
125
+ }