nw-builder 4.3.5 → 4.3.7
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 +4 -2
- package/src/bld/winCfg.js +2 -2
- package/src/get.js +18 -16
- package/src/index.js +12 -10
- package/src/run.js +76 -0
- package/src/util/ffmpeg.js +15 -12
- package/src/util.js +18 -0
- package/src/run/develop.js +0 -34
- package/src/run/execute.js +0 -33
- package/src/run/getPlatformSpecificName.js +0 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nw-builder",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.7",
|
|
4
4
|
"description": "Build NW.js desktop applications for MacOS, Windows and Linux.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NW.js",
|
|
@@ -40,8 +40,10 @@
|
|
|
40
40
|
"url": "https://github.com/nwutils/nw-builder.git"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
|
+
"ci:fmt": "prettier --check \"./**/*.{css,html,js,json,md,yml}\"",
|
|
44
|
+
"ci:lnt": "eslint --config=cfg/eslint.config.cjs cfg src test",
|
|
43
45
|
"fmt": "prettier --write \"./**/*.{css,html,js,json,md,yml}\"",
|
|
44
|
-
"lnt": "eslint --config=cfg/eslint.config.cjs --fix src test",
|
|
46
|
+
"lnt": "eslint --config=cfg/eslint.config.cjs --fix cfg src test",
|
|
45
47
|
"doc:dev": "concurrently --kill-others \"node cfg/fswatch.config.js\" \"vitepress dev doc\"",
|
|
46
48
|
"doc:bld": "vitepress build doc",
|
|
47
49
|
"test:unit": "node --test-reporter=spec --test test/unit/index.js",
|
package/src/bld/winCfg.js
CHANGED
|
@@ -60,10 +60,10 @@ const setWinConfig = async (app, outDir) => {
|
|
|
60
60
|
"file-version": app.version,
|
|
61
61
|
"product-version": app.version,
|
|
62
62
|
"version-string": versionString,
|
|
63
|
-
}
|
|
63
|
+
};
|
|
64
64
|
|
|
65
65
|
if (app.icon) {
|
|
66
|
-
rcEditOptions.icon = app.icon
|
|
66
|
+
rcEditOptions.icon = app.icon;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
try {
|
package/src/get.js
CHANGED
|
@@ -1,25 +1,15 @@
|
|
|
1
1
|
import { createWriteStream } from "node:fs";
|
|
2
|
-
|
|
3
2
|
import { mkdir, readdir, rm, rmdir } from "node:fs/promises";
|
|
4
3
|
import { get as getRequest } from "node:https";
|
|
5
4
|
import { resolve } from "node:path";
|
|
6
5
|
import { arch as ARCH, platform as PLATFORM } from "node:process";
|
|
7
|
-
import { log } from "./log.js";
|
|
8
6
|
|
|
9
7
|
import progress from "cli-progress";
|
|
10
8
|
import compressing from "compressing";
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
win32: "win",
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const ARCH_KV = {
|
|
19
|
-
x64: "x64",
|
|
20
|
-
ia32: "ia32",
|
|
21
|
-
arm64: "arm64",
|
|
22
|
-
};
|
|
10
|
+
import { log } from "./log.js";
|
|
11
|
+
import { PLATFORM_KV, ARCH_KV } from "./util.js";
|
|
12
|
+
import { replaceFfmpeg } from "./util/ffmpeg.js";
|
|
23
13
|
|
|
24
14
|
/**
|
|
25
15
|
* _Note: This an internal function which is not called directly. Please see example usage below._
|
|
@@ -55,7 +45,7 @@ const ARCH_KV = {
|
|
|
55
45
|
* mode: "get",
|
|
56
46
|
* downloadUrl: "https://cnpmjs.org/mirrors/nwjs/",
|
|
57
47
|
* });
|
|
58
|
-
*
|
|
48
|
+
*
|
|
59
49
|
* @example
|
|
60
50
|
* // FFmpeg (proprietary codecs)
|
|
61
51
|
* // Please read the license's constraints: https://nwjs.readthedocs.io/en/latest/For%20Developers/Enable%20Proprietary%20Codecs/#get-ffmpeg-binaries-from-the-community
|
|
@@ -133,7 +123,7 @@ export async function get({
|
|
|
133
123
|
}
|
|
134
124
|
|
|
135
125
|
// If not cached, then download.
|
|
136
|
-
if (nwCached === false) {
|
|
126
|
+
if (nwCached === false || ffmpeg === true) {
|
|
137
127
|
log.debug(`Downloading binaries`);
|
|
138
128
|
await mkdir(nwDir, { recursive: true });
|
|
139
129
|
|
|
@@ -144,7 +134,7 @@ export async function get({
|
|
|
144
134
|
// For GitHub releases and mirrors, we need to follow the redirect.
|
|
145
135
|
if (
|
|
146
136
|
downloadUrl ===
|
|
147
|
-
|
|
137
|
+
"https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt/releases/download" ||
|
|
148
138
|
downloadUrl === "https://npm.taobao.org/mirrors/nwjs" ||
|
|
149
139
|
downloadUrl === "https://npmmirror.com/mirrors/nwjs"
|
|
150
140
|
) {
|
|
@@ -190,6 +180,18 @@ export async function get({
|
|
|
190
180
|
|
|
191
181
|
// Remove compressed file after download and decompress.
|
|
192
182
|
return request.then(async () => {
|
|
183
|
+
if (ffmpeg === true) {
|
|
184
|
+
let ffmpegFile;
|
|
185
|
+
if (platform === "linux") {
|
|
186
|
+
ffmpegFile = "libffmpeg.so";
|
|
187
|
+
} else if (platform === "win") {
|
|
188
|
+
ffmpegFile = "ffmpeg.dll";
|
|
189
|
+
} else if (platform === "osx") {
|
|
190
|
+
ffmpegFile = "libffmpeg.dylib";
|
|
191
|
+
}
|
|
192
|
+
await replaceFfmpeg(platform, nwDir, ffmpegFile);
|
|
193
|
+
}
|
|
194
|
+
|
|
193
195
|
log.debug(`Binary decompressed starting removal`);
|
|
194
196
|
await rm(resolve(cacheDir, "ffmpeg.zip"), {
|
|
195
197
|
recursive: true,
|
package/src/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { resolve } from "node:path";
|
|
|
3
3
|
import { arch, platform, version } from "node:process";
|
|
4
4
|
|
|
5
5
|
import { build } from "./bld/build.js";
|
|
6
|
-
import {
|
|
6
|
+
import { run } from "./run.js";
|
|
7
7
|
import { isCached } from "./util/cache.js";
|
|
8
8
|
import { getFiles } from "./util/files.js";
|
|
9
9
|
import { getVersionManifest } from "./util/versionManifest.js";
|
|
@@ -137,15 +137,17 @@ const nwbuild = async (options) => {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
if (options.mode === "run") {
|
|
140
|
-
await
|
|
141
|
-
options.
|
|
142
|
-
|
|
143
|
-
options.platform,
|
|
144
|
-
options.
|
|
145
|
-
options.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
140
|
+
await run({
|
|
141
|
+
version: options.version,
|
|
142
|
+
flavor: options.flavor,
|
|
143
|
+
platform: options.platform,
|
|
144
|
+
arch: options.arch,
|
|
145
|
+
srcDir: options.srcDir,
|
|
146
|
+
cacheDir: options.cacheDir,
|
|
147
|
+
glob: options.glob,
|
|
148
|
+
argv: options.argv,
|
|
149
|
+
});
|
|
150
|
+
} else if (options.mode === "build") {
|
|
149
151
|
await build(
|
|
150
152
|
options.glob === true ? files : options.srcDir,
|
|
151
153
|
nwDir,
|
package/src/run.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { arch as ARCH, platform as PLATFORM } from "node:process";
|
|
4
|
+
|
|
5
|
+
import { log } from "./log.js";
|
|
6
|
+
import { EXE_NAME, ARCH_KV, PLATFORM_KV } from "./util.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* _Note: This an internal function which is not called directly. Please see example usage below._
|
|
10
|
+
*
|
|
11
|
+
* Run NW.js application. You can use get mode options in run mode too.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Minimal Usage (uses default values)
|
|
15
|
+
* nwbuild({
|
|
16
|
+
* mode: "run",
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* @param {options} options Run mode options
|
|
20
|
+
* @param {string} options.version NW.js runtime version. Defaults to "latest".
|
|
21
|
+
* @param {"normal" | "sdk"} options.flavor NW.js build flavor. Defaults to "normal".
|
|
22
|
+
* @param {"linux" | "osx" | "win"} options.platform Target platform. Defaults to host platform.
|
|
23
|
+
* @param {"ia32" | "x64" | "arm64"} options.arch Target architecture. Defaults to host architecture.
|
|
24
|
+
* @param {string} options.srcDir Source directory path. Defaults to "./src"
|
|
25
|
+
* @param {string} options.cacheDir Cache directory path. Defaults to "./cache"
|
|
26
|
+
* @param {boolean} options.glob If true, file globbing is enabled. Defaults to false.
|
|
27
|
+
* @param {string[]} options.argv Arguments to pass to NW.js. Defaults to []. See [NW.js CLI options](https://docs.nwjs.io/en/latest/References/Command%20Line%20Options/#command-line-options) for more information.
|
|
28
|
+
* @return {Promise<void>}
|
|
29
|
+
*/
|
|
30
|
+
export async function run({
|
|
31
|
+
version = "latest",
|
|
32
|
+
flavor = "normal",
|
|
33
|
+
platform = PLATFORM_KV[PLATFORM],
|
|
34
|
+
arch = ARCH_KV[ARCH],
|
|
35
|
+
srcDir = "./src",
|
|
36
|
+
cacheDir = "./cache",
|
|
37
|
+
glob = false,
|
|
38
|
+
argv = [],
|
|
39
|
+
}) {
|
|
40
|
+
try {
|
|
41
|
+
if (EXE_NAME[platform] === undefined) {
|
|
42
|
+
throw new Error("Unsupported platform.");
|
|
43
|
+
}
|
|
44
|
+
if (glob === true) {
|
|
45
|
+
throw new Error("Globbing is not supported with run mode.");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const nwDir = resolve(
|
|
49
|
+
cacheDir,
|
|
50
|
+
`nwjs${flavor === "sdk" ? "-sdk" : ""}-v${version}-${platform}-${arch}`,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
return new Promise((res, rej) => {
|
|
54
|
+
// It is assumed that the package.json is located at srcDir/package.json
|
|
55
|
+
const nwProcess = spawn(
|
|
56
|
+
resolve(nwDir, EXE_NAME[platform]),
|
|
57
|
+
[srcDir.concat(argv)],
|
|
58
|
+
{
|
|
59
|
+
detached: true,
|
|
60
|
+
windowsHide: true,
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
nwProcess.on("close", () => {
|
|
65
|
+
res();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
nwProcess.on("error", (error) => {
|
|
69
|
+
log.error(error);
|
|
70
|
+
rej(error);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
} catch (error) {
|
|
74
|
+
log.error(error);
|
|
75
|
+
}
|
|
76
|
+
}
|
package/src/util/ffmpeg.js
CHANGED
|
@@ -9,22 +9,25 @@ import { resolve } from "node:path";
|
|
|
9
9
|
* @param {string} ffmpegFile The path to the ffmpeg file to replace with
|
|
10
10
|
*/
|
|
11
11
|
export const replaceFfmpeg = async (platform, nwDir, ffmpegFile) => {
|
|
12
|
+
const src = resolve(nwDir, ffmpegFile);
|
|
12
13
|
if (platform === "linux") {
|
|
13
|
-
|
|
14
|
+
const dest = resolve(nwDir, "lib", ffmpegFile);
|
|
15
|
+
await copyFile(src, dest);
|
|
14
16
|
} else if (platform === "win") {
|
|
15
|
-
|
|
17
|
+
// don't do anything for windows because the extracted file is already in the correct path
|
|
18
|
+
// await copyFile(src, resolve(nwDir, ffmpegFile));
|
|
16
19
|
} else if (platform === "osx") {
|
|
17
|
-
|
|
20
|
+
const dest = resolve(
|
|
21
|
+
nwDir,
|
|
22
|
+
"nwjs.app",
|
|
23
|
+
"Contents",
|
|
24
|
+
"Frameworks",
|
|
25
|
+
"nwjs Framework.framework",
|
|
26
|
+
"Versions",
|
|
27
|
+
"Current",
|
|
18
28
|
ffmpegFile,
|
|
19
|
-
resolve(
|
|
20
|
-
nwDir,
|
|
21
|
-
"Contents",
|
|
22
|
-
"Frameworks",
|
|
23
|
-
"nwjs Framework.framework",
|
|
24
|
-
"Versions",
|
|
25
|
-
"Current",
|
|
26
|
-
ffmpegFile,
|
|
27
|
-
),
|
|
28
29
|
);
|
|
30
|
+
|
|
31
|
+
await copyFile(src, dest);
|
|
29
32
|
}
|
|
30
33
|
};
|
package/src/util.js
CHANGED
|
@@ -83,3 +83,21 @@ export async function getReleaseInfo(
|
|
|
83
83
|
}
|
|
84
84
|
return releaseData;
|
|
85
85
|
}
|
|
86
|
+
|
|
87
|
+
export const PLATFORM_KV = {
|
|
88
|
+
darwin: "osx",
|
|
89
|
+
linux: "linux",
|
|
90
|
+
win32: "win",
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const ARCH_KV = {
|
|
94
|
+
x64: "x64",
|
|
95
|
+
ia32: "ia32",
|
|
96
|
+
arm64: "arm64",
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const EXE_NAME = {
|
|
100
|
+
win: "nw.exe",
|
|
101
|
+
osx: "nwjs.app/Contents/MacOS/nwjs",
|
|
102
|
+
linux: "nw",
|
|
103
|
+
};
|
package/src/run/develop.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { execute } from "./execute.js";
|
|
2
|
-
import { getPlatformSpecificName } from "./getPlatformSpecificName.js";
|
|
3
|
-
|
|
4
|
-
import { log } from "../log.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Runs the NW app by spawning a child process
|
|
8
|
-
*
|
|
9
|
-
* @param {string} srcDir The directory to run from
|
|
10
|
-
* @param {string} nwDir The directory to run nw.js from
|
|
11
|
-
* @param {"win" | "osx" | "linux"} platform The platform to run for
|
|
12
|
-
* @param {string[]} argv The arguments to pass to the nw.js development server
|
|
13
|
-
* @param {boolean} glob If true then glob then globbing is enabled
|
|
14
|
-
* @return {Promise<undefined>}
|
|
15
|
-
*/
|
|
16
|
-
const develop = async (srcDir, nwDir, platform, argv, glob) => {
|
|
17
|
-
try {
|
|
18
|
-
if (getPlatformSpecificName(platform) === null) {
|
|
19
|
-
throw new Error("Unsupported platform.");
|
|
20
|
-
}
|
|
21
|
-
if (glob === true) {
|
|
22
|
-
throw new Error("Globbing is not supported by run mode.");
|
|
23
|
-
}
|
|
24
|
-
await execute(
|
|
25
|
-
srcDir,
|
|
26
|
-
`${nwDir}/${getPlatformSpecificName(platform)}`,
|
|
27
|
-
argv,
|
|
28
|
-
);
|
|
29
|
-
} catch (error) {
|
|
30
|
-
log.error(error);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export { develop };
|
package/src/run/execute.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
|
|
3
|
-
import { log } from "../log.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Executes the NW.js process
|
|
7
|
-
*
|
|
8
|
-
* @param {string} srcDir The source directory
|
|
9
|
-
* @param {string} nwPath The path to the NW.js executable
|
|
10
|
-
* @param {string} argv The arguments to pass to the NW.js process
|
|
11
|
-
* @return {Promise<undefined>} The exit code of the NW.js process
|
|
12
|
-
* @throws {Error} - If the NW.js process fails to start
|
|
13
|
-
*/
|
|
14
|
-
const execute = (srcDir, nwPath, argv) => {
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
// It is assumed that the package.jsonis located at srcDir/package.json
|
|
17
|
-
const nwProcess = spawn(nwPath, [srcDir.concat(argv)], {
|
|
18
|
-
detached: true,
|
|
19
|
-
windowsHide: true,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
nwProcess.on("close", () => {
|
|
23
|
-
resolve();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
nwProcess.on("error", (error) => {
|
|
27
|
-
log.error(error);
|
|
28
|
-
reject(error);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export { execute };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get platform specific name of the executable
|
|
3
|
-
*
|
|
4
|
-
* @param {string} platform - Platform
|
|
5
|
-
* @return {string} - Platform specific name
|
|
6
|
-
*/
|
|
7
|
-
const getPlatformSpecificName = (platform) => {
|
|
8
|
-
switch (platform) {
|
|
9
|
-
case "linux":
|
|
10
|
-
return "nw";
|
|
11
|
-
case "osx":
|
|
12
|
-
return "nwjs.app/Contents/MacOS/nwjs";
|
|
13
|
-
case "win":
|
|
14
|
-
return "nw.exe";
|
|
15
|
-
default:
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export { getPlatformSpecificName };
|