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.
package/package.json CHANGED
@@ -1,15 +1,20 @@
1
1
  {
2
2
  "name": "win_webview2",
3
- "version": "1.0.10",
3
+ "version": "1.0.13",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/nnttoo/win_webview2"
7
7
  },
8
8
  "description": "",
9
- "main": "./winWebview2.mjs",
10
- "types": "./winWebview2.d.ts",
9
+ "main": "./tsDist/tsExport/winwebview2.js",
10
+ "types": "./tsDist/tsExport/winwebview2.d.ts",
11
11
  "bin": {
12
- "win_webview2": "./ww2_builder.mjs"
12
+ "win_webview2": "tsDistRun.js"
13
+ },
14
+ "type": "commonjs",
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "build_watch": "tsc --watch"
13
18
  },
14
19
  "author": "",
15
20
  "license": "ISC",
@@ -17,9 +22,12 @@
17
22
  "prompts": "^2.4.2",
18
23
  "rcedit": "^4.0.1",
19
24
  "sharp": "^0.33.5",
20
- "sharp-ico": "^0.1.5"
25
+ "sharp-ico": "^0.1.5",
26
+ "tsx": "^4.21.0"
21
27
  },
22
28
  "devDependencies": {
23
- "@types/node": "^25.5.0"
29
+ "@types/node": "^25.5.0",
30
+ "@types/prompts": "^2.4.9",
31
+ "typescript": "^6.0.2"
24
32
  }
25
- }
33
+ }
@@ -0,0 +1 @@
1
+ export declare function logPrint(msg: any): void;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logPrint = logPrint;
4
+ function logPrint(msg) {
5
+ console.log(new Date().toLocaleString() + ": ", msg);
6
+ }
@@ -0,0 +1 @@
1
+ export declare function copyDir(source: string, destination: string): Promise<void>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.copyDir = copyDir;
7
+ const fs_1 = require("fs");
8
+ const path_1 = __importDefault(require("path"));
9
+ async function copyDir(source, destination) {
10
+ // pastikan folder tujuan ada
11
+ await fs_1.promises.mkdir(destination, { recursive: true });
12
+ const entries = await fs_1.promises.readdir(source, { withFileTypes: true });
13
+ for (const entry of entries) {
14
+ let srcPath = path_1.default.join(source, entry.name);
15
+ let destPath = path_1.default.join(destination, entry.name);
16
+ if (entry.isDirectory()) {
17
+ // rekursif ke subfolder
18
+ await copyDir(srcPath, destPath);
19
+ }
20
+ else {
21
+ await fs_1.promises.copyFile(srcPath, destPath);
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,7 @@
1
+ export type ConfigWW2 = {
2
+ appname: string;
3
+ icon_path: string;
4
+ entry_point: string;
5
+ outdir: string;
6
+ platform: 'Win32' | 'x64';
7
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export declare function buildForServer(): Promise<void>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.buildForServer = buildForServer;
7
+ const prompts_1 = __importDefault(require("prompts"));
8
+ const ww2_buildercore_1 = require("./ww2_buildercore");
9
+ async function buildForServer() {
10
+ const response = await (0, prompts_1.default)({
11
+ type: 'select',
12
+ name: 'menu',
13
+ message: 'Pilih menu',
14
+ choices: [
15
+ {
16
+ title: 'init_webview2', value: async () => {
17
+ await ww2_buildercore_1.WW2Deploy.initWW2();
18
+ }
19
+ },
20
+ {
21
+ title: 'deploy', value: async () => {
22
+ await ww2_buildercore_1.WW2Deploy.startDeploy();
23
+ }
24
+ },
25
+ ]
26
+ });
27
+ if (response && response.menu) {
28
+ response.menu();
29
+ }
30
+ }
31
+ buildForServer();
@@ -0,0 +1,14 @@
1
+ import { ConfigWW2 } from './builder_tp';
2
+ export declare class WW2Deploy {
3
+ configObjec?: ConfigWW2;
4
+ outputExeFile?: string;
5
+ makeDistFolder(): Promise<void>;
6
+ buildIcon(): Promise<void>;
7
+ copyExe(): Promise<void>;
8
+ editIcon(): Promise<void>;
9
+ readConfig(): Promise<void>;
10
+ copyNodeExe(): Promise<void>;
11
+ createIndexConf(): Promise<void>;
12
+ static initWW2(): Promise<void>;
13
+ static startDeploy(): Promise<void>;
14
+ }
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WW2Deploy = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const promises_1 = __importDefault(require("fs/promises"));
9
+ const sharp_1 = __importDefault(require("sharp"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const rcedit_1 = __importDefault(require("rcedit"));
12
+ const sharp_ico_1 = __importDefault(require("sharp-ico"));
13
+ const logprint_1 = require("../logprint");
14
+ const build_copyDir_1 = require("./build_copyDir");
15
+ const jsonConfigFilePath = "./win_webview2.json";
16
+ class WW2Deploy {
17
+ async makeDistFolder() {
18
+ if (this.configObjec == null)
19
+ return;
20
+ let config = this.configObjec;
21
+ let folderDist = config.outdir;
22
+ if (!fs_1.default.existsSync(folderDist)) {
23
+ await fs_1.default.promises.mkdir(folderDist);
24
+ }
25
+ let libFolder = path_1.default.join(folderDist, "lib");
26
+ if (!fs_1.default.existsSync(libFolder)) {
27
+ await fs_1.default.promises.mkdir(libFolder);
28
+ }
29
+ }
30
+ async buildIcon() {
31
+ if (this.configObjec == null)
32
+ return;
33
+ let config = this.configObjec;
34
+ let iconPath = config.icon_path;
35
+ if (!fs_1.default.existsSync(iconPath)) {
36
+ (0, logprint_1.logPrint)("icon notfound");
37
+ return;
38
+ }
39
+ let outputIcon = path_1.default.join(config.outdir, "icon.ico");
40
+ const sizes = [16, 32, 48, 256]; // Ukuran standar untuk rcedit
41
+ const images = await Promise.all(sizes.map(size => (0, sharp_1.default)(iconPath)
42
+ .resize(size, size)
43
+ .toFormat('png')));
44
+ await sharp_ico_1.default.sharpsToIco(images, outputIcon);
45
+ console.log('✅ Berhasil membuat icon.ico yang valid untuk rcedit!');
46
+ }
47
+ async copyExe() {
48
+ let currentDir = path_1.default.join(__dirname, "../../");
49
+ if (this.configObjec == null)
50
+ return;
51
+ let config = this.configObjec;
52
+ let platform = config.platform;
53
+ let inputDir = path_1.default.join(currentDir, "win_lib", platform);
54
+ this.outputExeFile = path_1.default.join(config.outdir, config.appname + ".exe");
55
+ await (0, build_copyDir_1.copyDir)(inputDir, config.outdir);
56
+ await promises_1.default.rename(path_1.default.join(config.outdir, "CmdWebview2.exe"), this.outputExeFile);
57
+ await (async () => {
58
+ let inputFileDll = jsonConfigFilePath;
59
+ let outFileDll = path_1.default.join(config.outdir, "win_webview2.json");
60
+ await fs_1.default.promises.copyFile(inputFileDll, outFileDll);
61
+ })();
62
+ (0, logprint_1.logPrint)("copy file success");
63
+ }
64
+ async editIcon() {
65
+ if (this.outputExeFile == null)
66
+ return;
67
+ if (this.configObjec == null)
68
+ return;
69
+ let object = this.configObjec;
70
+ let iconPath = path_1.default.join(object.outdir, "icon.ico");
71
+ iconPath = path_1.default.resolve(iconPath);
72
+ await (0, rcedit_1.default)(this.outputExeFile, {
73
+ icon: iconPath,
74
+ });
75
+ }
76
+ async readConfig() {
77
+ let str = await fs_1.default.promises.readFile(jsonConfigFilePath);
78
+ let jsonObj = JSON.parse(str.toString());
79
+ this.configObjec = jsonObj;
80
+ }
81
+ async copyNodeExe() {
82
+ if (this.configObjec == null)
83
+ return;
84
+ let obj = this.configObjec;
85
+ let inputNodeExe = process.execPath;
86
+ let outNodeExe = path_1.default.join(obj.outdir, "lib", "node.exe");
87
+ await fs_1.default.promises.copyFile(inputNodeExe, outNodeExe);
88
+ }
89
+ async createIndexConf() {
90
+ if (this.configObjec == null)
91
+ return;
92
+ let obj = this.configObjec;
93
+ let oututFileConf = path_1.default.join(obj.outdir, "index.bat");
94
+ let configCtn = `.\\\\lib\\\\node.exe ./${obj.entry_point}`;
95
+ await fs_1.default.promises.writeFile(oututFileConf, configCtn);
96
+ }
97
+ static async initWW2() {
98
+ let objConfig = {
99
+ entry_point: "app.js",
100
+ appname: "openweb",
101
+ icon_path: "./icon.png",
102
+ outdir: "./dist",
103
+ platform: 'Win32'
104
+ };
105
+ let objstr = JSON.stringify(objConfig, null, 2);
106
+ if (fs_1.default.existsSync(jsonConfigFilePath)) {
107
+ (0, logprint_1.logPrint)("file config is exits");
108
+ return;
109
+ }
110
+ await fs_1.default.promises.writeFile(jsonConfigFilePath, objstr);
111
+ }
112
+ static async startDeploy() {
113
+ (0, logprint_1.logPrint)("Start Deploy win_webview2");
114
+ let c = new WW2Deploy();
115
+ await c.readConfig();
116
+ await c.makeDistFolder();
117
+ await c.buildIcon();
118
+ await c.copyExe();
119
+ await c.editIcon();
120
+ await c.copyNodeExe();
121
+ await c.createIndexConf();
122
+ }
123
+ }
124
+ exports.WW2Deploy = WW2Deploy;
@@ -0,0 +1,28 @@
1
+ export type OpenWebArg = {
2
+ url: string;
3
+ width: number;
4
+ height: number;
5
+ kiosk: boolean;
6
+ maximize: boolean;
7
+ title: string;
8
+ isDebugMode: boolean;
9
+ winClassName: string;
10
+ };
11
+ export type OpenDialogFileArg = {
12
+ winClassName: string;
13
+ filter: string;
14
+ };
15
+ export type OpenDialogArg = {
16
+ winClassName: string;
17
+ };
18
+ export declare function openWeb(arg: OpenWebArg): Promise<void>;
19
+ export declare function openDialogFile(arg: OpenDialogFileArg): Promise<unknown>;
20
+ export declare function openDialogFolder(arg: OpenDialogArg): Promise<unknown>;
21
+ export declare function controlWindow(arg: {
22
+ winClassName: string;
23
+ controlcmd: "close" | "maximize" | "minimize" | "move" | "resize";
24
+ left: number;
25
+ top: number;
26
+ width: number;
27
+ height: number;
28
+ }): Promise<unknown>;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openWeb = openWeb;
4
+ exports.openDialogFile = openDialogFile;
5
+ exports.openDialogFolder = openDialogFolder;
6
+ exports.controlWindow = controlWindow;
7
+ const node_child_process_1 = require("node:child_process");
8
+ const promises_1 = require("node:fs/promises");
9
+ const jsonConfigFilePath = "./win_webview2.json";
10
+ async function readConfig() {
11
+ let str = await (0, promises_1.readFile)(jsonConfigFilePath);
12
+ let jsonObj = JSON.parse(str.toString());
13
+ return jsonObj;
14
+ }
15
+ async function getExecPath() {
16
+ let jsonConfig = await readConfig();
17
+ let exeFilePath = jsonConfig.appname + ".exe";
18
+ return exeFilePath;
19
+ }
20
+ async function openWeb(arg) {
21
+ let jsonConfig = await readConfig();
22
+ let exeFilePath = jsonConfig.appname + ".exe";
23
+ let arrOpen = [
24
+ "fun=openwebview",
25
+ "wndClassName=" + arg.winClassName,
26
+ "url=" + arg.url,
27
+ "width=" + arg.width,
28
+ "height=" + arg.height,
29
+ //"kiosk=true",
30
+ //"maximize=true",
31
+ "title=auto",
32
+ //"isDebugMode=true"
33
+ ];
34
+ if (arg.maximize) {
35
+ arrOpen.push("maximize=true");
36
+ }
37
+ if (arg.kiosk) {
38
+ arrOpen.push("kiosk=true");
39
+ }
40
+ if (arg.isDebugMode) {
41
+ arrOpen.push("isDebugMode=true");
42
+ }
43
+ (0, node_child_process_1.execFile)(exeFilePath, arrOpen, (err, data) => {
44
+ console.log(err);
45
+ });
46
+ }
47
+ async function openDialogFile(arg) {
48
+ let exeFilePath = await getExecPath();
49
+ return new Promise((r, x) => {
50
+ (0, node_child_process_1.execFile)(exeFilePath, [
51
+ "fun=openFileDialog",
52
+ "wndClassName=" + arg.winClassName,
53
+ "filter=" + arg.filter,
54
+ ], (/** @type {any} */ err, /** @type {string} */ data) => {
55
+ let filepath = "";
56
+ for (let l of data.split("\r\n")) {
57
+ if (l.startsWith("result:")) {
58
+ filepath = l.substring(7, l.length);
59
+ }
60
+ }
61
+ r(filepath);
62
+ });
63
+ });
64
+ }
65
+ async function openDialogFolder(arg) {
66
+ let exeFilePath = await getExecPath();
67
+ return new Promise((r, x) => {
68
+ (0, node_child_process_1.execFile)(exeFilePath, [
69
+ "fun=openFolderDialog",
70
+ "wndClassName=" + arg.winClassName,
71
+ ], (
72
+ /** @type {any} */
73
+ err,
74
+ /** @type {string} */
75
+ data) => {
76
+ let filepath = "";
77
+ for (let l of data.split("\r\n")) {
78
+ if (l.startsWith("result:")) {
79
+ filepath = l.substring(7, l.length);
80
+ }
81
+ }
82
+ r(filepath);
83
+ });
84
+ });
85
+ }
86
+ async function controlWindow(arg) {
87
+ let exeFilePath = await getExecPath();
88
+ return new Promise((r, x) => {
89
+ (0, node_child_process_1.execFile)(exeFilePath, [
90
+ "fun=controlwindow",
91
+ "wndClassName=" + arg.winClassName,
92
+ "controlcmd=" + arg.controlcmd,
93
+ "left=" + arg.left,
94
+ "top=" + arg.top,
95
+ "width=" + arg.width,
96
+ "height=" + arg.height,
97
+ ], (
98
+ /** @type {any} */
99
+ err,
100
+ /** @type {string} */
101
+ data) => {
102
+ r(data);
103
+ });
104
+ });
105
+ }
package/tsDistRun.js ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+
3
+ const path = require("path");
4
+
5
+ const entry = path.resolve(__dirname, "./tsDist/srcBuilder/ww2_build_promp.js");
6
+
7
+ require(entry);
@@ -1,3 +1,3 @@
1
- export function logPrint(msg) {
2
- console.log(new Date().toLocaleString() + ": ", msg);
1
+ export function logPrint(msg : any) {
2
+ console.log(new Date().toLocaleString() + ": ", msg);
3
3
  }
@@ -0,0 +1,32 @@
1
+ import { promises as fs } from "fs";
2
+ import path from "path";
3
+
4
+
5
+
6
+ export async function copyDir(
7
+ source: string,
8
+ destination: string
9
+ ) {
10
+
11
+
12
+
13
+ // pastikan folder tujuan ada
14
+ await fs.mkdir(destination, { recursive: true });
15
+
16
+ const entries = await fs.readdir(source, { withFileTypes: true });
17
+
18
+ for (const entry of entries) {
19
+ let srcPath = path.join(source, entry.name);
20
+ let destPath = path.join(destination, entry.name);
21
+
22
+ if (entry.isDirectory()) {
23
+ // rekursif ke subfolder
24
+ await copyDir(srcPath, destPath);
25
+ } else {
26
+
27
+ await fs.copyFile(srcPath, destPath);
28
+ }
29
+ }
30
+ }
31
+
32
+
@@ -0,0 +1,7 @@
1
+ export type ConfigWW2 = {
2
+ appname: string;
3
+ icon_path: string;
4
+ entry_point: string;
5
+ outdir: string;
6
+ platform : 'Win32' | 'x64'
7
+ };
@@ -0,0 +1,30 @@
1
+
2
+ import prompts from 'prompts';
3
+ import { WW2Deploy } from './ww2_buildercore';
4
+ export async function buildForServer() {
5
+ const response = await prompts({
6
+ type: 'select',
7
+ name: 'menu',
8
+ message: 'Pilih menu',
9
+ choices: [
10
+ {
11
+ title: 'init_webview2', value: async () => {
12
+
13
+ await WW2Deploy.initWW2();
14
+ }
15
+ },
16
+ {
17
+ title: 'deploy', value: async () => {
18
+
19
+ await WW2Deploy.startDeploy();
20
+ }
21
+ },
22
+ ]
23
+ });
24
+ if (response && response.menu) {
25
+
26
+ response.menu();
27
+ }
28
+ }
29
+
30
+ buildForServer();