win_webview2 1.0.13 → 1.1.5
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/README.md +164 -31
- package/buildtools/copyDll.ts +71 -0
- package/{tsconfig.json → buildtools/tsconfig.json} +12 -12
- package/dist/browser/ww2_browser.d.ts +32 -0
- package/dist/browser/ww2_browser.js +11 -0
- package/{tsDist/srcBuilder → dist/node/builder}/build_copyDir.d.ts +1 -1
- package/{tsDist/srcBuilder → dist/node/builder}/build_copyDir.js +24 -24
- package/dist/node/builder/builder_deploy.d.ts +2 -0
- package/{tsDist/srcBuilder/builder_tp.js → dist/node/builder/builder_deploy.js} +2 -2
- package/dist/node/builder/builder_init.d.ts +9 -0
- package/dist/node/builder/builder_init.js +52 -0
- package/dist/node/builder/builder_promps.d.ts +9 -0
- package/dist/node/builder/builder_promps.js +68 -0
- package/dist/node/builder/dirnameTool.d.ts +4 -0
- package/dist/node/builder/dirnameTool.js +16 -0
- package/dist/node/builder/tools.d.ts +4 -0
- package/dist/node/builder/tools.js +15 -0
- package/dist/node/builder/userExec.d.ts +2 -0
- package/dist/node/builder/userExec.js +45 -0
- package/{tsDist/srcBuilder/builder_tp.d.ts → dist/node/tsExport/config.d.ts} +7 -7
- package/dist/node/tsExport/config.js +2 -0
- package/dist/node/tsExport/dirnameTool.d.ts +6 -0
- package/dist/node/tsExport/dirnameTool.js +63 -0
- package/dist/node/tsExport/winwebview2.d.ts +38 -0
- package/dist/node/tsExport/winwebview2.js +51 -0
- package/dist/node/tsExport/ww2_config.d.ts +7 -0
- package/dist/node/tsExport/ww2_config.js +18 -0
- package/dist/node/tsExport/ww2_server.d.ts +36 -0
- package/dist/node/tsExport/ww2_server.js +100 -0
- package/package.json +21 -7
- package/srcBrowser/tsconfig.json +13 -0
- package/srcBrowser/ww2_browser.ts +47 -0
- package/srcNode/builder/builder_init.ts +78 -0
- package/srcNode/builder/builder_promps.ts +93 -0
- package/srcNode/builder/userExec.ts +54 -0
- package/srcNode/tsExport/dirnameTool.ts +34 -0
- package/srcNode/tsExport/winwebview2.ts +78 -0
- package/srcNode/tsExport/ww2_config.ts +24 -0
- package/srcNode/tsExport/ww2_server.ts +157 -0
- package/srcNode/tsconfig.json +13 -0
- package/tsDistRun.js +5 -5
- package/win_lib/Win32/WebView2Loader.dll +0 -0
- package/win_lib/Win32/exeOpenner.exe +0 -0
- package/win_lib/Win32/ww2_addon.node +0 -0
- package/win_lib/x64/WebView2Loader.dll +0 -0
- package/win_lib/x64/exeOpenner.exe +0 -0
- package/win_lib/x64/ww2_addon.node +0 -0
- package/tsDist/logprint.d.ts +0 -1
- package/tsDist/logprint.js +0 -6
- package/tsDist/srcBuilder/ww2_build_promp.d.ts +0 -1
- package/tsDist/srcBuilder/ww2_build_promp.js +0 -31
- package/tsDist/srcBuilder/ww2_buildercore.d.ts +0 -14
- package/tsDist/srcBuilder/ww2_buildercore.js +0 -124
- package/tsDist/tsExport/winwebview2.d.ts +0 -28
- package/tsDist/tsExport/winwebview2.js +0 -105
- package/tsSrc/logprint.ts +0 -3
- package/tsSrc/srcBuilder/build_copyDir.ts +0 -32
- package/tsSrc/srcBuilder/builder_tp.ts +0 -7
- package/tsSrc/srcBuilder/ww2_build_promp.ts +0 -30
- package/tsSrc/srcBuilder/ww2_buildercore.ts +0 -182
- package/tsSrc/tsExport/winwebview2.ts +0 -160
- package/win_lib/Win32/CmdWebview2.exe +0 -0
- package/win_lib/Win32/icon.ico +0 -0
- package/win_lib/Win32/index.bat +0 -3
- package/win_lib/x64/CmdWebview2.exe +0 -0
- package/win_lib/x64/icon.ico +0 -0
- package/win_lib/x64/index.bat +0 -3
package/README.md
CHANGED
|
@@ -1,52 +1,185 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
## win_webview2
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
A lightweight Node.js module to build Windows desktop UIs using Microsoft WebView2. A minimal and tiny alternative to Electron for developers who need a simple web-based interface without the heavy Chromium overhead
|
|
5
|
+
|
|
4
6
|
|
|
5
|
-
```npm i win_webview2```
|
|
6
7
|
|
|
8
|
+
## Installation
|
|
9
|
+
Install the package via npm:
|
|
7
10
|
|
|
8
|
-
Win Webview2 is a GUI toolkit for building desktop applications with Node.js. It is similar to Electron but significantly smaller because Win Webview2 utilizes Microsoft WebView2, which is already installed on Windows 10 and later versions.
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
```sh
|
|
13
|
+
npm install win_webview2
|
|
14
|
+
```
|
|
15
|
+
|
|
11
16
|
|
|
12
|
-
|
|
17
|
+
## Interactive Project Management
|
|
18
|
+
The win_webview2 CLI is designed to be your single point of control for the entire development lifecycle.
|
|
19
|
+
## 1. Scaffolding (First time)
|
|
20
|
+
To download the boilerplate and set up your project, simply run:
|
|
13
21
|
|
|
14
22
|
```sh
|
|
15
23
|
npx win_webview2
|
|
16
|
-
```
|
|
24
|
+
```
|
|
17
25
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- `deploy` – Builds the application from your Node.js project.
|
|
26
|
+
## 2. Develop, Watch, and Build
|
|
27
|
+
After the initial setup, you don't need to remember complex commands. Just run the same command again:
|
|
21
28
|
|
|
22
|
-
## Example Configuration File
|
|
23
29
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"appname": "openweb",
|
|
28
|
-
"icon_path": "./icon.png",
|
|
29
|
-
"outdir": "./dist"
|
|
30
|
-
}
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
npx win_webview2
|
|
31
33
|
```
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
What it does:
|
|
36
|
+
It opens an interactive menu where you can manage your project. You can simply use your arrow keys (↑/↓) to select common tasks:
|
|
37
|
+
|
|
38
|
+
* Watch Mode: Run and see changes in real-time.
|
|
39
|
+
* Build: Compile your application for production.
|
|
40
|
+
* Dev Tools: Open debugging utilities.
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
>Pro Tip: Just hit npx win_webview2, use the Up/Down arrows to pick your task,
|
|
44
|
+
>and press Enter. It's that simple!
|
|
45
|
+
|
|
46
|
+
## Features
|
|
47
|
+
|
|
48
|
+
* Built-in Express Server: Easily serve your static HTML folders.
|
|
49
|
+
* Native UI Management: Control window states (maximize, minimize, move, resize).
|
|
50
|
+
* Native Dialogs: Access Windows Open File and Open Folder dialogs directly from the browser.
|
|
51
|
+
* Low-level API: Direct access to the native Node.js addon.
|
|
52
|
+
|
|
34
53
|
|
|
35
|
-
```js
|
|
36
|
-
import { openDialogFile, openDialogFolder, openWeb } from 'win_webview2';
|
|
37
54
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
55
|
+
## Basic Usage (Server-side)
|
|
56
|
+
|
|
57
|
+
Use ww2_CreateServer to host your HTML files and initialize the WebView2 window.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
|
|
61
|
+
import { existsSync } from "node:fs";
|
|
62
|
+
import path from "node:path";
|
|
63
|
+
import { closeSplash, ww2_CreateServer } from "win_webview2/node"
|
|
64
|
+
// Determine your HTML folder path
|
|
65
|
+
|
|
66
|
+
let htmlFolder = (() => {
|
|
67
|
+
let result = path.join(__dirname, "html");
|
|
68
|
+
if (!existsSync(result)) {
|
|
69
|
+
result = path.join(process.cwd(), "assets/lib/html")
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
})();
|
|
73
|
+
// Create the server and UI
|
|
74
|
+
|
|
75
|
+
ww2_CreateServer({
|
|
76
|
+
port: 0, // 0 for auto-assign
|
|
77
|
+
uiConfig: {
|
|
41
78
|
width: 800,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
79
|
+
height: 400,
|
|
80
|
+
title: "Ww2 UI",
|
|
81
|
+
wclassname: "myuiclass",
|
|
82
|
+
isDebug: true,
|
|
83
|
+
isKiosk: false,
|
|
84
|
+
isMaximize: false,
|
|
85
|
+
},
|
|
86
|
+
onExpressCreate: (app) => {
|
|
87
|
+
// You can add custom express middlewares here
|
|
88
|
+
},
|
|
89
|
+
htmlfolder: htmlFolder
|
|
90
|
+
});
|
|
91
|
+
// Close splash screen if active
|
|
92
|
+
closeSplash();
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
------------------------------
|
|
99
|
+
## Browser Integration (Client-side)
|
|
100
|
+
Once the server is running, you can interact with the native Windows layer using callWw2.
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
|
|
104
|
+
import { callWw2 } from "win_webview2/browser"
|
|
105
|
+
// Open File Dialog
|
|
106
|
+
const openFile = async () => {
|
|
107
|
+
let r = await callWw2({
|
|
108
|
+
openFileDialog: {
|
|
109
|
+
filter: "All Files (*.*)|*.*",
|
|
110
|
+
ownerClassName: "myuiclass",
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
console.log("Selected file:", r.result);
|
|
114
|
+
};
|
|
115
|
+
// Window Controls (Close, Move, Resize, Max/Min)
|
|
116
|
+
const closeWindow = async () => {
|
|
117
|
+
|
|
118
|
+
await callWw2({
|
|
119
|
+
controlWindow: {
|
|
120
|
+
controlcmd: "close",
|
|
121
|
+
wndClassName: "myuiclass"
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const resizeWindow = async () => {
|
|
127
|
+
await callWw2({
|
|
128
|
+
controlWindow: {
|
|
129
|
+
controlcmd: "resize",
|
|
130
|
+
wndClassName: "myuiclass",
|
|
131
|
+
width: 800,
|
|
132
|
+
height: 700
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
------------------------------
|
|
140
|
+
|
|
141
|
+
## Low-Level API
|
|
142
|
+
If you need direct access to the native module (.node addon), you can use getModule.
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
|
|
146
|
+
import { getModule } from "win_webview2/node";
|
|
147
|
+
async function runLowLevel() {
|
|
148
|
+
const ww2 = await getModule();
|
|
149
|
+
|
|
150
|
+
// Manual window control
|
|
151
|
+
ww2.controlWindow({
|
|
152
|
+
wndClassName: "myuiclass",
|
|
153
|
+
controlcmd: "maximize"
|
|
154
|
+
});
|
|
48
155
|
}
|
|
49
156
|
|
|
50
157
|
```
|
|
51
158
|
|
|
52
|
-
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
## Module Interfaces
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
|
|
165
|
+
export interface WW2ControlWindowsArg {
|
|
166
|
+
wndClassName: string;
|
|
167
|
+
controlcmd: "close" | "move" | "maximize" | "minimize" | "resize" | "check";
|
|
168
|
+
left?: number;
|
|
169
|
+
top?: number;
|
|
170
|
+
height?: number;
|
|
171
|
+
width?: number;
|
|
172
|
+
}
|
|
173
|
+
interface Ww2Module {
|
|
174
|
+
openWeb: (arg: Ww2WebConfig) => void;
|
|
175
|
+
openFileDialog: (arg: WW2FileDialogArg) => void;
|
|
176
|
+
openFolderDialog: (arg: WW2FileDialogArg) => void;
|
|
177
|
+
controlWindow: (arg: WW2ControlWindowsArg) => void;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
------------------------------
|
|
183
|
+
## License
|
|
184
|
+
MIT
|
|
185
|
+
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { exec } from "node:child_process";
|
|
2
|
+
import { copyFile, mkdir } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
function debugDir(dirPath: string) {
|
|
6
|
+
exec("cd " + dirPath + "&& dir", (s, o) => {
|
|
7
|
+
console.log(o);
|
|
8
|
+
})
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
|
|
13
|
+
let result = "\n";
|
|
14
|
+
|
|
15
|
+
let rootPath = path.join(__dirname, "../../");
|
|
16
|
+
let copyFromRoot = async (src: string, target: string) => {
|
|
17
|
+
result += "\n" + target;
|
|
18
|
+
await copyFile(path.join(rootPath, src), path.join(rootPath, target));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
|
|
23
|
+
await mkdir(path.join(rootPath, "win_webview2/win_lib/Win32"));
|
|
24
|
+
await mkdir(path.join(rootPath, "win_webview2/win_lib/x64"));
|
|
25
|
+
} catch (error) {
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await copyFromRoot(
|
|
30
|
+
"exeOpener/build/x64/exeOpenner.exe",
|
|
31
|
+
"win_webview2/win_lib/x64/exeOpenner.exe"
|
|
32
|
+
);
|
|
33
|
+
await copyFromRoot(
|
|
34
|
+
"exeOpener/build/x64/splash.png",
|
|
35
|
+
"win_webview2/win_lib/x64/splash.png"
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
await copyFromRoot(
|
|
39
|
+
"exeOpener/build/x86/exeOpenner.exe",
|
|
40
|
+
"win_webview2/win_lib/Win32/exeOpenner.exe"
|
|
41
|
+
);
|
|
42
|
+
await copyFromRoot(
|
|
43
|
+
"exeOpener/build/x86/splash.png",
|
|
44
|
+
"win_webview2/win_lib/Win32/splash.png"
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
console.log("copy webview2 32");
|
|
48
|
+
await copyFromRoot(
|
|
49
|
+
"nodeAddOn/build/ia32/Release/ww2_addon.node",
|
|
50
|
+
"win_webview2/win_lib/Win32/ww2_addon.node"
|
|
51
|
+
);
|
|
52
|
+
await copyFromRoot(
|
|
53
|
+
"nodeAddOn/build/ia32/Release/WebView2Loader.dll",
|
|
54
|
+
"win_webview2/win_lib/Win32/WebView2Loader.dll"
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
console.log("copy webview2 64");
|
|
58
|
+
await copyFromRoot(
|
|
59
|
+
"nodeAddOn/build/x64/Release/ww2_addon.node",
|
|
60
|
+
"win_webview2/win_lib/x64/ww2_addon.node"
|
|
61
|
+
);
|
|
62
|
+
await copyFromRoot(
|
|
63
|
+
"nodeAddOn/build/x64/Release/WebView2Loader.dll",
|
|
64
|
+
"win_webview2/win_lib/x64/WebView2Loader.dll"
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
console.log("copy done :" + result);
|
|
70
|
+
|
|
71
|
+
})();
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "CommonJS",
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"rootDir": "./
|
|
7
|
-
"outDir": "./tsDist",
|
|
8
|
-
"strict": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"skipLibCheck": true
|
|
11
|
-
},
|
|
12
|
-
"include": ["
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"rootDir": "./",
|
|
7
|
+
"outDir": "./tsDist",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true
|
|
11
|
+
},
|
|
12
|
+
"include": ["./"]
|
|
13
13
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
interface WW2FileDialogArg {
|
|
2
|
+
filter: string;
|
|
3
|
+
ownerClassName: string;
|
|
4
|
+
}
|
|
5
|
+
interface WW2ControlWindowsArg {
|
|
6
|
+
wndClassName: string;
|
|
7
|
+
controlcmd: "close" | "move" | "maximize" | "minimize" | "resize" | "check";
|
|
8
|
+
left?: number;
|
|
9
|
+
top?: number;
|
|
10
|
+
height?: number;
|
|
11
|
+
width?: number;
|
|
12
|
+
}
|
|
13
|
+
export type PostData = {
|
|
14
|
+
openWeb?: {
|
|
15
|
+
wclassname: string;
|
|
16
|
+
url: string;
|
|
17
|
+
title: string;
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
isKiosk: boolean;
|
|
21
|
+
isMaximize: boolean;
|
|
22
|
+
isDebug: boolean;
|
|
23
|
+
};
|
|
24
|
+
openFileDialog?: WW2FileDialogArg;
|
|
25
|
+
openFolderDialog?: WW2FileDialogArg;
|
|
26
|
+
controlWindow?: WW2ControlWindowsArg;
|
|
27
|
+
};
|
|
28
|
+
export declare function callWw2(arg: PostData): Promise<{
|
|
29
|
+
err: string;
|
|
30
|
+
result: string;
|
|
31
|
+
}>;
|
|
32
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function copyDir(source: string, destination: string): Promise<void>;
|
|
1
|
+
export declare function copyDir(source: string, destination: string): Promise<void>;
|
|
@@ -1,24 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,52 @@
|
|
|
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.ww2Init = ww2Init;
|
|
7
|
+
const dirnameTool_1 = require("../tsExport/dirnameTool");
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
9
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
10
|
+
function runCommand(command) {
|
|
11
|
+
try {
|
|
12
|
+
const currentShell = process.platform === 'win32' ? 'cmd.exe' : '/bin/sh';
|
|
13
|
+
(0, child_process_1.execSync)(command, { stdio: 'inherit', shell: currentShell, killSignal: "SIGINT" });
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
console.error(`Command Error: ${command}`);
|
|
17
|
+
process.exit();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const jsonConfigFilePath = "./win_webview2.json";
|
|
21
|
+
let mdirname = (0, dirnameTool_1.getWw2Dirname)();
|
|
22
|
+
let ww2Choise = {
|
|
23
|
+
"ww2_typescript": {
|
|
24
|
+
description: "init win_webview2",
|
|
25
|
+
fun: async () => {
|
|
26
|
+
runCommand('npx degit nnttoo/win_webview2/example/ww2_typescript#master ww2_typescript');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
async function ww2Init() {
|
|
31
|
+
const response = await (0, prompts_1.default)({
|
|
32
|
+
type: 'select',
|
|
33
|
+
name: 'menu',
|
|
34
|
+
message: 'Pick one example',
|
|
35
|
+
instructions: '(Use arrow keys to navigate, press enter to select)',
|
|
36
|
+
choices: (() => {
|
|
37
|
+
let result = [];
|
|
38
|
+
for (let item in ww2Choise) {
|
|
39
|
+
let val = ww2Choise[item];
|
|
40
|
+
result.push({
|
|
41
|
+
title: item,
|
|
42
|
+
value: val.fun,
|
|
43
|
+
description: val.description,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
})(),
|
|
48
|
+
});
|
|
49
|
+
if (response && response.menu) {
|
|
50
|
+
await response.menu();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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 builder_init_1 = require("./builder_init");
|
|
9
|
+
const userExec_1 = require("./userExec");
|
|
10
|
+
let ww2Choise = {
|
|
11
|
+
"init_win_webview2": {
|
|
12
|
+
description: "init win_webview2",
|
|
13
|
+
fun: async () => {
|
|
14
|
+
await (0, builder_init_1.ww2Init)();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
async function buildForServer() {
|
|
19
|
+
let userChoise = await (0, userExec_1.readUserScripts)();
|
|
20
|
+
if (userChoise != null) {
|
|
21
|
+
ww2Choise = {
|
|
22
|
+
...ww2Choise,
|
|
23
|
+
...userChoise
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const response = await (0, prompts_1.default)({
|
|
27
|
+
type: 'select',
|
|
28
|
+
name: 'menu',
|
|
29
|
+
message: 'Pick one',
|
|
30
|
+
instructions: '(Use arrow keys to navigate, press enter to select)',
|
|
31
|
+
choices: (() => {
|
|
32
|
+
let result = [];
|
|
33
|
+
for (let item in ww2Choise) {
|
|
34
|
+
let val = ww2Choise[item];
|
|
35
|
+
result.push({
|
|
36
|
+
title: item,
|
|
37
|
+
value: val.fun,
|
|
38
|
+
description: val.description,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
})(),
|
|
43
|
+
});
|
|
44
|
+
if (response && response.menu) {
|
|
45
|
+
await response.menu();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
console.log("ww2 version : v6 \n\n");
|
|
49
|
+
const args = process.argv.slice(2);
|
|
50
|
+
if (args.length > 0) {
|
|
51
|
+
let argument = args[0];
|
|
52
|
+
if (argument.startsWith("--")) {
|
|
53
|
+
argument = argument.substring(2);
|
|
54
|
+
}
|
|
55
|
+
console.log(argument);
|
|
56
|
+
if (ww2Choise[argument]) {
|
|
57
|
+
ww2Choise[argument].fun();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
buildForServer();
|
|
62
|
+
}
|
|
63
|
+
process.on('SIGINT', () => {
|
|
64
|
+
console.log('\n[Sinyal SIGINT Terdeteksi]');
|
|
65
|
+
console.log('User menekan Ctrl+C. Membersihkan data...');
|
|
66
|
+
// Anda harus memanggil exit secara manual jika menggunakan listener ini
|
|
67
|
+
process.exit(0);
|
|
68
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDirname = getDirname;
|
|
4
|
+
const node_url_1 = require("node:url");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
function getDirname() {
|
|
7
|
+
// Trik deteksi lingkungan
|
|
8
|
+
const _filename = typeof __filename !== 'undefined'
|
|
9
|
+
? __filename
|
|
10
|
+
// @ts-ignore:
|
|
11
|
+
: (0, node_url_1.fileURLToPath)(eval('import.meta.url'));
|
|
12
|
+
const _dirname = typeof __dirname !== 'undefined'
|
|
13
|
+
? __dirname
|
|
14
|
+
: (0, node_path_1.dirname)(_filename);
|
|
15
|
+
return { _dirname, _filename };
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDirname = getDirname;
|
|
4
|
+
const node_url_1 = require("node:url");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
function getDirname() {
|
|
7
|
+
// Trik deteksi lingkungan
|
|
8
|
+
const _filename = typeof __filename !== 'undefined'
|
|
9
|
+
? __filename
|
|
10
|
+
: (0, node_url_1.fileURLToPath)(import.meta.url);
|
|
11
|
+
const _dirname = typeof __dirname !== 'undefined'
|
|
12
|
+
? __dirname
|
|
13
|
+
: (0, node_path_1.dirname)(_filename);
|
|
14
|
+
return { _dirname, _filename };
|
|
15
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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.readUserScripts = readUserScripts;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const dirnameTool_1 = require("../tsExport/dirnameTool");
|
|
9
|
+
const promises_1 = require("node:fs/promises");
|
|
10
|
+
const comment_json_1 = require("comment-json");
|
|
11
|
+
const node_child_process_1 = require("node:child_process");
|
|
12
|
+
function runNpm(command) {
|
|
13
|
+
try {
|
|
14
|
+
const currentShell = process.platform === 'win32' ? 'cmd.exe' : '/bin/sh';
|
|
15
|
+
let cmd = `npm run ${command}`;
|
|
16
|
+
console.log(cmd);
|
|
17
|
+
(0, node_child_process_1.execSync)(cmd, { stdio: 'inherit', shell: currentShell, killSignal: "SIGINT" });
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
console.error(`Command Error: ${command}`);
|
|
21
|
+
process.exit();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function readUserScripts() {
|
|
25
|
+
let dirUser = (0, dirnameTool_1.findUserProjectRoot)();
|
|
26
|
+
if (dirUser == null)
|
|
27
|
+
return;
|
|
28
|
+
let pkgJson = node_path_1.default.join(dirUser, "package.json");
|
|
29
|
+
let pkgTxt = await (0, promises_1.readFile)(pkgJson, "utf-8");
|
|
30
|
+
let obj = (0, comment_json_1.parse)(pkgTxt);
|
|
31
|
+
if (obj.scripts == null)
|
|
32
|
+
return;
|
|
33
|
+
let ww2Choise = {};
|
|
34
|
+
let name = obj.name ? obj.name : "";
|
|
35
|
+
for (let kscript in obj.scripts) {
|
|
36
|
+
let cmd = obj.scripts[kscript];
|
|
37
|
+
ww2Choise["--" + kscript] = {
|
|
38
|
+
description: name + " : " + cmd,
|
|
39
|
+
fun: () => {
|
|
40
|
+
runNpm(kscript);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return ww2Choise;
|
|
45
|
+
}
|
|
@@ -1,7 +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
|
-
};
|
|
1
|
+
export type ConfigWW2 = {
|
|
2
|
+
appname: string;
|
|
3
|
+
icon_path: string;
|
|
4
|
+
entry_point: string;
|
|
5
|
+
outdir: string;
|
|
6
|
+
platform: 'Win32' | 'x64';
|
|
7
|
+
};
|