nw-builder 4.0.7 → 4.0.8

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.0.7",
3
+ "version": "4.0.8",
4
4
  "description": "Build NW.js desktop applications for MacOS, Windows and Linux.",
5
5
  "keywords": [
6
6
  "NW.js",
@@ -34,8 +34,6 @@ export const getReleaseInfo = async (version, cacheDir, manifestUrl) => {
34
34
  releaseData = manifest.versions.find(
35
35
  (release) => release.version === `v${version}`,
36
36
  );
37
-
38
- releaseData.version = version;
39
37
  }
40
38
  return releaseData;
41
39
  };
package/src/nwbuild.js CHANGED
@@ -1,7 +1,4 @@
1
- import { mkdir, readFile, rm } from "node:fs/promises";
2
- import { basename } from "node:path";
3
-
4
- import glob from "glob-promise";
1
+ import { mkdir, rm } from "node:fs/promises";
5
2
 
6
3
  import { decompress } from "./get/decompress.js";
7
4
  import { download } from "./get/download.js";
@@ -11,6 +8,7 @@ import { packager } from "./bld/package.js";
11
8
  import { develop } from "./run/develop.js";
12
9
  import { isCached } from "./util/cache.js";
13
10
  import { notify } from "./util/notify.js";
11
+ import { getOptions } from "./util/options.js";
14
12
  import { parse } from "./util/parse.js";
15
13
  import { validate } from "./util/validate.js";
16
14
 
@@ -81,93 +79,56 @@ import { log } from "./log.js";
81
79
  */
82
80
  const nwbuild = async (options) => {
83
81
  let nwDir = "";
84
- let nwPkg = undefined;
85
82
  let cached;
83
+ let nwCached;
86
84
  let built;
87
85
  let releaseInfo = {};
86
+
88
87
  notify();
89
- try {
90
- let files = [];
91
- let patterns = options.srcDir.split(" ");
92
-
93
- for (const pattern of patterns) {
94
- let contents = await glob(pattern);
95
- files.push(...contents);
96
- // Try to find the first instance of the package.json
97
- for (const content of contents) {
98
- if (basename(content) === "package.json" && nwPkg === undefined) {
99
- nwPkg = JSON.parse(await readFile(content));
100
- }
101
- }
102
-
103
- if (nwPkg === undefined) {
104
- throw new Error("package.json not found in srcDir file glob patterns.");
105
- }
106
- }
107
88
 
108
- if (files.length === 0) {
109
- throw new Error(`The globbing pattern ${options.srcDir} is invalid.`);
110
- }
89
+ try {
90
+ const { opts, files, nwPkg } = await getOptions(options);
91
+ options = opts;
111
92
 
112
- // The name property is required for NW.js applications
113
- if (nwPkg.name === undefined) {
114
- throw new Error(`name property is missing from package.json`);
115
- }
93
+ // Parse options
94
+ options = await parse(options, nwPkg);
116
95
 
117
- // The main property is required for NW.js applications
118
- if (nwPkg.main === undefined) {
119
- throw new Error(`main property is missing from package.json`);
96
+ // Create cacheDir if it does not exist
97
+ cached = await isCached(options.cacheDir);
98
+ if (cached === false) {
99
+ await mkdir(options.cacheDir, { recursive: true });
120
100
  }
121
101
 
122
- // If the nwbuild property exists in srcDir/package.json, then they take precedence
123
- if (typeof nwPkg.nwbuild === "object") {
124
- options = { ...nwPkg.nwbuild };
125
- } else if (typeof nwPkg.nwbuild === "undefined") {
126
- log.debug(`nwbuild property is not defined in package.json`);
127
- } else {
128
- throw new Error(
129
- `nwbuild property in the package.json is of type ${typeof nwPkg.nwbuild}. Expected type object.`,
130
- );
102
+ // Create outDir if it does not exist
103
+ built = await isCached(options.outDir);
104
+ if (built === false) {
105
+ await mkdir(options.outDir, { recursive: true });
131
106
  }
132
107
 
133
- // Parse options, set required values to undefined and flags with default values unless specified by user
134
- options = await parse(options, nwPkg);
135
-
136
- // Validate options.version here
137
- // We need to do this to get the version specific release info
108
+ // Validate options.version to get the version specific release info
138
109
  releaseInfo = await getReleaseInfo(
139
110
  options.version,
140
111
  options.cacheDir,
141
112
  options.manifestUrl,
142
113
  );
143
- options.version = releaseInfo.version;
114
+ // Remove leading "v" from version string
115
+ options.version = releaseInfo.version.slice(1);
144
116
 
145
- validate(options, releaseInfo);
117
+ await validate(options, releaseInfo);
146
118
 
147
119
  // Variable to store nwDir file path
148
120
  nwDir = `${options.cacheDir}/nwjs${
149
121
  options.flavor === "sdk" ? "-sdk" : ""
150
122
  }-v${options.version}-${options.platform}-${options.arch}`;
151
123
 
152
- // Create cacheDir if it does not exist
153
- cached = await isCached(nwDir);
154
- if (cached === false) {
155
- await mkdir(nwDir, { recursive: true });
156
- }
157
-
158
- // Create outDir if it does not exist
159
- built = await isCached(options.outDir);
160
- if (built === false) {
161
- await mkdir(options.outDir, { recursive: true });
162
- }
163
-
124
+ nwCached = await isCached(nwDir);
164
125
  // Remove cached NW binary
165
- if (options.cache === false && cached === true) {
126
+ if (options.cache === false && nwCached === true) {
166
127
  log.debug("Remove cached NW binary");
167
128
  await rm(nwDir, { force: true, recursive: true });
168
129
  }
169
130
  // Download relevant NW.js binaries
170
- if (cached === false) {
131
+ if (nwCached === false) {
171
132
  log.debug("Download relevant NW.js binaries");
172
133
  await download(
173
134
  options.version,
package/src/util/cache.js CHANGED
@@ -3,8 +3,8 @@ import { access, constants } from "node:fs/promises";
3
3
  /**
4
4
  * Check if NW binaries are cached
5
5
  *
6
- * @param {string} nwDir Path to cached NW binaries
7
- * @return {Promise<boolean>} Boolean value to denote if cache exists or not
6
+ * @param {string} nwDir Path to cached NW binaries
7
+ * @return {boolean} Boolean value to denote if cache exists or not
8
8
  */
9
9
  export const isCached = async (nwDir) => {
10
10
  let exists = true;
@@ -1,14 +1,13 @@
1
- import { createRequire } from 'node:module';
1
+ import { createRequire } from "node:module";
2
2
  const require = createRequire(import.meta.url);
3
3
 
4
4
  import updateNotifier from "update-notifier";
5
5
 
6
-
7
6
  /**
8
7
  * Notify the user if there is a new version of the package available.
9
- *
10
- * @return {Promise<void>}
11
- */
8
+ *
9
+ * @return {Promise<void>}
10
+ */
12
11
  export const notify = async () => {
13
12
  const packageJson = require("../../package.json");
14
13
  updateNotifier({ pkg: packageJson }).notify();
@@ -0,0 +1,50 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { basename } from "node:path";
3
+
4
+ import glob from "glob-promise";
5
+
6
+ import { log } from "../log.js";
7
+
8
+ /**
9
+ * Get options object from package.json, otherwise from module/cli
10
+ *
11
+ * @param {import("../nwbuild").Options} opts The options object
12
+ * @return {Promise<object>} The options object
13
+ */
14
+ export const getOptions = async (opts) => {
15
+ let files = [];
16
+ let nwPkg;
17
+ const patterns = opts.srcDir.split(" ");
18
+
19
+ for (const pattern of patterns) {
20
+ let contents = await glob(pattern);
21
+ files.push(...contents);
22
+ // Try to find the first instance of the package.json
23
+ for (const content of contents) {
24
+ if (basename(content) === "package.json" && nwPkg === undefined) {
25
+ nwPkg = JSON.parse(await readFile(content));
26
+ }
27
+ }
28
+
29
+ if (nwPkg === undefined) {
30
+ throw new Error("package.json not found in srcDir file glob patterns.");
31
+ }
32
+ }
33
+
34
+ if (files.length === 0) {
35
+ throw new Error(`The globbing pattern ${opts.srcDir} is invalid.`);
36
+ }
37
+
38
+ // If the nwbuild property exists in srcDir/package.json, then they take precedence
39
+ if (typeof nwPkg.nwbuild === "object") {
40
+ opts = { ...nwPkg.nwbuild };
41
+ } else if (typeof nwPkg.nwbuild === "undefined") {
42
+ log.debug(`nwbuild property is not defined in package.json`);
43
+ } else {
44
+ throw new Error(
45
+ `nwbuild property in the package.json is of type ${typeof nwPkg.nwbuild}. Expected type object.`,
46
+ );
47
+ }
48
+
49
+ return { opts, files, nwPkg };
50
+ };
@@ -3,9 +3,9 @@ import { readdir } from "node:fs/promises";
3
3
  /**
4
4
  * Validate options
5
5
  *
6
- * @param {object} options Options
7
- * @param {object} releaseInfo Version specific NW release info
8
- * @return {undefined} True if options are valid. False otherwise
6
+ * @param {object} options Options
7
+ * @param {object} releaseInfo Version specific NW release info
8
+ * @return {Promise<undefined>} True if options are valid. False otherwise
9
9
  */
10
10
  export const validate = async (options, releaseInfo) => {
11
11
  if (options.srcDir === "") {