nw-builder 4.3.4 → 4.3.6

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,6 +1,6 @@
1
1
  {
2
2
  "name": "nw-builder",
3
- "version": "4.3.4",
3
+ "version": "4.3.6",
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,5 +1,4 @@
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";
@@ -8,17 +7,9 @@ import { arch as ARCH, platform as PLATFORM } from "node:process";
8
7
  import progress from "cli-progress";
9
8
  import compressing from "compressing";
10
9
 
11
- const PLATFORM_KV = {
12
- darwin: "osx",
13
- linux: "linux",
14
- win32: "win",
15
- };
16
-
17
- const ARCH_KV = {
18
- x64: "x64",
19
- ia32: "ia32",
20
- arm64: "arm64",
21
- };
10
+ import { log } from "./log.js";
11
+ import { PLATFORM_KV, ARCH_KV } from "./util.js";
12
+ import { replaceFfmpeg } from "./util/ffmpeg.js";
22
13
 
23
14
  /**
24
15
  * _Note: This an internal function which is not called directly. Please see example usage below._
@@ -54,7 +45,7 @@ const ARCH_KV = {
54
45
  * mode: "get",
55
46
  * downloadUrl: "https://cnpmjs.org/mirrors/nwjs/",
56
47
  * });
57
- *
48
+ *
58
49
  * @example
59
50
  * // FFmpeg (proprietary codecs)
60
51
  * // Please read the license's constraints: https://nwjs.readthedocs.io/en/latest/For%20Developers/Enable%20Proprietary%20Codecs/#get-ffmpeg-binaries-from-the-community
@@ -84,6 +75,7 @@ export async function get({
84
75
  cache = true,
85
76
  ffmpeg = false,
86
77
  }) {
78
+ log.debug(`Start getting binaries`);
87
79
  let nwCached = true;
88
80
  const nwDir = resolve(
89
81
  cacheDir,
@@ -117,23 +109,28 @@ export async function get({
117
109
 
118
110
  // If options.cache is false, remove cache.
119
111
  if (cache === false) {
112
+ log.debug(`Removing existing binaries`);
120
113
  rmdir(nwDir, { recursive: true, force: true });
121
114
  }
122
115
 
123
116
  // Check if cache exists.
124
117
  try {
125
118
  await readdir(nwDir);
119
+ log.debug(`Found existing binaries`);
126
120
  } catch (error) {
121
+ log.debug(`No existing binaries`);
127
122
  nwCached = false;
128
123
  }
129
124
 
130
125
  // If not cached, then download.
131
- if (nwCached === false) {
126
+ if (nwCached === false || ffmpeg === true) {
127
+ log.debug(`Downloading binaries`);
132
128
  await mkdir(nwDir, { recursive: true });
133
129
 
134
130
  const stream = createWriteStream(out);
135
131
  const request = new Promise((resolve, reject) => {
136
132
  getRequest(url, (response) => {
133
+ log.debug(`Response from ${url}`);
137
134
  // For GitHub releases and mirrors, we need to follow the redirect.
138
135
  if (
139
136
  downloadUrl ===
@@ -145,6 +142,7 @@ export async function get({
145
142
  }
146
143
 
147
144
  getRequest(url, (response) => {
145
+ log.debug(`Response from ${url}`);
148
146
  let chunks = 0;
149
147
  bar.start(Number(response.headers["content-length"]), 0);
150
148
  response.on("data", async (chunk) => {
@@ -158,6 +156,7 @@ export async function get({
158
156
  });
159
157
 
160
158
  response.on("end", () => {
159
+ log.debug(`Binary fully downloaded`);
161
160
  bar.stop();
162
161
  if (platform === "linux") {
163
162
  compressing.tgz
@@ -180,7 +179,12 @@ export async function get({
180
179
  });
181
180
 
182
181
  // Remove compressed file after download and decompress.
183
- request.then(async () => {
182
+ return request.then(async () => {
183
+ if (ffmpeg === true) {
184
+ await replaceFfmpeg(platform, nwDir, out);
185
+ }
186
+
187
+ log.debug(`Binary decompressed starting removal`);
184
188
  await rm(resolve(cacheDir, "ffmpeg.zip"), {
185
189
  recursive: true,
186
190
  force: true,
@@ -190,6 +194,7 @@ export async function get({
190
194
  resolve(cacheDir, `nw.${platform === "linux" ? "tgz" : "zip"}`),
191
195
  { recursive: true, force: true },
192
196
  );
197
+ log.debug(`Binary zip removed`);
193
198
  });
194
199
  }
195
200
  }
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 { develop } from "./run/develop.js";
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 develop(
141
- options.srcDir,
142
- nwDir,
143
- options.platform,
144
- options.argv,
145
- options.glob,
146
- );
147
- }
148
- else if (options.mode === "build") {
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.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
+ };
@@ -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 };
@@ -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 };