- import child_process from "node:child_process";
-import console from "node:console";
-import fs from "node:fs";
+ import fs from "node:fs";
import fsm from "node:fs/promises";
import https from "node:https";
import path from "node:path";
@@ -176,8 +174,8 @@ Source: get.js
options.downloadUrl === "https://npmmirror.com/mirrors/nwjs"
) {
url = `${options.downloadUrl}/v${options.version}/nwjs${options.flavor === "sdk" ? "-sdk" : ""
- }-v${options.version}-${options.platform}-${options.arch}.${options.platform === "linux" ? "tar.gz" : "zip"
- }`;
+ }-v${options.version}-${options.platform}-${options.arch}.${options.platform === "linux" ? "tar.gz" : "zip"
+ }`;
}
https.get(url, (response) => {
@@ -338,20 +336,7 @@ Source: get.js
path.resolve(options.cacheDir, "node"),
path.resolve(options.cacheDir, `node-v${options.version}-${options.platform}-${options.arch}`),
);
-
- child_process.exec(
- "patch " +
- path.resolve(
- options.cacheDir,
- `node-v${options.version}-${options.platform}-${options.arch}`,
- "common.gypi",
- ) +
- " " +
- path.resolve("..", "..", "patches", "node_header.patch"),
- (error) => {
- console.error(error);
- },
- );
+ return;
}
const stream = fs.createWriteStream(out);
@@ -417,13 +402,13 @@ Source: get.js
- Global
+ Global
- Documentation generated by JSDoc 4.0.2 on Tue Dec 26 2023 16:38:03 GMT+0530 (India Standard Time)
+ Documentation generated by JSDoc 4.0.2 on Sun Jan 21 2024 18:15:08 GMT-0500 (Eastern Standard Time)
diff --git a/docs/global.html b/docs/global.html
index 4b2d1c126..2d31b0c9b 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -160,7 +160,7 @@ Parameters:
-
+ Build options
@@ -201,7 +201,7 @@ Parameters:
Source:
@@ -279,8 +279,7 @@ Examples
});
// Rebuild Node native modules
-// This behaviour is currently disabled.
-// Tracking issue: https://github.com/nwutils/nw-builder/pull/993
+// This assumes you have a binding.gyp file in your options.srcDir.
nwbuild({
mode: "build",
nodeAddon: "gyp"
@@ -398,7 +397,7 @@ Parameters:
Source:
@@ -500,6 +499,196 @@ Examples
+ (async) nwbuild(options) → {Promise.<undefined>}
+
+
+
+
+
+
+
+ Installation Guide
+
+Every NW.js release includes a modified Node.js binary at a specific version. It is recommended to [install](https://nodejs.org/en/download/package-manager) exactly that version on the host system. Not doing so may download ABI incompatible Node modules. Consult the NW.js [versions manifest](https://nwjs.io/versions) for what Node.js version to install. It is recommended to use a Node version manager (such as [volta](https://volta.sh), n, nvm, or nvm-windows) to be able to easily install and switch between Node versions.
+
+Please refer to the examples below for basic usage.
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+Options
+
+
+
+
+
+
+
+
+
+ Options
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+
+
+ Type
+
+
+
+Promise.<undefined>
+
+
+
+
+
+
+
+
+
+
+ Examples
+
+ // ESM usage:
+
+import nwbuild from "nw-builder";
+
+ // CJS usage
+
+let nwbuild = undefined;
+
+(() => {
+try {
+nwbuild = await import("nw-builder");
+} catch(error) {
+console.error(error);
+}
+})();
+
+ // Module usage
+
+nwbuild();
+
+ // CLI usage
+
+npx nwbuild
+
+ // Node manifest usage
+
+"nwbuild": {}
+
+
+
+
+
+
+
+
+
(async) run(options) → {Promise.<void>}
@@ -1728,7 +1917,7 @@ Properties:
Source:
@@ -2354,6 +2543,788 @@ Properties:
+Options
+
+
+
+
+
+ Configuration options
+
+
+
+
+ Type:
+
+
+
+
+
+
+ Properties:
+
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+ Attributes
+
+
+
+ Default
+
+
+ Description
+
+
+
+
+
+
+
+
+ srcDir
+
+
+
+
+
+"./"
+|
+
+string
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ "./"
+
+
+
+
+ String of space separated glob patterns which correspond to NW app code
+
+
+
+
+
+
+ mode
+
+
+
+
+
+"get"
+|
+
+"run"
+|
+
+"build"
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ "build"
+
+
+
+
+ Run or build application
+
+
+
+
+
+
+ version
+
+
+
+
+
+"latest"
+|
+
+"stable"
+|
+
+string
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ "latest"
+
+
+
+
+ NW runtime version
+
+
+
+
+
+
+ flavor
+
+
+
+
+
+"normal"
+|
+
+"sdk"
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ "normal"
+
+
+
+
+ NW runtime build flavor
+
+
+
+
+
+
+ platform
+
+
+
+
+
+"linux"
+|
+
+"osx"
+|
+
+"win"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ NW supported platforms
+
+
+
+
+
+
+ arch
+
+
+
+
+
+"ia32"
+|
+
+"x64"
+|
+
+"arm64"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ NW supported architectures
+
+
+
+
+
+
+ outDir
+
+
+
+
+
+"./out"
+|
+
+string
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ "./out"
+
+
+
+
+ Directory to store build artifacts
+
+
+
+
+
+
+ cacheDir
+
+
+
+
+
+"./cache"
+|
+
+string
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ "./cache"
+
+
+
+
+ Directory to store NW binaries
+
+
+
+
+
+
+ downloadUrl
+
+
+
+
+
+"https://dl.nwjs.io"
+|
+
+string
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ "https://dl.nwjs.io"
+
+
+
+
+ URI to download NW binaries from
+
+
+
+
+
+
+ manifestUrl
+
+
+
+
+
+"https://nwjs.io/versions"
+|
+
+string
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ "https://nwjs.io/versions"
+
+
+
+
+ URI to download manifest from
+
+
+
+
+
+
+ app
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Refer to Linux/Windows Specific Options under Getting Started in the docs
+
+
+
+
+
+
+ cache
+
+
+
+
+
+boolean
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ true
+
+
+
+
+ If true the existing cache is used. Otherwise it removes and redownloads it.
+
+
+
+
+
+
+ zip
+
+
+
+
+
+boolean
+|
+
+"zip"
+|
+
+"tar"
+|
+
+"tgz"
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ false
+
+
+
+
+ If true, "zip", "tar" or "tgz" the outDir directory is compressed.
+
+
+
+
+
+
+ cli
+
+
+
+
+
+boolean
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ false
+
+
+
+
+ If true the CLI is used to glob srcDir and parse other options
+
+
+
+
+
+
+ ffmpeg
+
+
+
+
+
+boolean
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ false
+
+
+
+
+ If true the chromium ffmpeg is replaced by community version
+
+
+
+
+
+
+ glob
+
+
+
+
+
+boolean
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ true
+
+
+
+
+ If true globbing is enabled
+
+
+
+
+
+
+ logLevel
+
+
+
+
+
+"error"
+|
+
+"warn"
+|
+
+"info"
+|
+
+"debug"
+
+
+
+
+
+
+
+
+ <optional>
+
+
+
+
+
+
+
+
+
+ "info"
+
+
+
+
+ Specified log level.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
OsxRc
@@ -3565,13 +4536,13 @@ Properties:
- Global
+ Global
- Documentation generated by JSDoc 4.0.2 on Tue Dec 26 2023 16:38:03 GMT+0530 (India Standard Time)
+ Documentation generated by JSDoc 4.0.2 on Sun Jan 21 2024 18:15:08 GMT-0500 (Eastern Standard Time)
diff --git a/docs/index.html b/docs/index.html
index de370ad05..a20e7c2e9 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -119,13 +119,13 @@ Alternatives
- Global
+ Global
- Documentation generated by JSDoc 4.0.2 on Tue Dec 26 2023 16:38:03 GMT+0530 (India Standard Time)
+ Documentation generated by JSDoc 4.0.2 on Sun Jan 21 2024 18:15:08 GMT-0500 (Eastern Standard Time)
diff --git a/docs/index.js.html b/docs/index.js.html
new file mode 100644
index 000000000..929db0aa1
--- /dev/null
+++ b/docs/index.js.html
@@ -0,0 +1,221 @@
+
+
+
+
+ JSDoc: Source: index.js
+
+
+
+
+
+
+
+
+
+
+
+
+
Source: index.js
+
+
+
+
+
+
+
+
+ import console from "node:console";
+import fs from "node:fs";
+import fsm from "node:fs/promises";
+
+import bld from "./bld.js";
+import get from "./get.js";
+import run from "./run.js";
+import util from "./util.js";
+
+/**
+ * @typedef {object} Options Configuration options
+ * @property {"./" | string} [srcDir="./"] String of space separated glob patterns which correspond to NW app code
+ * @property {"get" | "run" | "build"} [mode="build"] Run or build application
+ * @property {"latest" | "stable" | string} [version="latest"] NW runtime version
+ * @property {"normal" | "sdk"} [flavor="normal"] NW runtime build flavor
+ * @property {"linux" | "osx" | "win"} platform NW supported platforms
+ * @property {"ia32" | "x64" | "arm64"} arch NW supported architectures
+ * @property {"./out" | string} [outDir="./out"] Directory to store build artifacts
+ * @property {"./cache" | string} [cacheDir="./cache"] Directory to store NW binaries
+ * @property {"https://dl.nwjs.io" | string} [downloadUrl="https://dl.nwjs.io"] URI to download NW binaries from
+ * @property {"https://nwjs.io/versions" | string} [manifestUrl="https://nwjs.io/versions"] URI to download manifest from
+ * @property {object} app Refer to Linux/Windows Specific Options under Getting Started in the docs
+ * @property {boolean} [cache=true] If true the existing cache is used. Otherwise it removes and redownloads it.
+ * @property {boolean | "zip" | "tar" | "tgz"} [zip=false] If true, "zip", "tar" or "tgz" the outDir directory is compressed.
+ * @property {boolean} [cli=false] If true the CLI is used to glob srcDir and parse other options
+ * @property {boolean} [ffmpeg=false] If true the chromium ffmpeg is replaced by community version
+ * @property {boolean} [glob=true] If true globbing is enabled
+ * @property {"error" | "warn" | "info" | "debug"} [logLevel="info"] Specified log level.
+ */
+
+/**
+ * Installation Guide
+ *
+ * Every NW.js release includes a modified Node.js binary at a specific version. It is recommended to [install](https://nodejs.org/en/download/package-manager) exactly that version on the host system. Not doing so may download ABI incompatible Node modules. Consult the NW.js [versions manifest](https://nwjs.io/versions) for what Node.js version to install. It is recommended to use a Node version manager (such as [volta](https://volta.sh), n, nvm, or nvm-windows) to be able to easily install and switch between Node versions.
+ *
+ * Please refer to the examples below for basic usage.
+ *
+ * @example
+ * // ESM usage:
+ *
+ * import nwbuild from "nw-builder";
+ *
+ * @example
+ * // CJS usage
+ *
+ * let nwbuild = undefined;
+ *
+ * (() => {
+ * try {
+ * nwbuild = await import("nw-builder");
+ * } catch(error) {
+ * console.error(error);
+ * }
+ * })();
+ *
+ * @example
+ * // Module usage
+ *
+ * nwbuild();
+ *
+ * @example
+ * // CLI usage
+ *
+ * npx nwbuild
+ *
+ * @example
+ * // Node manifest usage
+ *
+ * "nwbuild": {}
+ *
+ * @param {Options} options Options
+ * @returns {Promise<undefined>}
+ */
+const nwbuild = async (options) => {
+ let built;
+ let releaseInfo = {};
+ let manifest = {};
+
+ try {
+ // Parse options
+ options = await util.parse(options, manifest);
+
+ manifest = await util.getNodeManifest({ srcDir: options.srcDir, glob: options.glob });
+ if (typeof manifest?.nwbuild === "object") {
+ options = manifest.nwbuild;
+ }
+
+ options = await util.parse(options, manifest);
+
+ //TODO: impl logging
+
+ built = fs.existsSync(options.cacheDir);
+ if (built === false) {
+ await fsm.mkdir(options.cacheDir, { recursive: true });
+ }
+
+ if (options.mode === "build") {
+ built = fs.existsSync(options.outDir);
+ if (built === false) {
+ await fsm.mkdir(options.outDir, { recursive: true });
+ }
+ }
+
+ // Validate options.version to get the version specific release info
+ releaseInfo = await util.getReleaseInfo(
+ options.version,
+ options.platform,
+ options.arch,
+ options.cacheDir,
+ options.manifestUrl,
+ );
+
+ await util.validate(options, releaseInfo);
+
+ // Remove leading "v" from version string
+ options.version = releaseInfo.version.slice(1);
+
+ // Download binaries
+ await get({
+ version: options.version,
+ flavor: options.flavor,
+ platform: options.platform,
+ arch: options.arch,
+ downloadUrl: options.downloadUrl,
+ cacheDir: options.cacheDir,
+ cache: options.cache,
+ ffmpeg: options.ffmpeg,
+ nativeAddon: options.nativeAddon,
+ });
+
+ if (options.mode === "get") {
+ // Do nothing else since we have already downloaded the binaries.
+ return;
+ }
+
+ if (options.mode === "run") {
+ await run({
+ version: options.version,
+ flavor: options.flavor,
+ platform: options.platform,
+ arch: options.arch,
+ srcDir: options.srcDir,
+ cacheDir: options.cacheDir,
+ glob: options.glob,
+ argv: options.argv,
+ });
+ } else if (options.mode === "build") {
+ await bld({
+ version: options.version,
+ flavor: options.flavor,
+ platform: options.platform,
+ arch: options.arch,
+ manifestUrl: options.manifestUrl,
+ srcDir: options.srcDir,
+ cacheDir: options.cacheDir,
+ outDir: options.outDir,
+ app: options.app,
+ glob: options.glob,
+ managedManifest: options.managedManifest,
+ nativeAddon: options.nativeAddon,
+ zip: options.zip,
+ });
+ }
+ } catch (error) {
+ console.error(error);
+ throw error;
+ }
+};
+
+export default nwbuild;
+
+
+
+
+
+
+
+
+
+
+ Global
+
+
+
+
+
+ Documentation generated by JSDoc 4.0.2 on Sun Jan 21 2024 18:15:08 GMT-0500 (Eastern Standard Time)
+
+
+
+
+
+
diff --git a/docs/run.js.html b/docs/run.js.html
index dfb3de003..6aa6bc0eb 100644
--- a/docs/run.js.html
+++ b/docs/run.js.html
@@ -51,7 +51,7 @@ Source: run.js
* @async
* @function
* @param {RunOptions} options Run mode options
- * @return {Promise<void>}
+ * @returns {Promise<void>}
*
* @example
* // Minimal Usage (uses default values)
@@ -118,13 +118,13 @@ Source: run.js
- Global
+ Global
- Documentation generated by JSDoc 4.0.2 on Tue Dec 26 2023 16:38:03 GMT+0530 (India Standard Time)
+ Documentation generated by JSDoc 4.0.2 on Sun Jan 21 2024 18:15:08 GMT-0500 (Eastern Standard Time)
diff --git a/package.json b/package.json
index 28e74ba35..e99771cc9 100644
--- a/package.json
+++ b/package.json
@@ -42,7 +42,7 @@
},
"scripts": {
"lint": "eslint ./**/*.js",
- "docs": "jsdoc -d docs ./README.md ./src/get.js ./src/run.js ./src/bld.js",
+ "docs": "jsdoc -d docs ./README.md ./src/index.js ./src/get.js ./src/run.js ./src/bld.js",
"test": "node --test test/*.test.js",
"demo": "cd test/fixture && node demo.js"
},