win_webview2 1.0.10 → 1.0.13

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.
@@ -1,185 +1,182 @@
1
- // @ts-check
2
-
3
- /** @typedef {import("./ww2_builder_type").ConfigWW2} ConfigWW2 */
4
-
5
-
6
- import fs from 'fs'
7
- import sharp from "sharp"
8
- import path from "path";
9
- import { logPrint } from "./ww2_builder_log.mjs";
10
- import { fileURLToPath } from 'url';
11
- import rcedit from "rcedit";
12
- import sharpsToIco from "sharp-ico"
13
-
14
-
15
- const jsonConfigFilePath = "./win_webview2.json";
16
-
17
- export class WW2Deploy {
18
-
19
- /** @type {ConfigWW2 | null} */
20
-
21
- configObjec = null;
22
-
23
- /** @type {"x64" | "Win32" } */
24
- platform = "Win32";
25
-
26
- /** @type {string | null} */
27
- outputExeFile = null;
28
-
29
-
30
-
31
- async makeDistFolder() {
32
-
33
- if (this.configObjec == null) return;
34
- let config = this.configObjec;
35
-
36
- let folderDist = config.outdir;
37
-
38
- if (!fs.existsSync(folderDist)) {
39
- await fs.promises.mkdir(folderDist);
40
- }
41
-
42
- let libFolder = path.join(folderDist, "lib");
43
- if (!fs.existsSync(libFolder)) {
44
- await fs.promises.mkdir(libFolder);
45
- }
46
- }
47
-
48
- async buildIcon() {
49
- if (this.configObjec == null) return;
50
-
51
- let config = this.configObjec;
52
-
53
- let iconPath = config.icon_path;
54
- if (!fs.existsSync(iconPath)) {
55
-
56
- logPrint("icon notfound");
57
- return;
58
-
59
- }
60
-
61
- let outputIcon = path.join(config.outdir, "icon.ico");
62
-
63
- const sizes = [16, 32, 48, 256]; // Ukuran standar untuk rcedit
64
- const images = await Promise.all(sizes.map(size =>
65
- sharp(iconPath)
66
- .resize(size, size)
67
- .toFormat('png')
68
- ));
69
-
70
-
71
- await sharpsToIco.sharpsToIco(images, outputIcon);
72
-
73
- console.log('✅ Berhasil membuat icon.ico yang valid untuk rcedit!');
74
-
75
-
76
- }
77
-
78
- async copyExe() {
79
- let currentDirMjs = fileURLToPath(import.meta.url);
80
- let currentDir = path.dirname(currentDirMjs);
81
-
82
- if (this.configObjec == null) return;
83
- let config = this.configObjec;
84
-
85
- logPrint("COpy webview2 exe file");
86
- logPrint(currentDir);
87
-
88
- let inputFileExe = path.join(currentDir, "win_lib", this.platform, "CmdWebview2.exe");
89
-
90
- let outFileExe = path.join(config.outdir, config.appname + ".exe");
91
- this.outputExeFile = inputFileExe;
92
- await fs.promises.copyFile(inputFileExe, outFileExe);
93
-
94
- let inputFileDll = path.join(currentDir, "win_lib", this.platform, "WebView2Loader.dll");
95
- let outFileDll = path.join(config.outdir, "WebView2Loader.dll");
96
- await fs.promises.copyFile(inputFileDll, outFileDll);
97
-
98
- await (async () => {
99
- let inputFileDll = jsonConfigFilePath;
100
- let outFileDll = path.join(config.outdir, "win_webview2.json");
101
- await fs.promises.copyFile(inputFileDll, outFileDll);
102
-
103
- })();
104
-
105
-
106
-
107
- logPrint("copy file success");
108
- }
109
-
110
- async editIcon() {
111
- if (this.outputExeFile == null) return;
112
- if (this.configObjec == null) return;
113
-
114
- let object = this.configObjec;
115
-
116
-
117
- let iconPath = path.join(object.outdir, "icon.ico");
118
- iconPath = path.resolve(iconPath);
119
-
120
- await rcedit(this.outputExeFile, {
121
- icon: iconPath,
122
- });
123
- }
124
-
125
- async readConfig() {
126
- let str = await fs.promises.readFile(jsonConfigFilePath);
127
- let jsonObj = JSON.parse(str.toString());
128
-
129
- this.configObjec = jsonObj;
130
- }
131
-
132
- async copyNodeExe() {
133
- if (this.configObjec == null) return;
134
- let obj = this.configObjec;
135
-
136
- let inputNodeExe = process.execPath;
137
- let outNodeExe = path.join(obj.outdir, "lib", "node.exe");
138
- await fs.promises.copyFile(inputNodeExe, outNodeExe);
139
- }
140
-
141
- async createIndexConf() {
142
- if (this.configObjec == null) return;
143
- let obj = this.configObjec;
144
-
145
- let oututFileConf = path.join(obj.outdir, "index.bat");
146
-
147
- let configCtn = `.\\\\lib\\\\node.exe ./${obj.entry_point}`
148
- await fs.promises.writeFile(oututFileConf, configCtn);
149
- }
150
-
151
- static async initWW2() {
152
- /** @type {ConfigWW2} */
153
-
154
- let objConfig = {
155
- entry_point: "app.js",
156
- appname: "openweb",
157
- icon_path: "./icon.png",
158
- outdir: "./dist"
159
- }
160
-
161
- let objstr = JSON.stringify(objConfig, null, 2);
162
- if(fs.existsSync(jsonConfigFilePath)){
163
- logPrint("file config is exits");
164
- return;
165
- }
166
-
167
- await fs.promises.writeFile(jsonConfigFilePath, objstr);
168
- }
169
-
170
-
171
-
172
- static async startDeploy() {
173
- logPrint("Start Deploy win_webview2");
174
- let c = new WW2Deploy();
175
-
176
- await c.readConfig();
177
- await c.makeDistFolder();
178
- await c.buildIcon();
179
- await c.copyExe();
180
- await c.editIcon();
181
- await c.copyNodeExe();
182
- await c.createIndexConf();
183
-
184
- }
1
+
2
+
3
+ import fs from "fs"
4
+ import fspromise from "fs/promises"
5
+ import sharp from "sharp"
6
+ import path from "path";
7
+ import { fileURLToPath } from 'url';
8
+ import rcedit from "rcedit";
9
+ import sharpsToIco from "sharp-ico"
10
+ import { ConfigWW2 } from './builder_tp';
11
+ import { logPrint } from '../logprint';
12
+ import { copyDir } from './build_copyDir';
13
+
14
+
15
+ const jsonConfigFilePath = "./win_webview2.json";
16
+
17
+ export class WW2Deploy {
18
+
19
+ configObjec? : ConfigWW2;
20
+ outputExeFile? :string;
21
+
22
+
23
+
24
+ async makeDistFolder() {
25
+
26
+ if (this.configObjec == null) return;
27
+ let config = this.configObjec;
28
+
29
+ let folderDist = config.outdir;
30
+
31
+ if (!fs.existsSync(folderDist)) {
32
+ await fs.promises.mkdir(folderDist);
33
+ }
34
+
35
+ let libFolder = path.join(folderDist, "lib");
36
+ if (!fs.existsSync(libFolder)) {
37
+ await fs.promises.mkdir(libFolder);
38
+ }
39
+ }
40
+
41
+ async buildIcon() {
42
+ if (this.configObjec == null) return;
43
+
44
+ let config = this.configObjec;
45
+
46
+ let iconPath = config.icon_path;
47
+ if (!fs.existsSync(iconPath)) {
48
+
49
+ logPrint("icon notfound");
50
+ return;
51
+
52
+ }
53
+
54
+ let outputIcon = path.join(config.outdir, "icon.ico");
55
+
56
+ const sizes = [16, 32, 48, 256]; // Ukuran standar untuk rcedit
57
+ const images = await Promise.all(sizes.map(size =>
58
+ sharp(iconPath)
59
+ .resize(size, size)
60
+ .toFormat('png')
61
+ ));
62
+
63
+
64
+ await sharpsToIco.sharpsToIco(images, outputIcon);
65
+
66
+ console.log('✅ Berhasil membuat icon.ico yang valid untuk rcedit!');
67
+
68
+
69
+ }
70
+
71
+ async copyExe() {
72
+ let currentDir = path.join(__dirname,"../../");
73
+
74
+ if (this.configObjec == null) return;
75
+ let config = this.configObjec;
76
+ let platform = config.platform;
77
+
78
+
79
+
80
+
81
+ let inputDir = path.join(
82
+ currentDir, "win_lib",
83
+ platform);
84
+
85
+
86
+
87
+ this.outputExeFile = path.join(config.outdir, config.appname + ".exe");
88
+ await copyDir(inputDir, config.outdir);
89
+ await fspromise.rename(
90
+ path.join(config.outdir,"CmdWebview2.exe"),
91
+ this.outputExeFile
92
+
93
+ );
94
+
95
+ await (async () => {
96
+ let inputFileDll = jsonConfigFilePath;
97
+ let outFileDll = path.join(config.outdir, "win_webview2.json");
98
+ await fs.promises.copyFile(inputFileDll, outFileDll);
99
+
100
+ })();
101
+
102
+
103
+
104
+ logPrint("copy file success");
105
+ }
106
+
107
+ async editIcon() {
108
+ if (this.outputExeFile == null) return;
109
+ if (this.configObjec == null) return;
110
+
111
+ let object = this.configObjec;
112
+
113
+
114
+ let iconPath = path.join(object.outdir, "icon.ico");
115
+ iconPath = path.resolve(iconPath);
116
+
117
+ await rcedit(this.outputExeFile, {
118
+ icon: iconPath,
119
+ });
120
+ }
121
+
122
+ async readConfig() {
123
+ let str = await fs.promises.readFile(jsonConfigFilePath);
124
+ let jsonObj = JSON.parse(str.toString());
125
+
126
+ this.configObjec = jsonObj;
127
+ }
128
+
129
+ async copyNodeExe() {
130
+ if (this.configObjec == null) return;
131
+ let obj = this.configObjec;
132
+
133
+ let inputNodeExe = process.execPath;
134
+ let outNodeExe = path.join(obj.outdir, "lib", "node.exe");
135
+ await fs.promises.copyFile(inputNodeExe, outNodeExe);
136
+ }
137
+
138
+ async createIndexConf() {
139
+ if (this.configObjec == null) return;
140
+ let obj = this.configObjec;
141
+
142
+ let oututFileConf = path.join(obj.outdir, "index.bat");
143
+
144
+ let configCtn = `.\\\\lib\\\\node.exe ./${obj.entry_point}`
145
+ await fs.promises.writeFile(oututFileConf, configCtn);
146
+ }
147
+
148
+ static async initWW2() {
149
+
150
+ let objConfig : ConfigWW2 = {
151
+ entry_point: "app.js",
152
+ appname: "openweb",
153
+ icon_path: "./icon.png",
154
+ outdir: "./dist",
155
+ platform : 'Win32'
156
+ }
157
+
158
+ let objstr = JSON.stringify(objConfig, null, 2);
159
+ if(fs.existsSync(jsonConfigFilePath)){
160
+ logPrint("file config is exits");
161
+ return;
162
+ }
163
+
164
+ await fs.promises.writeFile(jsonConfigFilePath, objstr);
165
+ }
166
+
167
+
168
+
169
+ static async startDeploy() {
170
+ logPrint("Start Deploy win_webview2");
171
+ let c = new WW2Deploy();
172
+
173
+ await c.readConfig();
174
+ await c.makeDistFolder();
175
+ await c.buildIcon();
176
+ await c.copyExe();
177
+ await c.editIcon();
178
+ await c.copyNodeExe();
179
+ await c.createIndexConf();
180
+
181
+ }
185
182
  }