@simplysm/sd-cli 10.0.40 → 10.0.45

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 (63) hide show
  1. package/dist/build-tools/SdCliIndexFileGenerator.d.ts +5 -0
  2. package/dist/build-tools/SdCliIndexFileGenerator.js +51 -0
  3. package/dist/build-tools/SdCliIndexFileGenerator.js.map +1 -0
  4. package/dist/{SdLinter.d.ts → build-tools/SdLinter.d.ts} +1 -1
  5. package/dist/{SdLinter.js → build-tools/SdLinter.js} +2 -1
  6. package/dist/build-tools/SdLinter.js.map +1 -0
  7. package/dist/{SdTsIncrementalBuilder.d.ts → build-tools/SdTsIncrementalBuilder.d.ts} +1 -1
  8. package/dist/{SdTsIncrementalBuilder.js → build-tools/SdTsIncrementalBuilder.js} +1 -1
  9. package/dist/build-tools/SdTsIncrementalBuilder.js.map +1 -0
  10. package/dist/builders/SdCliClientBuilder.js +84 -8
  11. package/dist/builders/SdCliClientBuilder.js.map +1 -1
  12. package/dist/builders/SdCliJsLibLinter.js +1 -1
  13. package/dist/builders/SdCliJsLibLinter.js.map +1 -1
  14. package/dist/builders/SdCliServerBuilder.js +22 -5
  15. package/dist/builders/SdCliServerBuilder.js.map +1 -1
  16. package/dist/builders/SdCliTsLibBuilder.js +6 -5
  17. package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
  18. package/dist/commons.d.ts +18 -7
  19. package/dist/entry/SdCliElectron.d.ts +5 -0
  20. package/dist/entry/SdCliElectron.js +59 -1
  21. package/dist/entry/SdCliElectron.js.map +1 -1
  22. package/dist/entry/SdCliProject.js +75 -19
  23. package/dist/entry/SdCliProject.js.map +1 -1
  24. package/dist/index.d.ts +19 -1
  25. package/dist/index.js +19 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/sd-cli.js +26 -21
  28. package/dist/sd-cli.js.map +1 -1
  29. package/dist/utils/SdCliBuildResultUtil.js +3 -2
  30. package/dist/utils/SdCliBuildResultUtil.js.map +1 -1
  31. package/dist/utils/SdCliViteElectronMainPlugin.js +24 -7
  32. package/dist/utils/SdCliViteElectronMainPlugin.js.map +1 -1
  33. package/dist/utils/SdCliViteExternalPlugin.d.ts +1 -0
  34. package/dist/utils/SdCliViteExternalPlugin.js +9 -6
  35. package/dist/utils/SdCliViteExternalPlugin.js.map +1 -1
  36. package/dist/utils/SdCliViteReactSwcPlugin.js +2 -4
  37. package/dist/utils/SdCliViteReactSwcPlugin.js.map +1 -1
  38. package/dist/utils/sdCliTsDefineTransformer.js.map +1 -1
  39. package/package.json +12 -11
  40. package/src/build-tools/SdCliIndexFileGenerator.ts +62 -0
  41. package/src/{SdLinter.ts → build-tools/SdLinter.ts} +3 -2
  42. package/src/{SdTsIncrementalBuilder.ts → build-tools/SdTsIncrementalBuilder.ts} +2 -2
  43. package/src/builders/SdCliClientBuilder.ts +298 -203
  44. package/src/builders/SdCliJsLibLinter.ts +1 -1
  45. package/src/builders/SdCliServerBuilder.ts +325 -307
  46. package/src/builders/SdCliTsLibBuilder.ts +135 -133
  47. package/src/commons.ts +73 -61
  48. package/src/entry/SdCliElectron.ts +124 -48
  49. package/src/entry/SdCliProject.ts +524 -455
  50. package/src/index.ts +19 -1
  51. package/src/sd-cli.ts +190 -179
  52. package/src/utils/SdCliBuildResultUtil.ts +4 -3
  53. package/src/utils/SdCliViteElectronMainPlugin.ts +25 -7
  54. package/src/utils/SdCliViteExternalPlugin.ts +12 -7
  55. package/src/utils/SdCliViteReactSwcPlugin.ts +6 -8
  56. package/src/utils/sdCliTsDefineTransformer.ts +23 -23
  57. package/tsconfig.json +7 -1
  58. package/dist/SdLinter.js.map +0 -1
  59. package/dist/SdTsIncrementalBuilder.js.map +0 -1
  60. package/dist/entry/SdCliLocalUpdate.d.ts +0 -12
  61. package/dist/entry/SdCliLocalUpdate.js +0 -94
  62. package/dist/entry/SdCliLocalUpdate.js.map +0 -1
  63. package/src/entry/SdCliLocalUpdate.ts +0 -125
@@ -3,164 +3,166 @@ import path from "path";
3
3
  import {ISdCliBuilderResult, ISdCliLibPackageConfig, ISdCliPackageBuildResult} from "../commons";
4
4
  import {EventEmitter} from "events";
5
5
  import {FunctionQueue, Uuid} from "@simplysm/sd-core-common";
6
- import {SdTsIncrementalBuilder} from "../SdTsIncrementalBuilder";
7
- import {SdLinter} from "../SdLinter";
6
+ import {SdTsIncrementalBuilder} from "../build-tools/SdTsIncrementalBuilder";
7
+ import {SdLinter} from "../build-tools/SdLinter";
8
8
  import {pathToFileURL} from "url";
9
9
  import less from "less";
10
10
  import ts from "typescript";
11
11
  import transformKeys from "ts-transformer-keys/transformer";
12
12
 
13
13
  export class SdCliTsLibBuilder extends EventEmitter {
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();
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();
20
49
  }
21
50
 
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
- }
51
+ this._debug("COPY...");
52
+ await FsUtil.copyAsync(
53
+ path.resolve(this._pkgPath, "src/assets"),
54
+ path.resolve(this._pkgPath, "dist/assets")
55
+ );
28
56
 
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
57
 
36
- this._debug("dist 초기화...");
37
- await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
58
+ this._debug(`빌드 완료`);
59
+ return {
60
+ affectedFilePaths: buildResult.affectedFilePaths,
61
+ buildResults: [...buildResult.results, ...lintResults, ...styleResult ? [styleResult] : []]
62
+ };
63
+ }
38
64
 
39
- this._debug("BUILD...");
40
- const buildResult = await sdTsProgram.buildAsync();
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
+ }));
41
72
 
42
- this._debug("LINT...");
43
- const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(buildResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
73
+ this._debug("dist 초기화...");
74
+ await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
44
75
 
45
- let styleResult: ISdCliPackageBuildResult | undefined;
46
- if (this._pkgConf.style !== undefined) {
47
- this._debug("STYLE...");
48
- styleResult = await this._genStyleAsync();
49
- }
76
+ this.emit("change");
50
77
 
51
- this._debug("COPY...");
52
- await FsUtil.copyAsync(
53
- path.resolve(this._pkgPath, "src/assets"),
54
- path.resolve(this._pkgPath, "dist/assets")
55
- );
78
+ this._debug("BUILD...");
79
+ const buildResult = await sdTsProgram.buildAsync();
56
80
 
81
+ this._debug("LINT...");
82
+ const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(buildResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
57
83
 
58
- this._debug(`빌드 완료`);
59
- return {
60
- affectedFilePaths: buildResult.affectedFilePaths,
61
- buildResults: [...buildResult.results, ...lintResults, ...styleResult ? [styleResult] : []]
62
- };
84
+ let styleResult: ISdCliPackageBuildResult | undefined;
85
+ if (this._pkgConf.style !== undefined) {
86
+ this._debug("STYLE...");
87
+ styleResult = await this._genStyleAsync();
63
88
  }
64
89
 
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) {
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] : []]
100
+ });
101
+
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!))) {
86
123
  this._debug("STYLE...");
87
- styleResult = await this._genStyleAsync();
88
- }
124
+ watchStyleResult = await this._genStyleAsync();
125
+ }
89
126
 
90
- this._debug("COPY...");
91
- await FsUtil.copyAsync(
127
+ this._debug("COPY...");
128
+ await FsUtil.copyAsync(
92
129
  path.resolve(this._pkgPath, "src/assets"),
93
130
  path.resolve(this._pkgPath, "dist/assets")
94
- );
131
+ );
95
132
 
96
- this._debug(`빌드 완료`);
97
- this.emit("complete", {
98
- affectedFilePaths: buildResult.affectedFilePaths,
99
- buildResults: [...buildResult.results, ...lintResults, ...styleResult ? [styleResult] : []]
133
+ this._debug(`빌드 완료`);
134
+ this.emit("complete", {
135
+ affectedFilePaths: watchBuildResult.affectedFilePaths,
136
+ buildResults: [...watchBuildResult.results, ...watchLintResults, ...watchStyleResult ? [watchStyleResult] : []]
137
+ });
100
138
  });
101
-
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
- });
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 as (string | Function)[]).map((item) => typeof item === "function" ? item({}) : item).join("");
151
+ const styleRendered = await less.render(styleText);
152
+ await FsUtil.writeFileAsync(path.resolve(this._pkgPath, "style.css"), styleRendered.css);
140
153
  }
141
-
142
- private _debug(msg: string): void {
143
- this._logger.debug(`[${path.basename(this._pkgPath)}] ${msg}`);
154
+ catch (err) {
155
+ return {
156
+ code: undefined,
157
+ message: err.message,
158
+ severity: "error",
159
+ char: undefined,
160
+ line: undefined,
161
+ filePath: srcFilePath,
162
+ type: "style"
163
+ };
144
164
  }
145
165
 
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
- }
166
+ return;
167
+ }
166
168
  }
package/src/commons.ts CHANGED
@@ -1,96 +1,108 @@
1
1
  export interface INpmConfig {
2
- name: string;
3
- description?: string;
4
- version: string;
5
- workspaces?: string[];
6
-
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
- }>;
14
-
15
- resolutions?: Record<string, string>;
2
+ name: string;
3
+ description?: string;
4
+ version: string;
5
+ workspaces?: string[];
6
+
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
+ }>;
14
+
15
+ resolutions?: Record<string, string>;
16
16
  }
17
17
 
18
18
  export interface ISdCliBuildClusterReqMessage {
19
- cmd: "watch" | "build";
20
- pkgPath: string;
21
- pkgConf: TSdCliPackageConfig;
22
- builderKey?: "web" | "electron";
23
- withLint: boolean;
19
+ cmd: "watch" | "build";
20
+ pkgPath: string;
21
+ pkgConf: TSdCliPackageConfig;
22
+ builderKey?: "web" | "electron";
23
+ withLint: boolean;
24
24
  }
25
25
 
26
26
  export interface ISdCliBuildClusterResMessage {
27
- req: ISdCliBuildClusterReqMessage;
28
- type: "change" | "complete" | "ready";
29
- result?: ISdCliBuilderResult;
27
+ req: ISdCliBuildClusterReqMessage;
28
+ type: "change" | "complete" | "ready";
29
+ result?: ISdCliBuilderResult;
30
30
  }
31
31
 
32
32
  export interface ISdCliBuilderResult {
33
- port?: number;
34
- affectedFilePaths: string[];
35
- buildResults: ISdCliPackageBuildResult[];
33
+ port?: number;
34
+ affectedFilePaths: string[];
35
+ buildResults: ISdCliPackageBuildResult[];
36
36
  }
37
37
 
38
38
  export interface ISdCliPackageBuildResult {
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;
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;
45
+ type: "build" | "lint" | "style" | undefined;
45
46
  }
46
47
 
47
- export interface ISdCliConfig {
48
- packages: Record<string, TSdCliPackageConfig | undefined>;
49
- localUpdates?: Record<string, string>;
50
- }
51
- export type TSdCliConfigFn = (isDev: boolean, opts?: string[]) => ISdCliConfig;
48
+ export type TSdCliConfig = Record<string, TSdCliPackageConfig | undefined>;
49
+ export type TSdCliConfigFn = (isDev: boolean, opts?: string[]) => TSdCliConfig;
52
50
 
53
51
  export type TSdCliPackageConfig = ISdCliLibPackageConfig | ISdCliServerPackageConfig | ISdCliClientPackageConfig;
54
52
 
55
53
  export interface ISdCliLibPackageConfig {
56
- type: "library";
57
- style?: string;
58
- publish?: "npm";
54
+ type: "library";
55
+ style?: string;
56
+ publish?: "npm";
57
+ polyfills?: string[];
59
58
  }
60
59
 
61
60
  export interface ISdCliServerPackageConfig {
62
- type: "server";
63
- externals?: string[];
64
- publish?: ISdCliLocalDirectoryPublishConfig;
65
- configs?: Record<string, any>;
61
+ type: "server";
62
+ externals?: string[];
63
+ publish?: ISdCliLocalDirectoryPublishConfig | ISdCliFtpPublishConfig;
64
+ configs?: Record<string, any>;
66
65
  }
67
66
 
68
67
  export interface ISdCliClientPackageConfig {
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
- }
68
+ type: "client";
69
+ server?: string;
70
+ publish?: ISdCliLocalDirectoryPublishConfig | ISdCliFtpPublishConfig;
71
+ env?: Record<string, string>;
72
+ configs?: Record<string, any>;
73
+
74
+ builder?: {
75
+ web?: ISdCliClientBuilderWebConfig;
76
+ electron?: ISdCliClientBuilderElectronConfig;
77
+ }
79
78
  }
80
79
 
81
80
  export interface ISdCliLocalDirectoryPublishConfig {
82
- type: "local-directory";
83
- path: string;
81
+ type: "local-directory";
82
+ path: string;
83
+ }
84
+
85
+ export interface ISdCliFtpPublishConfig {
86
+ type: "ftp" | "ftps" | "sftp";
87
+ host: string;
88
+ port?: number;
89
+ path?: string;
90
+ user?: string;
91
+ pass?: string;
84
92
  }
85
93
 
86
94
  export interface ISdCliClientBuilderElectronConfig {
87
- appId: string;
88
- installerIcon?: string;
89
- postInstallScript?: string;
90
- devServerPort?: number;
91
- reinstallDependencies?: string[];
95
+ appId: string;
96
+ installerIcon?: string;
97
+ postInstallScript?: string;
98
+ devServerHost?: string;
99
+ devServerPort?: number;
100
+ reinstallDependencies?: string[];
101
+ env?: Record<string, string>;
92
102
  }
93
103
 
94
104
  export interface ISdCliClientBuilderWebConfig {
95
- devServerPort?: number;
105
+ devServerHost?: string;
106
+ devServerPort?: number;
107
+ env?: Record<string, string>;
96
108
  }
@@ -1,55 +1,131 @@
1
1
  import {FsUtil, Logger, SdProcess} from "@simplysm/sd-core-node";
2
2
  import {pathToFileURL} from "url";
3
3
  import path from "path";
4
- import {INpmConfig, ISdCliConfig} from "../commons";
4
+ import {INpmConfig, TSdCliConfig} from "../commons";
5
+ import electronBuilder from "electron-builder";
5
6
 
6
7
  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);
8
+ public static async runAsync(opt: {
9
+ confFileRelPath: string;
10
+ optNames: string[];
11
+ pkgName: string;
12
+ }): Promise<void> {
13
+ const logger = Logger.get(["simplysm", "sd-cli", "SdCliElectron", "runAsync"]);
14
+
15
+ const pkgPath = path.resolve(process.cwd(), `packages/${opt.pkgName}`);
16
+ const electronPath = path.resolve(pkgPath, ".cache/dev/electron/src");
17
+
18
+ logger.log("설정 가져오기...");
19
+ const projConf = (await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)).default(true, opt.optNames) as TSdCliConfig;
20
+ const pkgConf = projConf[opt.pkgName];
21
+ if (pkgConf?.type !== "client" || pkgConf.builder?.electron === undefined) {
22
+ throw new Error();
23
+ }
24
+
25
+ logger.log("package.json 파일 쓰기...");
26
+ const npmConfig = (await FsUtil.readJsonAsync(path.resolve(pkgPath, `package.json`))) as INpmConfig;
27
+
28
+ const externalPkgNames = pkgConf.builder.electron.reinstallDependencies ?? [];
29
+
30
+ await FsUtil.writeJsonAsync(path.resolve(electronPath, `package.json`), {
31
+ name: npmConfig.name,
32
+ version: npmConfig.version,
33
+ description: npmConfig.description,
34
+ main: "electron-main.js",
35
+ ...pkgConf.builder.electron.postInstallScript !== undefined ? {
36
+ scripts: {
37
+ "postinstall": pkgConf.builder.electron.postInstallScript
38
+ },
39
+ } : {},
40
+ dependencies: externalPkgNames.toObject((item) => item, (item) => npmConfig.dependencies![item])
41
+ });
42
+
43
+ logger.log("npm install...");
44
+ await SdProcess.spawnAsync(`npm install`, {cwd: electronPath}, true);
45
+
46
+ for (const externalPkgName of externalPkgNames) {
47
+ if (FsUtil.exists(path.resolve(electronPath, "node_modules", externalPkgName, "binding.gyp"))) {
48
+ logger.log(`electron rebuild (${externalPkgName})...`);
49
+ await SdProcess.spawnAsync(`electron-rebuild -m ./node_modules/${externalPkgName}`, {cwd: electronPath}, true);
50
+ }
51
+ }
52
+
53
+ logger.log("electron...");
54
+ await SdProcess.spawnAsync(`electron .`, {cwd: electronPath}, true);
55
+ }
56
+
57
+ public static async buildForDevAsync(opt: {
58
+ confFileRelPath: string;
59
+ optNames: string[];
60
+ pkgName: string;
61
+ }): Promise<void> {
62
+ const logger = Logger.get(["simplysm", "sd-cli", "SdCliElectron", "buildForDevAsync"]);
63
+
64
+ const pkgPath = path.resolve(process.cwd(), `packages/${opt.pkgName}`);
65
+ const electronPath = path.resolve(pkgPath, ".cache/dev/electron/src");
66
+ const electronDistPath = path.resolve(pkgPath, ".cache/dev/electron/dist");
67
+
68
+ logger.log("설정 가져오기...");
69
+ const projConf = (await import(pathToFileURL(path.resolve(process.cwd(), opt.confFileRelPath)).href)).default(true, opt.optNames) as TSdCliConfig;
70
+ const pkgConf = projConf[opt.pkgName];
71
+ if (pkgConf?.type !== "client" || pkgConf.builder?.electron === undefined) {
72
+ throw new Error();
54
73
  }
74
+
75
+ logger.log("package.json 파일 쓰기...");
76
+ const npmConfig = (await FsUtil.readJsonAsync(path.resolve(pkgPath, `package.json`))) as INpmConfig;
77
+
78
+ const externalPkgNames = pkgConf.builder.electron.reinstallDependencies ?? [];
79
+
80
+ await FsUtil.writeJsonAsync(path.resolve(electronPath, `package.json`), {
81
+ name: npmConfig.name,
82
+ version: npmConfig.version,
83
+ description: npmConfig.description,
84
+ main: "electron-main.js",
85
+ ...pkgConf.builder.electron.postInstallScript !== undefined ? {
86
+ scripts: {
87
+ "postinstall": pkgConf.builder.electron.postInstallScript
88
+ },
89
+ } : {},
90
+ dependencies: externalPkgNames.toObject((item) => item, (item) => npmConfig.dependencies![item])
91
+ });
92
+
93
+ logger.log("npm install...");
94
+ await SdProcess.spawnAsync(`npm install`, {cwd: electronPath}, true);
95
+
96
+ for (const externalPkgName of externalPkgNames) {
97
+ if (FsUtil.exists(path.resolve(electronPath, "node_modules", externalPkgName, "binding.gyp"))) {
98
+ logger.log(`electron rebuild (${externalPkgName})...`);
99
+ await SdProcess.spawnAsync(`electron-rebuild -m ./node_modules/${externalPkgName}`, {cwd: electronPath}, true);
100
+ }
101
+ }
102
+
103
+ logger.log("build...");
104
+
105
+ await electronBuilder.build({
106
+ targets: electronBuilder.Platform.WINDOWS.createTarget(),
107
+ config: {
108
+ appId: pkgConf.builder.electron.appId,
109
+ productName: npmConfig.description,
110
+ // asar: false,
111
+ win: {
112
+ target: "nsis"
113
+ },
114
+ nsis: {},
115
+ directories: {
116
+ app: electronPath,
117
+ output: electronDistPath
118
+ },
119
+ ...pkgConf.builder.electron.installerIcon !== undefined ? {
120
+ icon: path.resolve(pkgPath, "src", pkgConf.builder.electron.installerIcon)
121
+ } : {},
122
+ removePackageScripts: false
123
+ }
124
+ });
125
+
126
+ await FsUtil.copyAsync(
127
+ path.resolve(electronDistPath, `${npmConfig.description} Setup ${npmConfig.version}.exe`),
128
+ path.resolve(pkgPath, `dist/electron/${npmConfig.description}-dev.exe`)
129
+ );
130
+ }
55
131
  }