nw-builder 4.3.10 → 4.4.0
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 +2 -2
- package/package.json +4 -4
- package/src/bld/build.js +2 -11
- package/src/get_ffmpeg.js +134 -0
- package/src/{get.js → get_nwjs.js} +8 -49
- package/src/index.js +4 -7
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# nw-builder
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/nw-builder)
|
|
4
|
-
[](https://www.npmjs.com/package/nw-builder/v/latest)
|
|
4
|
+
[](https://app.gitter.im/#/room/#nwjs_nw-builder:gitter.im)
|
|
5
5
|
|
|
6
6
|
Build [NW.js](https://github.com/nwjs/nw.js) applications for Mac, Windows and Linux.
|
|
7
7
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nw-builder",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "Build NW.js desktop applications for MacOS, Windows and Linux.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NW.js",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"lnt": "eslint --config=cfg/eslint.config.cjs --fix cfg src test",
|
|
47
47
|
"doc:dev": "concurrently --kill-others \"node cfg/fswatch.config.js\" \"vitepress dev doc\"",
|
|
48
48
|
"doc:bld": "vitepress build doc",
|
|
49
|
-
"test:unit": "node --test
|
|
50
|
-
"test:e2e": "node --test
|
|
49
|
+
"test:unit": "node --test test/unit/index.js",
|
|
50
|
+
"test:e2e": "node --test test/e2e/index.js",
|
|
51
51
|
"test:mod": "cd test/fixture && node demo.js",
|
|
52
52
|
"test:cli": "cd test/fixture && nwbuild --platform win --arch x64 --outDir out --no-glob app"
|
|
53
53
|
},
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"compressing": "^1.9.0",
|
|
68
68
|
"glob": "^10.3.3",
|
|
69
69
|
"plist": "^3.1.0",
|
|
70
|
-
"rcedit": "^
|
|
70
|
+
"rcedit": "^4.0.0",
|
|
71
71
|
"winston": "^3.9.0",
|
|
72
72
|
"yargs": "^17.7.2"
|
|
73
73
|
},
|
package/src/bld/build.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
|
-
import { cp, rm
|
|
2
|
+
import { cp, rm } from "node:fs/promises";
|
|
3
3
|
|
|
4
4
|
import compressing from "compressing";
|
|
5
5
|
|
|
@@ -18,18 +18,9 @@ import { setWinConfig } from "./winCfg.js";
|
|
|
18
18
|
* @param {"linux" | "osx" | "win"} platform Platform is the operating system type
|
|
19
19
|
* @param {"zip" | boolean} zip Specify if the build artifacts are to be zipped
|
|
20
20
|
* @param {object} app Multi platform configuration options
|
|
21
|
-
* @param {string} nwPkg NW.js manifest file
|
|
22
21
|
* @return {Promise<undefined>}
|
|
23
22
|
*/
|
|
24
|
-
export const build = async (
|
|
25
|
-
files,
|
|
26
|
-
nwDir,
|
|
27
|
-
outDir,
|
|
28
|
-
platform,
|
|
29
|
-
zip,
|
|
30
|
-
app,
|
|
31
|
-
nwPkg,
|
|
32
|
-
) => {
|
|
23
|
+
export const build = async (files, nwDir, outDir, platform, zip, app) => {
|
|
33
24
|
log.debug(`Remove any files at ${outDir} directory`);
|
|
34
25
|
await rm(outDir, { force: true, recursive: true });
|
|
35
26
|
log.debug(`Copy ${nwDir} files to ${outDir} directory`);
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { createWriteStream, existsSync } from "node:fs";
|
|
2
|
+
import { rm } from "node:fs/promises";
|
|
3
|
+
import { get as getRequest } from "node:https";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
import { arch as ARCH, platform as PLATFORM } from "node:process";
|
|
6
|
+
|
|
7
|
+
import progress from "cli-progress";
|
|
8
|
+
import compressing from "compressing";
|
|
9
|
+
|
|
10
|
+
import { log } from "./log.js";
|
|
11
|
+
import { PLATFORM_KV, ARCH_KV } from "./util.js";
|
|
12
|
+
import { replaceFfmpeg } from "./util/ffmpeg.js";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* _Note: This an internal function which is not called directly. Please see example usage below._
|
|
16
|
+
*
|
|
17
|
+
* Get FFMPEG binaries.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // FFMPEG (proprietary codecs)
|
|
21
|
+
* // Please read the license's constraints: https://nwjs.readthedocs.io/en/latest/For%20Developers/Enable%20Proprietary%20Codecs/#get-ffmpeg-binaries-from-the-community
|
|
22
|
+
* nwbuild({
|
|
23
|
+
* mode: "get",
|
|
24
|
+
* ffmpeg: true,
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* @param {object} options Get mode options
|
|
28
|
+
* @param {string} options.version NW.js runtime version. Defaults to "latest".
|
|
29
|
+
* @param {"normal" | "sdk"} options.flavor NW.js build flavor. Defaults to "normal".
|
|
30
|
+
* @param {"linux" | "osx" | "win"} options.platform Target platform. Defaults to host platform.
|
|
31
|
+
* @param {"ia32" | "x64" | "arm64"} options.arch Target architecture. Defaults to host architecture.
|
|
32
|
+
* @param {string} options.cacheDir Cache directory path. Defaults to "./cache"
|
|
33
|
+
* @param {boolean} options.cache If false, remove cache before download. Defaults to true.
|
|
34
|
+
* @return {Promise<void>}
|
|
35
|
+
*/
|
|
36
|
+
export async function get_ffmpeg({
|
|
37
|
+
version = "latest",
|
|
38
|
+
flavor = "normal",
|
|
39
|
+
platform = PLATFORM_KV[PLATFORM],
|
|
40
|
+
arch = ARCH_KV[ARCH],
|
|
41
|
+
cacheDir = "./cache",
|
|
42
|
+
cache = true,
|
|
43
|
+
}) {
|
|
44
|
+
log.debug(`Start getting binaries`);
|
|
45
|
+
const nwDir = resolve(
|
|
46
|
+
cacheDir,
|
|
47
|
+
`nwjs${flavor === "sdk" ? "-sdk" : ""}-v${version}-${platform}-${arch}`,
|
|
48
|
+
);
|
|
49
|
+
const bar = new progress.SingleBar({}, progress.Presets.rect);
|
|
50
|
+
|
|
51
|
+
// If options.ffmpeg is true, then download ffmpeg.
|
|
52
|
+
const downloadUrl =
|
|
53
|
+
"https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt/releases/download";
|
|
54
|
+
let url = `${downloadUrl}/${version}/${version}-${platform}-${arch}.zip`;
|
|
55
|
+
const out = resolve(cacheDir, `ffmpeg-v${version}-${platform}-${arch}.zip`);
|
|
56
|
+
|
|
57
|
+
// If options.cache is false, remove cache.
|
|
58
|
+
if (cache === false) {
|
|
59
|
+
log.debug(`Removing existing binaries`);
|
|
60
|
+
await rm(out, {
|
|
61
|
+
recursive: true,
|
|
62
|
+
force: true,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Check if cache exists.
|
|
67
|
+
if (existsSync(out)) {
|
|
68
|
+
log.debug(`Found existing FFMPEG cache`);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
log.debug(`Downloading FFMPEG`);
|
|
73
|
+
const stream = createWriteStream(out);
|
|
74
|
+
const request = new Promise((resolve, reject) => {
|
|
75
|
+
getRequest(url, (response) => {
|
|
76
|
+
log.debug(`Response from ${url}`);
|
|
77
|
+
// For GitHub releases and mirrors, we need to follow the redirect.
|
|
78
|
+
url = response.headers.location;
|
|
79
|
+
|
|
80
|
+
getRequest(url, (response) => {
|
|
81
|
+
log.debug(`Response from ${url}`);
|
|
82
|
+
let chunks = 0;
|
|
83
|
+
bar.start(Number(response.headers["content-length"]), 0);
|
|
84
|
+
response.on("data", async (chunk) => {
|
|
85
|
+
chunks += chunk.length;
|
|
86
|
+
bar.increment();
|
|
87
|
+
bar.update(chunks);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
response.on("error", (error) => {
|
|
91
|
+
reject(error);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
response.on("end", () => {
|
|
95
|
+
log.debug(`FFMPEG fully downloaded`);
|
|
96
|
+
bar.stop();
|
|
97
|
+
if (platform === "linux") {
|
|
98
|
+
compressing.tgz.uncompress(out, nwDir).then(() => resolve());
|
|
99
|
+
} else {
|
|
100
|
+
compressing.zip.uncompress(out, nwDir).then(() => resolve());
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
response.pipe(stream);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
response.on("error", (error) => {
|
|
108
|
+
reject(error);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Remove compressed file after download and decompress.
|
|
114
|
+
return request.then(async () => {
|
|
115
|
+
let ffmpegFile;
|
|
116
|
+
if (platform === "linux") {
|
|
117
|
+
ffmpegFile = "libffmpeg.so";
|
|
118
|
+
} else if (platform === "win") {
|
|
119
|
+
ffmpegFile = "ffmpeg.dll";
|
|
120
|
+
} else if (platform === "osx") {
|
|
121
|
+
ffmpegFile = "libffmpeg.dylib";
|
|
122
|
+
}
|
|
123
|
+
await replaceFfmpeg(platform, nwDir, ffmpegFile);
|
|
124
|
+
|
|
125
|
+
if (cache === false) {
|
|
126
|
+
log.debug(`Removing FFMPEG zip cache`);
|
|
127
|
+
await rm(out, {
|
|
128
|
+
recursive: true,
|
|
129
|
+
force: true,
|
|
130
|
+
});
|
|
131
|
+
log.debug(`FFMPEG zip cache removed`);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
@@ -2,14 +2,13 @@ import { createWriteStream } from "node:fs";
|
|
|
2
2
|
import { mkdir, readdir, rm, rmdir } from "node:fs/promises";
|
|
3
3
|
import { get as getRequest } from "node:https";
|
|
4
4
|
import { resolve } from "node:path";
|
|
5
|
-
import { arch as ARCH, platform as PLATFORM } from "node:process";
|
|
5
|
+
import { arch as ARCH, platform as PLATFORM, exit as EXIT } from "node:process";
|
|
6
6
|
|
|
7
7
|
import progress from "cli-progress";
|
|
8
8
|
import compressing from "compressing";
|
|
9
9
|
|
|
10
10
|
import { log } from "./log.js";
|
|
11
11
|
import { PLATFORM_KV, ARCH_KV } from "./util.js";
|
|
12
|
-
import { replaceFfmpeg } from "./util/ffmpeg.js";
|
|
13
12
|
import child_process from "child_process";
|
|
14
13
|
|
|
15
14
|
/**
|
|
@@ -24,7 +23,7 @@ import child_process from "child_process";
|
|
|
24
23
|
* });
|
|
25
24
|
*
|
|
26
25
|
* @example
|
|
27
|
-
* // Unofficial
|
|
26
|
+
* // Unofficial macOS builds (upto v0.75.0)
|
|
28
27
|
* nwbuild({
|
|
29
28
|
* mode: "get",
|
|
30
29
|
* platform: "osx",
|
|
@@ -47,14 +46,6 @@ import child_process from "child_process";
|
|
|
47
46
|
* downloadUrl: "https://cnpmjs.org/mirrors/nwjs/",
|
|
48
47
|
* });
|
|
49
48
|
*
|
|
50
|
-
* @example
|
|
51
|
-
* // FFmpeg (proprietary codecs)
|
|
52
|
-
* // Please read the license's constraints: https://nwjs.readthedocs.io/en/latest/For%20Developers/Enable%20Proprietary%20Codecs/#get-ffmpeg-binaries-from-the-community
|
|
53
|
-
* nwbuild({
|
|
54
|
-
* mode: "get",
|
|
55
|
-
* ffmpeg: true,
|
|
56
|
-
* });
|
|
57
|
-
*
|
|
58
49
|
* @param {object} options Get mode options
|
|
59
50
|
* @param {string} options.version NW.js runtime version. Defaults to "latest".
|
|
60
51
|
* @param {"normal" | "sdk"} options.flavor NW.js build flavor. Defaults to "normal".
|
|
@@ -63,10 +54,9 @@ import child_process from "child_process";
|
|
|
63
54
|
* @param {string} options.downloadUrl File server to download from. Defaults to "https://dl.nwjs.io". Set "https://npm.taobao.org/mirrors/nwjs" for China mirror or "https://cnpmjs.org/mirrors/nwjs/" for Singapore mirror.
|
|
64
55
|
* @param {string} options.cacheDir Cache directory path. Defaults to "./cache"
|
|
65
56
|
* @param {boolean} options.cache If false, remove cache before download. Defaults to true.
|
|
66
|
-
* @param {boolean} options.ffmpeg If true, download ffmpeg. Defaults to false since it contains proprietary codecs. Please read the license's constraints: https://nwjs.readthedocs.io/en/latest/For%20Developers/Enable%20Proprietary%20Codecs/#get-ffmpeg-binaries-from-the-community
|
|
67
57
|
* @return {Promise<void>}
|
|
68
58
|
*/
|
|
69
|
-
export async function
|
|
59
|
+
export async function get_nwjs({
|
|
70
60
|
version = "latest",
|
|
71
61
|
flavor = "normal",
|
|
72
62
|
platform = PLATFORM_KV[PLATFORM],
|
|
@@ -74,7 +64,6 @@ export async function get({
|
|
|
74
64
|
downloadUrl = "https://dl.nwjs.io",
|
|
75
65
|
cacheDir = "./cache",
|
|
76
66
|
cache = true,
|
|
77
|
-
ffmpeg = false,
|
|
78
67
|
}) {
|
|
79
68
|
log.debug(`Start getting binaries`);
|
|
80
69
|
let nwCached = true;
|
|
@@ -100,14 +89,6 @@ export async function get({
|
|
|
100
89
|
out = resolve(cacheDir, `nw.${platform === "linux" ? "tgz" : "zip"}`);
|
|
101
90
|
}
|
|
102
91
|
|
|
103
|
-
// If options.ffmpeg is true, then download ffmpeg.
|
|
104
|
-
if (ffmpeg === true) {
|
|
105
|
-
downloadUrl =
|
|
106
|
-
"https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt/releases/download";
|
|
107
|
-
url = `${downloadUrl}/${version}/${version}-${platform}-${arch}.zip`;
|
|
108
|
-
out = resolve(cacheDir, `ffmpeg.zip`);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
92
|
// If options.cache is false, remove cache.
|
|
112
93
|
if (cache === false) {
|
|
113
94
|
log.debug(`Removing existing binaries`);
|
|
@@ -124,7 +105,7 @@ export async function get({
|
|
|
124
105
|
}
|
|
125
106
|
|
|
126
107
|
// If not cached, then download.
|
|
127
|
-
if (nwCached === false
|
|
108
|
+
if (nwCached === false) {
|
|
128
109
|
log.debug(`Downloading binaries`);
|
|
129
110
|
await mkdir(nwDir, { recursive: true });
|
|
130
111
|
|
|
@@ -134,8 +115,6 @@ export async function get({
|
|
|
134
115
|
log.debug(`Response from ${url}`);
|
|
135
116
|
// For GitHub releases and mirrors, we need to follow the redirect.
|
|
136
117
|
if (
|
|
137
|
-
downloadUrl ===
|
|
138
|
-
"https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt/releases/download" ||
|
|
139
118
|
downloadUrl === "https://npm.taobao.org/mirrors/nwjs" ||
|
|
140
119
|
downloadUrl === "https://npmmirror.com/mirrors/nwjs"
|
|
141
120
|
) {
|
|
@@ -160,9 +139,7 @@ export async function get({
|
|
|
160
139
|
log.debug(`Binary fully downloaded`);
|
|
161
140
|
bar.stop();
|
|
162
141
|
if (platform === "linux") {
|
|
163
|
-
compressing.tgz
|
|
164
|
-
.uncompress(out, ffmpeg ? nwDir : cacheDir)
|
|
165
|
-
.then(() => resolve());
|
|
142
|
+
compressing.tgz.uncompress(out, cacheDir).then(() => resolve());
|
|
166
143
|
} else if (platform === "osx") {
|
|
167
144
|
//TODO: compressing package does not restore symlinks on some macOS (eg: circleCI)
|
|
168
145
|
const exec = function (cmd) {
|
|
@@ -174,15 +151,13 @@ export async function get({
|
|
|
174
151
|
if (result.status !== 0) {
|
|
175
152
|
log.debug(`Command failed with status ${result.status}`);
|
|
176
153
|
if (result.error) console.log(result.error);
|
|
177
|
-
|
|
154
|
+
EXIT(1);
|
|
178
155
|
}
|
|
179
156
|
return resolve();
|
|
180
157
|
};
|
|
181
|
-
exec(`unzip -o "${out}" -d "${
|
|
158
|
+
exec(`unzip -o "${out}" -d "${cacheDir}"`);
|
|
182
159
|
} else {
|
|
183
|
-
compressing.zip
|
|
184
|
-
.uncompress(out, ffmpeg ? nwDir : cacheDir)
|
|
185
|
-
.then(() => resolve());
|
|
160
|
+
compressing.zip.uncompress(out, cacheDir).then(() => resolve());
|
|
186
161
|
}
|
|
187
162
|
});
|
|
188
163
|
|
|
@@ -197,23 +172,7 @@ export async function get({
|
|
|
197
172
|
|
|
198
173
|
// Remove compressed file after download and decompress.
|
|
199
174
|
return request.then(async () => {
|
|
200
|
-
if (ffmpeg === true) {
|
|
201
|
-
let ffmpegFile;
|
|
202
|
-
if (platform === "linux") {
|
|
203
|
-
ffmpegFile = "libffmpeg.so";
|
|
204
|
-
} else if (platform === "win") {
|
|
205
|
-
ffmpegFile = "ffmpeg.dll";
|
|
206
|
-
} else if (platform === "osx") {
|
|
207
|
-
ffmpegFile = "libffmpeg.dylib";
|
|
208
|
-
}
|
|
209
|
-
await replaceFfmpeg(platform, nwDir, ffmpegFile);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
175
|
log.debug(`Binary decompressed starting removal`);
|
|
213
|
-
await rm(resolve(cacheDir, "ffmpeg.zip"), {
|
|
214
|
-
recursive: true,
|
|
215
|
-
force: true,
|
|
216
|
-
});
|
|
217
176
|
|
|
218
177
|
await rm(
|
|
219
178
|
resolve(cacheDir, `nw.${platform === "linux" ? "tgz" : "zip"}`),
|
package/src/index.js
CHANGED
|
@@ -10,7 +10,8 @@ import { getVersionManifest } from "./util/versionManifest.js";
|
|
|
10
10
|
import { parse } from "./util/parse.js";
|
|
11
11
|
import { validate } from "./util/validate.js";
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import { get_nwjs } from "./get_nwjs.js";
|
|
14
|
+
import { get_ffmpeg } from "./get_ffmpeg.js";
|
|
14
15
|
import { log, setLogLevel } from "./log.js";
|
|
15
16
|
import { getReleaseInfo } from "./util.js";
|
|
16
17
|
|
|
@@ -106,7 +107,7 @@ const nwbuild = async (options) => {
|
|
|
106
107
|
);
|
|
107
108
|
|
|
108
109
|
// Download NW.js binaries
|
|
109
|
-
await
|
|
110
|
+
await get_nwjs({
|
|
110
111
|
version: options.version,
|
|
111
112
|
flavor: options.flavor,
|
|
112
113
|
platform: options.platform,
|
|
@@ -114,20 +115,17 @@ const nwbuild = async (options) => {
|
|
|
114
115
|
downloadUrl: options.downloadUrl,
|
|
115
116
|
cacheDir: options.cacheDir,
|
|
116
117
|
cache: options.cache,
|
|
117
|
-
ffmpeg: false,
|
|
118
118
|
});
|
|
119
119
|
|
|
120
120
|
// Download ffmpeg binaries and replace chromium ffmpeg
|
|
121
121
|
if (options.ffmpeg === true) {
|
|
122
|
-
await
|
|
122
|
+
await get_ffmpeg({
|
|
123
123
|
version: options.version,
|
|
124
124
|
flavor: options.flavor,
|
|
125
125
|
platform: options.platform,
|
|
126
126
|
arch: options.arch,
|
|
127
|
-
downloadUrl: options.downloadUrl,
|
|
128
127
|
cacheDir: options.cacheDir,
|
|
129
128
|
cache: options.cache,
|
|
130
|
-
ffmpeg: true,
|
|
131
129
|
});
|
|
132
130
|
}
|
|
133
131
|
|
|
@@ -155,7 +153,6 @@ const nwbuild = async (options) => {
|
|
|
155
153
|
options.platform,
|
|
156
154
|
options.zip,
|
|
157
155
|
options.app,
|
|
158
|
-
manifest,
|
|
159
156
|
);
|
|
160
157
|
}
|
|
161
158
|
} catch (error) {
|