nw-builder 4.2.0 → 4.2.2

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 CHANGED
@@ -12,98 +12,6 @@ Build [NW.js](https://github.com/nwjs/nw.js) applications for Mac, Windows and L
12
12
  - Integrate [`nwjs-ffmpeg-prebuilt`](https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt)
13
13
  - Configure executable fields and icons
14
14
 
15
- ## Installation
15
+ Check out the [documentation](https://nwutils.io/nw-builder/) if you wish to give `nw-builder` a try.
16
16
 
17
- Install `nw-builder` via `npm` or your preferred Node package manager of choice.
18
-
19
- ```shell
20
- npm i -D nw-builder
21
- ```
22
-
23
- ## Usage
24
-
25
- ### Run your first application
26
-
27
- Module usage
28
-
29
- ```javascript
30
- import nwbuild from "nw-builder";
31
-
32
- nwbuild({
33
- srcDir: "./nwapp/*",
34
- mode: "run",
35
- version: "latest",
36
- flavor: "sdk",
37
- });
38
- ```
39
-
40
- CLI usage
41
-
42
- ```shell
43
- nwbuild ./nwapp/* --mode=run --version=latest --flavor=sdk
44
- ```
45
-
46
- package.json usage
47
-
48
- `./nwapp/package.json`
49
-
50
- ```json
51
- {
52
- "name": "nwdemo",
53
- "main": "./index.html",
54
- "nwbuild": {
55
- "srcDir": "./nwapp/*",
56
- "mode": "run",
57
- "version": "latest",
58
- "flavor": "sdk"
59
- }
60
- }
61
- ```
62
-
63
- ### Build your first application
64
-
65
- Module usage
66
-
67
- ```javascript
68
- import nwbuild from "nw-builder";
69
-
70
- nwbuild({
71
- srcDir: "./nwapp/*",
72
- mode: "build",
73
- version: "latest",
74
- flavor: "normal",
75
- platform: "linux",
76
- arch: "x64",
77
- outDir: "./out",
78
- });
79
- ```
80
-
81
- CLI usage
82
-
83
- ```shell
84
- nwbuild ./nwapp/* --mode=build --version=latest --flavor=normal --platform=linux --arch=x64 --outDir=./out
85
- ```
86
-
87
- package.json usage
88
-
89
- `./nwapp/package.json`
90
-
91
- ```json
92
- {
93
- "name": "nwdemo",
94
- "main": "./index.html",
95
- "nwbuild": {
96
- "srcDir": "./nwapp/*",
97
- "mode": "build",
98
- "version": "latest",
99
- "flavor": "normal",
100
- "platform": "linux",
101
- "arch": "x64",
102
- "outDir": "./out"
103
- }
104
- }
105
- ```
106
-
107
- ## Limitations
108
-
109
- - #716 File permissions are incorrectly set for Linux or MacOS apps built on Windows platform.
17
+ > Please note that the documentation assumes you know [how to write NW.js applications](https://nwjs.readthedocs.io/en/latest/For%20Users/Getting%20Started/).
@@ -10,7 +10,7 @@ import { develop } from "./run/develop.js";
10
10
  import { isCached } from "./util/cache.js";
11
11
  import { replaceFfmpeg } from "./util/ffmpeg.js";
12
12
  import { getFiles } from "./util/files.js";
13
- import { getManifest } from "./util/manifest.js";
13
+ import { getVersionManifest } from "./util/versionManifest.js";
14
14
  import { parse } from "./util/parse.js";
15
15
  import { validate } from "./util/validate.js";
16
16
  import { xattr } from "./util/xattr.js";
@@ -18,7 +18,7 @@ import { xattr } from "./util/xattr.js";
18
18
  import { log } from "./log.js";
19
19
 
20
20
  /**
21
- * @typedef {object} App
21
+ * @typedef {object} APP
22
22
  * @property {string} name Name of the application
23
23
  * Linux configuration options
24
24
  * @property {string} genericName Generic name of the application
@@ -58,7 +58,7 @@ import { log } from "./log.js";
58
58
  */
59
59
 
60
60
  /**
61
- * @typedef {object} Options
61
+ * @typedef {object} OPTIONS
62
62
  * @property {string} [srcDir="./"] String of space separated glob patterns which correspond to NW app code
63
63
  * @property {"get" | "run" | "build"} [mode="build"] Run or build application
64
64
  * @property {"latest" | "stable" | string} [version="latest"] NW runtime version
@@ -69,7 +69,7 @@ import { log } from "./log.js";
69
69
  * @property {"./cache" | string} [cacheDir="./cache"] Directory to store NW binaries
70
70
  * @property {"https://dl.nwjs.io" | "https://npmmirror.com/mirrors/nwjs" | "https://npm.taobao.org/mirrors/nwjs"} [downloadUrl="https://dl.nwjs.io"] URI to download NW binaries from
71
71
  * @property {"https://nwjs.io/versions"} [manifestUrl="https://nwjs.io/versions"] URI to download manifest from
72
- * @property {App} app Multi platform configuration options
72
+ * @property {APP} app Multi platform configuration options
73
73
  * @property {boolean} [cache=true] If true the existing cache is used. Otherwise it removes and redownloads it.
74
74
  * @property {boolean} [zip=false] If true the outDir directory is zipped
75
75
  * @property {boolean} [cli=false] If true the CLI is used to glob srcDir and parse other options
@@ -78,9 +78,9 @@ import { log } from "./log.js";
78
78
  */
79
79
 
80
80
  /**
81
- * Entry point for nw-builder application
81
+ * Automates building an NW.js application.
82
82
  *
83
- * @param {...Options} options Options
83
+ * @param {OPTIONS} options NW-Builder user options
84
84
  * @return {Promise<undefined>}
85
85
  */
86
86
  const nwbuild = async (options) => {
@@ -98,8 +98,8 @@ const nwbuild = async (options) => {
98
98
  options = await parse(options, manifest);
99
99
 
100
100
  if (options.mode !== "get") {
101
- files = await getFiles(options.srcDir);
102
- manifest = await getManifest(files, options.glob);
101
+ files = options.glob ? await getFiles(options.srcDir) : options.srcDir;
102
+ manifest = await getVersionManifest(files, options.glob);
103
103
  if (typeof manifest?.nwbuild === "object") {
104
104
  options = manifest.nwbuild;
105
105
  }
@@ -129,16 +129,16 @@ const nwbuild = async (options) => {
129
129
  options.cacheDir,
130
130
  options.manifestUrl,
131
131
  );
132
- // Remove leading "v" from version string
133
- options.version = releaseInfo.version.slice(1);
134
132
 
135
133
  await validate(options, releaseInfo);
136
134
 
135
+ // Remove leading "v" from version string
136
+ options.version = releaseInfo.version.slice(1);
137
+
137
138
  // Variable to store nwDir file path
138
139
  nwDir = resolve(
139
140
  options.cacheDir,
140
- `nwjs${options.flavor === "sdk" ? "-sdk" : ""}-v${options.version}-${
141
- options.platform
141
+ `nwjs${options.flavor === "sdk" ? "-sdk" : ""}-v${options.version}-${options.platform
142
142
  }-${options.arch}`,
143
143
  );
144
144
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nw-builder",
3
- "version": "4.2.0",
3
+ "version": "4.2.2",
4
4
  "description": "Build NW.js desktop applications for MacOS, Windows and Linux.",
5
5
  "keywords": [
6
6
  "NW.js",
@@ -26,10 +26,12 @@
26
26
  ],
27
27
  "license": "MIT",
28
28
  "exports": {
29
- "default": "./src/nwbuild.js"
29
+ "default": "./index.js",
30
+ "types": "./index.d.ts"
30
31
  },
31
32
  "type": "module",
32
33
  "files": [
34
+ "./index.js",
33
35
  "./src",
34
36
  "./LICENSE"
35
37
  ],
@@ -41,16 +43,16 @@
41
43
  "scripts": {
42
44
  "fmt": "prettier --write \"./**/*.{css,html,js,json,md,yml}\"",
43
45
  "lnt": "eslint --fix ./src",
44
- "doc:js": "jsdoc ./src/nwbuild.js -d jsdocs",
46
+ "doc:js": "jsdoc ./index.js -d jsdocs",
45
47
  "doc:dev": "vitepress dev docs",
46
48
  "doc:bld": "vitepress build docs",
47
49
  "doc:pkg": "gh-pages -d docs/.vitepress/dist",
48
50
  "test:jest": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
49
51
  "test:unit": "node --test-reporter=spec --test test/unit/index.js",
50
52
  "test:e2e": "node --test-reporter=spec --test e2e/index.js",
51
- "test:manual:get": "cd test/fixture && nwbuild --mode=get",
52
- "test:manual:dev": "cd test/fixture && nwbuild --mode=run ./app --no-glob",
53
- "test:manual:bld": "cd test/fixture && nwbuild --mode=build ./app --no-glob"
53
+ "test:manual:get": "cd test/fixture && nwbuild --mode=get --version=0.74.0",
54
+ "test:manual:dev": "cd test/fixture && nwbuild --mode=run --version=0.74.0 ./app --no-glob",
55
+ "test:manual:bld": "cd test/fixture && nwbuild --mode=build --version=0.74.0 ./app --no-glob"
54
56
  },
55
57
  "devDependencies": {
56
58
  "eslint": "^8.36.0",
@@ -68,7 +70,7 @@
68
70
  "archiver": "^5.3.1",
69
71
  "cli-progress": "^3.12.0",
70
72
  "decompress": "^4.2.1",
71
- "glob-promise": "^6.0.2",
73
+ "glob": "^9.3.4",
72
74
  "plist": "^3.0.6",
73
75
  "rcedit": "^3.0.1",
74
76
  "winston": "^3.8.2",
package/src/cli.js CHANGED
@@ -3,7 +3,7 @@
3
3
  import yargs from "yargs/yargs";
4
4
  import { hideBin } from "yargs/helpers";
5
5
 
6
- import nwbuild from "./nwbuild.js";
6
+ import nwbuild from "../index.js";
7
7
 
8
8
  const cli = yargs(hideBin(process.argv))
9
9
  .version(false)
package/src/util/files.js CHANGED
@@ -1,4 +1,4 @@
1
- import glob from "glob-promise";
1
+ import glob from "glob";
2
2
 
3
3
  /**
4
4
  * Get file paths from a srcDir glob pattern
package/src/util/parse.js CHANGED
@@ -7,11 +7,12 @@ import { getPlatform } from "./platform.js";
7
7
  /**
8
8
  * Parse options
9
9
  *
10
- * @param {import("../nwbuild").Options} options Options
11
- * @param {object} pkg Package.json as JSON
12
- * @return {Promise<object>} Options
10
+ * @param {import("../../index.js").OPTIONS} options Options
11
+ * @param {object} pkg Package.json as JSON
12
+ * @return {Promise<object>} Options
13
13
  */
14
14
  export const parse = async (options, pkg) => {
15
+ options = options ?? {};
15
16
  options.mode = options.mode ?? "build";
16
17
 
17
18
  options.version = options.version ?? "latest";
@@ -40,43 +41,49 @@ export const parse = async (options, pkg) => {
40
41
  options.zip = options.zip ?? false;
41
42
 
42
43
  options.app = options.app ?? {};
43
- // linux desktop entry file configurations options
44
- options.app.name = options.app.name ?? pkg.name;
45
- options.app.genericName = options.app.genericName ?? undefined;
46
- options.app.noDisplay = options.app.noDisplay ?? undefined;
47
- options.app.comment = options.app.comment ?? undefined;
48
- options.app.icon = options.app.icon ?? undefined;
49
- options.app.hidden = options.app.hidden ?? undefined;
50
- options.app.onlyShowIn = options.app.onlyShowIn ?? undefined;
51
- options.app.notShowIn = options.app.notShowIn ?? undefined;
52
- options.app.dBusActivatable = options.app.dBusActivatable ?? undefined;
53
- options.app.tryExec = options.app.tryExec ?? undefined;
54
- options.app.exec = options.app.name ?? undefined;
55
- options.app.path = options.app.path ?? undefined;
56
- options.app.terminal = options.app.terminal ?? undefined;
57
- options.app.actions = options.app.actions ?? undefined;
58
- options.app.mimeType = options.app.mimeType ?? undefined;
59
- options.app.categories = options.app.categories ?? undefined;
60
- options.app.implements = options.app.implements ?? undefined;
61
- options.app.keywords = options.app.keywords ?? undefined;
62
- options.app.startupNotify = options.app.startupNotify ?? undefined;
63
- options.app.startupWMClass = options.app.startupWMClass ?? undefined;
64
- options.app.prefersNonDefaultGPU =
65
- options.app.prefersNonDefaultGPU ?? undefined;
66
- options.app.singleMainWindow = options.app.singleMainWindow ?? undefined;
67
- // windows configuration options
68
- options.app.comments = options.app.comments ?? undefined;
69
- options.app.company = options.app.company ?? pkg.author;
70
- options.app.fileDescription = options.app.fileDescription ?? pkg.description;
71
- options.app.fileVersion = options.app.fileVersion ?? pkg.version;
72
- options.app.internalName = options.app.internalName ?? pkg.name;
73
- options.app.legalCopyright = options.app.legalCopyright ?? undefined;
74
- options.app.legalTrademark = options.app.legalTrademark ?? undefined;
75
- options.app.originalFilename = options.app.originalFilename ?? pkg.name;
76
- options.app.privateBuild = options.app.privateBuild ?? undefined;
77
- options.app.productName = options.app.productName ?? pkg.name;
78
- options.app.productVersion = options.app.productVersion ?? pkg.version;
79
- options.app.specialBuild = options.app.specialBuild ?? undefined;
44
+
45
+ // TODO: move this out to
46
+ if (options.platform === "linux") {
47
+ // linux desktop entry file configurations options
48
+ options.app.name = options.app.name ?? pkg.name;
49
+ options.app.genericName = options.app.genericName ?? undefined;
50
+ options.app.noDisplay = options.app.noDisplay ?? undefined;
51
+ options.app.comment = options.app.comment ?? undefined;
52
+ options.app.icon = options.app.icon ?? undefined;
53
+ options.app.hidden = options.app.hidden ?? undefined;
54
+ options.app.onlyShowIn = options.app.onlyShowIn ?? undefined;
55
+ options.app.notShowIn = options.app.notShowIn ?? undefined;
56
+ options.app.dBusActivatable = options.app.dBusActivatable ?? undefined;
57
+ options.app.tryExec = options.app.tryExec ?? undefined;
58
+ options.app.exec = options.app.name ?? undefined;
59
+ options.app.path = options.app.path ?? undefined;
60
+ options.app.terminal = options.app.terminal ?? undefined;
61
+ options.app.actions = options.app.actions ?? undefined;
62
+ options.app.mimeType = options.app.mimeType ?? undefined;
63
+ options.app.categories = options.app.categories ?? undefined;
64
+ options.app.implements = options.app.implements ?? undefined;
65
+ options.app.keywords = options.app.keywords ?? undefined;
66
+ options.app.startupNotify = options.app.startupNotify ?? undefined;
67
+ options.app.startupWMClass = options.app.startupWMClass ?? undefined;
68
+ options.app.prefersNonDefaultGPU =
69
+ options.app.prefersNonDefaultGPU ?? undefined;
70
+ options.app.singleMainWindow = options.app.singleMainWindow ?? undefined;
71
+ }
72
+ if (options.platform === "win") {
73
+ // windows configuration options
74
+ options.app.comments = options.app.comments ?? undefined;
75
+ options.app.company = options.app.company ?? pkg.author;
76
+ options.app.fileDescription = options.app.fileDescription ?? pkg.description;
77
+ options.app.fileVersion = options.app.fileVersion ?? pkg.version;
78
+ options.app.internalName = options.app.internalName ?? pkg.name;
79
+ options.app.legalCopyright = options.app.legalCopyright ?? undefined;
80
+ options.app.legalTrademark = options.app.legalTrademark ?? undefined;
81
+ options.app.originalFilename = options.app.originalFilename ?? pkg.name;
82
+ options.app.privateBuild = options.app.privateBuild ?? undefined;
83
+ options.app.productName = options.app.productName ?? pkg.name;
84
+ options.app.productVersion = options.app.productVersion ?? pkg.version;
85
+ options.app.specialBuild = options.app.specialBuild ?? undefined;
86
+ }
80
87
 
81
88
  return { ...options };
82
89
  };
@@ -3,10 +3,10 @@ import { readdir } from "node:fs/promises";
3
3
  /**
4
4
  * Validate options
5
5
  *
6
- * @param {import("../nwbuild").Options} options Options
7
- * @param {object} releaseInfo Version specific NW release info
8
- * @return {Promise<undefined>} Return undefined if options are valid
9
- * @throws {Error} Throw error if options are invalid
6
+ * @param {import("../../index.js").OPTIONS} options Options
7
+ * @param {object} releaseInfo Version specific NW release info
8
+ * @return {Promise<undefined>} Return undefined if options are valid
9
+ * @throws {Error} Throw error if options are invalid
10
10
  */
11
11
  export const validate = async (options, releaseInfo) => {
12
12
  if (!["get", "run", "build"].includes(options.mode)) {
@@ -14,7 +14,9 @@ export const validate = async (options, releaseInfo) => {
14
14
  `Unknown mode ${options.mode}. Expected "get", "run" or "build".`,
15
15
  );
16
16
  }
17
- // We don't validate version since getReleaseInfo already does that
17
+ if (typeof releaseInfo === "undefined") {
18
+ throw new Error("The specified version does not exist in the version manifest. Disable cache to redownload the version manifest. If you still get this error, that means the version you've specified is incorrect.");
19
+ }
18
20
  if (!releaseInfo.flavors.includes(options.flavor)) {
19
21
  throw new Error(
20
22
  `${options.flavor} flavor is not supported by this download server.`,
@@ -8,7 +8,7 @@ import { basename } from "node:path";
8
8
  * @param {boolean} glob Whether or not the files are glob patterns
9
9
  * @return {Promise<object>} NW.js manifest file
10
10
  */
11
- export const getManifest = async (files, glob) => {
11
+ export const getVersionManifest = async (files, glob) => {
12
12
  let manifest;
13
13
 
14
14
  if (glob === false) {