nw-builder 3.8.6-beta.1 → 3.8.6-beta.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/lib/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
- const { resolve } = require("node:path");
2
- const { mkdir, readdir, cp, rm, rename } = require("node:fs/promises");
3
- const glob = require('simple-glob');
1
+ const { basename, resolve } = require("node:path");
2
+ const { version } = require("node:process");
3
+ const { mkdir, cp, rm, rename } = require("node:fs/promises");
4
+ const { readFileSync } = require("node:fs");
5
+ const glob = require("simple-glob");
4
6
  var _ = require("lodash");
5
- var inherits = require("inherits");
6
- var EventEmitter = require("events").EventEmitter;
7
7
  var fs = require("graceful-fs-extra");
8
8
  var path = require("path");
9
9
  var thenify = require("thenify");
@@ -11,945 +11,932 @@ var rcedit = require("rcedit");
11
11
  var winresourcer = thenify(require("winresourcer"));
12
12
  var semver = require("semver");
13
13
  var platformOverrides = require("./platformOverrides.cjs");
14
- var deprecate = require("deprecate");
15
14
 
16
15
  const {
17
16
  checkCache,
18
- detectCurrentPlatform,
19
17
  get,
20
- run,
18
+ getReleaseInfo,
19
+ isCached,
20
+ log,
21
+ setLogLevel,
21
22
  Platforms,
22
- checkPkgOptions,
23
- Options,
24
- parseOptions,
23
+ parse,
24
+ run,
25
+ validate,
25
26
  } = require("../dist/index.cjs");
26
27
  var NwVersions = require("./versions.cjs");
27
28
  var Version = require("./Version.cjs");
28
29
  var Utils = require("./utils.cjs");
29
30
 
30
- // We inherit from EventEmitter for logging
31
- inherits(NwBuilder, EventEmitter);
31
+ class NwBuilder {
32
+ constructor(options) {
33
+ this.init(options).then(() => {
34
+ this._platforms = { ...Platforms };
32
35
 
33
- function NwBuilder(options) {
34
- const pkgOptions = checkPkgOptions(options.files);
35
- // Options are defined in package.json take precedence
36
- if (Object.entries(pkgOptions).length !== 0) {
37
- this.options = parseOptions(pkgOptions, Options);
38
- this.options.files = options.files;
39
- } else {
40
- this.options = parseOptions(options, Options);
36
+ // clear all unused platforms
37
+ for (const name in this._platforms) {
38
+ if (
39
+ this.options.platforms &&
40
+ this.options.platforms.indexOf(name) === -1
41
+ )
42
+ delete this._platforms[name];
43
+ }
44
+ });
41
45
  }
42
46
 
43
- if (this.options.currentPlatform === null) {
44
- this.options.currentPlatform = detectCurrentPlatform(process);
45
- }
47
+ async init(options) {
48
+ let manifest = {};
49
+ let releaseInfo = {};
50
+ try {
51
+ options = parse(options, manifest);
46
52
 
47
- if (this.options.platforms && this.options.platforms.length === 0) {
48
- this.options.platforms = [detectCurrentPlatform(process)];
49
- } else if (this.options.platforms && this.options.platforms.length === 1) {
50
- this.options.platforms = this.options.platforms[0].split(",");
51
- }
53
+ for (const file of glob(options.files)) {
54
+ if (basename(file) === "package.json" && manifest === undefined) {
55
+ manifest = JSON.parse(readFileSync(file));
56
+ }
57
+ }
52
58
 
53
- // Intercept the platforms and check for the legacy platforms of 'osx' and 'win' and
54
- // replace with 'osx32', 'osx64', and 'win32', 'win64' respectively.
55
- if (typeof this.options.platforms != "undefined") {
56
- if (this.options.platforms && this.options.platforms.indexOf("osx") >= 0) {
57
- this.options.platforms.splice(
58
- this.options.platforms.indexOf("osx"),
59
- 1,
60
- "osx32",
61
- "osx64",
62
- );
63
- }
64
- if (this.options.platforms && this.options.platforms.indexOf("win") >= 0) {
65
- this.options.platforms.splice(
66
- this.options.platforms.indexOf("win"),
67
- 1,
68
- "win32",
69
- "win64",
70
- );
71
- }
72
- if (
73
- this.options.platforms &&
74
- this.options.platforms.indexOf("linux") >= 0
75
- ) {
76
- this.options.platforms.splice(
77
- this.options.platforms.indexOf("linux"),
78
- 1,
79
- "linux32",
80
- "linux64",
81
- );
82
- }
83
- }
59
+ if (manifest === undefined) {
60
+ throw new Error(
61
+ "package.json not found in options.files glob patterns.",
62
+ );
63
+ }
84
64
 
85
- // Some Option checking
86
- if (!this.options.files) {
87
- throw new Error("Please specify some files");
88
- }
65
+ if (typeof manifest?.nwbuild === "object") {
66
+ options = manifest.nwbuild;
67
+ }
89
68
 
90
- if (this.options.platforms && this.options.platforms.length === 0)
91
- throw new Error("No platform to build!");
69
+ options = parse(options, manifest);
92
70
 
93
- // verify all the platforms specifed by the user are supported
94
- // this + previous check assures as we have only buildable platforms specified
95
- this.options.platforms &&
96
- this.options.platforms.forEach(function (platform) {
97
- if (!(platform in Platforms))
98
- throw new Error("Unknown platform " + platform);
99
- });
71
+ let platform = options.currentPlatform.slice(
72
+ 0,
73
+ options.currentPlatform.length - 2,
74
+ );
75
+ let arch =
76
+ "x" + options.currentPlatform.slice(options.currentPlatform.length - 2);
77
+
78
+ getReleaseInfo(
79
+ options.version,
80
+ options.cacheDir,
81
+ options.manifestUrl,
82
+ ).then((info) => {
83
+ releaseInfo = info;
84
+ validate(options, info)
85
+ .then(() => {
86
+ // Remove leading "v" from version string
87
+ options.version = info.version.slice(1);
88
+ })
89
+ .catch((error) => {
90
+ log.error(error);
91
+ });
92
+ });
100
93
 
101
- this._platforms = _.cloneDeep(Platforms);
94
+ setLogLevel(options.quiet);
102
95
 
103
- // clear all unused platforms
104
- for (var name in this._platforms) {
105
- if (this.options.platforms && this.options.platforms.indexOf(name) === -1)
106
- delete this._platforms[name];
96
+ if (options.quiet === "debug") {
97
+ log.debug(`Platform: ${platform}`);
98
+ log.debug(`Archicture: ${arch}`);
99
+ log.debug(`Node Version: ${version}`);
100
+ log.debug(`NW.js Version: ${options.version}\n`);
101
+ }
102
+ } catch (error) {
103
+ log.error(error);
104
+ } finally {
105
+ this.options = options;
106
+ }
107
107
  }
108
- }
109
108
 
110
- /**
111
- * Check if NW binaries are cached
112
- *
113
- * @param {string} nwDir Path to cached NW binaries
114
- * @return {Promise<boolean>} Boolean value to denote if cache exists or not
115
- */
116
- NwBuilder.prototype.isCached = async function (nwDir) {
117
- let exists = true;
118
- try {
119
- await readdir(nwDir);
120
- } catch (e) {
121
- exists = false;
122
- }
123
- return exists;
124
- };
109
+ build(callback) {
110
+ // Let's create a NWjs app
111
+ var build = this.checkFiles()
112
+ .then(this.downloadNwjs.bind(this))
113
+ .then(this.preparePlatformSpecificManifests.bind(this))
114
+ .then(this.createReleaseFolder.bind(this))
115
+ .then(this.copyNwjs.bind(this))
116
+ .then(this.handleLinuxApp.bind(this))
117
+ .then(this.handleMacApp.bind(this))
118
+ .then(this.handleWinApp.bind(this))
119
+ .then(this.zipAppFiles.bind(this))
120
+ .then(this.mergeAppFiles.bind(this))
121
+ .then(function (info) {
122
+ // the promise(s) resolves to nothing in some cases
123
+ return info || this;
124
+ });
125
125
 
126
- NwBuilder.prototype.build = function (callback) {
127
- // Let's create a NWjs app
128
- var build = this.checkFiles()
129
- .then(this.downloadNwjs.bind(this))
130
- .then(this.preparePlatformSpecificManifests.bind(this))
131
- .then(this.createReleaseFolder.bind(this))
132
- .then(this.copyNwjs.bind(this))
133
- .then(this.handleLinuxApp.bind(this))
134
- .then(this.handleMacApp.bind(this))
135
- .then(this.handleWinApp.bind(this))
136
- .then(this.zipAppFiles.bind(this))
137
- .then(this.mergeAppFiles.bind(this))
138
- .then(function (info) {
139
- // the promise(s) resolves to nothing in some cases
140
- return info || this;
141
- });
126
+ if (typeof callback === "function") {
127
+ build
128
+ .then(function (result) {
129
+ callback(false, result);
130
+ })
131
+ .catch(callback);
132
+ return true;
133
+ }
142
134
 
143
- if (typeof callback === "function") {
144
- build
145
- .then(function (result) {
146
- callback(false, result);
147
- })
148
- .catch(callback);
149
- return true;
135
+ return build;
150
136
  }
151
137
 
152
- return build;
153
- };
138
+ run(callback) {
139
+ // We do not want to download nwjs for other platforms if are going to run the App
140
+ var platforms = this.options.platforms;
141
+ this.options.platforms = [this.options.currentPlatform];
142
+
143
+ // Let's run this NWjs app
144
+ var run = this.checkFiles()
145
+ .then(this.downloadNwjs.bind(this))
146
+ .then(this.runApp.bind(this));
147
+
148
+ if (typeof callback === "function") {
149
+ run
150
+ .then(function (result) {
151
+ this.options.platforms = platforms;
152
+ callback(false, result);
153
+ })
154
+ .catch(function (error) {
155
+ this.options.platforms = platforms;
156
+ callback(true, error);
157
+ });
158
+ return true;
159
+ }
160
+
161
+ return run;
162
+ }
163
+
164
+ checkFiles() {
165
+ var self = this;
154
166
 
155
- NwBuilder.prototype.run = function (callback) {
156
- // We do not want to download nwjs for other platforms if are going to run the App
157
- var platforms = this.options.platforms;
158
- this.options.platforms = [this.options.currentPlatform];
159
-
160
- // Let's run this NWjs app
161
- var run = this.checkFiles()
162
- .then(this.downloadNwjs.bind(this))
163
- .then(this.runApp.bind(this));
164
-
165
- if (typeof callback === "function") {
166
- run
167
- .then(function (result) {
168
- this.options.platforms = platforms;
169
- callback(false, result);
167
+ return Utils.getFileList(this.options.files)
168
+ .then(function (data) {
169
+ self._appPkg = data.json;
170
+ self._files = data.files;
171
+ return self._appPkg;
170
172
  })
171
- .catch(function (error) {
172
- this.options.platforms = platforms;
173
- callback(true, error);
173
+ .then(Utils.getPackageInfo)
174
+ .then(function (appPkg) {
175
+ self._appPkg = appPkg;
176
+
177
+ if (!self.options.appName || !self.options.appVersion) {
178
+ self.options.appName = self.options.appName
179
+ ? self.options.appName
180
+ : appPkg.name;
181
+ self.options.appVersion = self.options.appVersion
182
+ ? self.options.appVersion
183
+ : appPkg.version;
184
+ }
174
185
  });
175
- return true;
176
186
  }
177
187
 
178
- return run;
179
- };
188
+ resolveLatestVersion() {
189
+ var self = this;
180
190
 
181
- NwBuilder.prototype.checkFiles = function () {
182
- var self = this;
183
-
184
- return Utils.getFileList(this.options.files)
185
- .then(function (data) {
186
- self._appPkg = data.json;
187
- self._files = data.files;
188
- return self._appPkg;
189
- })
190
- .then(Utils.getPackageInfo)
191
- .then(function (appPkg) {
192
- self._appPkg = appPkg;
193
-
194
- if (!self.options.appName || !self.options.appVersion) {
195
- self.options.appName = self.options.appName
196
- ? self.options.appName
197
- : appPkg.name;
198
- self.options.appVersion = self.options.appVersion
199
- ? self.options.appVersion
200
- : appPkg.version;
201
- }
191
+ if (self.options.version !== "latest") return Promise.resolve();
192
+
193
+ return NwVersions.getLatestVersion(
194
+ self.options.downloadUrl,
195
+ self.options.manifestUrl,
196
+ self.options.flavor,
197
+ ).then(function (latestVersion) {
198
+ log.debug("Latest Version: v" + latestVersion.version);
199
+ self.options.version = latestVersion.version;
200
+ return latestVersion;
202
201
  });
203
- };
202
+ }
204
203
 
205
- NwBuilder.prototype.resolveLatestVersion = function () {
206
- var self = this;
204
+ checkVersion() {
205
+ var version = this.options.version,
206
+ flavor =
207
+ semver.valid(version) && semver.satisfies(version, "<0.12.3")
208
+ ? "sdk"
209
+ : this.options.flavor,
210
+ self = this;
207
211
 
208
- if (self.options.version !== "latest") return Promise.resolve();
212
+ if (!semver.valid(version)) {
213
+ return Promise.reject("The version " + version + " is not valid.");
214
+ }
209
215
 
210
- return NwVersions.getLatestVersion(
211
- self.options.downloadUrl,
212
- self.options.manifestUrl,
213
- self.options.flavor,
214
- ).then(function (latestVersion) {
215
- self.emit("log", "Latest Version: v" + latestVersion.version);
216
- self.options.version = latestVersion.version;
217
- return latestVersion;
218
- });
219
- };
216
+ var getVersionFromManifest = function () {
217
+ return NwVersions.getVersion({
218
+ desiredVersion: version,
219
+ downloadUrl: self.options.downloadUrl,
220
+ manifestUrl: self.options.manifestUrl,
221
+ flavor: flavor,
222
+ });
223
+ };
224
+ var getVersion;
225
+
226
+ // if the user specified the exact version and all its platforms are cached, don't hit the manifest at all;
227
+ // just trust the ones are cached and assume they're supported
228
+ if (self.options.version !== "latest") {
229
+ var areAllPlatformsCached = true;
230
+ this._forEachPlatform(function (name, platform) {
231
+ var platformToCheck = platform;
232
+
233
+ if (semver.satisfies(self.options.version, ">=0.12.3")) {
234
+ platformToCheck = _.clone(platform);
235
+ platformToCheck.files = ["*"]; // otherwise it'll try to check cache legacy version files
236
+ }
220
237
 
221
- NwBuilder.prototype.checkVersion = function () {
222
- var version = this.options.version,
223
- flavor =
224
- semver.valid(version) && semver.satisfies(version, "<0.12.3")
225
- ? "sdk"
226
- : this.options.flavor,
227
- self = this;
238
+ if (
239
+ !self.isPlatformCached(
240
+ name,
241
+ platformToCheck,
242
+ self.options.version,
243
+ flavor,
244
+ )
245
+ ) {
246
+ areAllPlatformsCached = false;
247
+ }
248
+ });
249
+ if (areAllPlatformsCached) {
250
+ getVersion = Promise.resolve(
251
+ new Version({
252
+ version: version,
253
+ flavors: [flavor],
254
+ downloadUrl: self.options.downloadUrl,
255
+ supportedPlatforms: Object.keys(this._platforms),
256
+ }),
257
+ );
258
+ } else {
259
+ // otherwise hit the manifest
260
+ getVersion = getVersionFromManifest();
261
+ }
262
+ } else {
263
+ // otherwise hit the manifest
264
+ getVersion = getVersionFromManifest();
265
+ }
228
266
 
229
- if (!semver.valid(version)) {
230
- return Promise.reject("The version " + version + " is not valid.");
267
+ return getVersion.then(function (version) {
268
+ self._version = version;
269
+ self._version.flavor = flavor;
270
+ log.debug(
271
+ "Using v" +
272
+ self._version.version +
273
+ " (" +
274
+ (self._version.flavor === "" ? "normal" : self._version.flavor + ")"),
275
+ );
276
+ if (self._version.isLegacy) {
277
+ log.warn("NW.js / node-webkit versions <0.12.3 are deprecated.");
278
+ }
279
+ });
231
280
  }
232
281
 
233
- var getVersionFromManifest = function () {
234
- return NwVersions.getVersion({
235
- desiredVersion: version,
236
- downloadUrl: self.options.downloadUrl,
237
- manifestUrl: self.options.manifestUrl,
238
- flavor: flavor,
239
- });
240
- };
241
- var getVersion;
282
+ platformFilesForVersion() {
283
+ var self = this;
242
284
 
243
- // if the user specified the exact version and all its platforms are cached, don't hit the manifest at all;
244
- // just trust the ones are cached and assume they're supported
245
- if (self.options.version !== "latest") {
246
- var areAllPlatformsCached = true;
247
285
  this._forEachPlatform(function (name, platform) {
248
- var platformToCheck = platform;
249
-
250
- if (semver.satisfies(self.options.version, ">=0.12.3")) {
251
- platformToCheck = _.clone(platform);
252
- platformToCheck.files = ["*"]; // otherwise it'll try to check cache legacy version files
253
- }
286
+ var satisfied = self.preparePlatformFiles(name, platform);
254
287
 
288
+ // need the second condition for newer NW.js versions
255
289
  if (
256
- !self.isPlatformCached(
257
- name,
258
- platformToCheck,
259
- self.options.version,
260
- flavor,
290
+ !(
291
+ satisfied &&
292
+ !!self._version.platforms[name + "-" + self._version.flavor]
261
293
  )
262
294
  ) {
263
- areAllPlatformsCached = false;
295
+ throw new Error(
296
+ "Unsupported NW.js version '" +
297
+ self._version.version +
298
+ " (" +
299
+ self._version.flavor +
300
+ ")' for platform '" +
301
+ name +
302
+ "'",
303
+ );
264
304
  }
265
305
  });
266
- if (areAllPlatformsCached) {
267
- getVersion = Promise.resolve(
268
- new Version({
269
- version: version,
270
- flavors: [flavor],
271
- downloadUrl: self.options.downloadUrl,
272
- supportedPlatforms: Object.keys(this._platforms),
273
- }),
274
- );
275
- } else {
276
- // otherwise hit the manifest
277
- getVersion = getVersionFromManifest();
306
+
307
+ return Promise.resolve();
308
+ }
309
+
310
+ async downloadNwjs() {
311
+ let options = this.options;
312
+ let built;
313
+
314
+ built = await isCached(options.cacheDir);
315
+ if (built === false) {
316
+ await mkdir(options.cacheDir, { recursive: true });
278
317
  }
279
- } else {
280
- // otherwise hit the manifest
281
- getVersion = getVersionFromManifest();
282
- }
283
-
284
- return getVersion.then(function (version) {
285
- self._version = version;
286
- self._version.flavor = flavor;
287
- self.emit(
288
- "log",
289
- "Using v" +
290
- self._version.version +
291
- " (" +
292
- (self._version.flavor === "" ? "normal" : self._version.flavor + ")"),
293
- );
294
- if (self._version.isLegacy) {
295
- deprecate("NW.js / node-webkit versions <0.12.3 are deprecated.");
318
+ for await (const os of options.platforms) {
319
+ let platform = os.slice(0, os.length - 2);
320
+ let arch = "x" + os.slice(os.length - 2);
321
+ await get({
322
+ version: options.version,
323
+ flavor: options.flavor,
324
+ platform: platform,
325
+ arch: arch,
326
+ downloadUrl: options.downloadUrl,
327
+ cacheDir: options.cacheDir,
328
+ cache: !options.forceDownload,
329
+ ffmpeg: false,
330
+ });
296
331
  }
297
- });
298
- };
299
-
300
- NwBuilder.prototype.platformFilesForVersion = function () {
301
- var self = this;
332
+ }
302
333
 
303
- this._forEachPlatform(function (name, platform) {
304
- var satisfied = self.preparePlatformFiles(name, platform);
334
+ buildGypModules() {
335
+ // @todo
336
+ // If we trigger a rebuild we have to copy
337
+ // the node_modules to a tmp location because
338
+ // we don't want to change the source files
339
+ }
305
340
 
306
- // need the second condition for newer NW.js versions
341
+ preparePlatformSpecificManifests() {
307
342
  if (
308
343
  !(
309
- satisfied &&
310
- !!self._version.platforms[name + "-" + self._version.flavor]
344
+ this._appPkg.platformOverrides &&
345
+ Object.keys(this._appPkg.platformOverrides).length
311
346
  )
312
347
  ) {
313
- throw new Error(
314
- "Unsupported NW.js version '" +
315
- self._version.version +
316
- " (" +
317
- self._version.flavor +
318
- ")' for platform '" +
319
- name +
320
- "'",
321
- );
348
+ return Promise.resolve();
322
349
  }
323
- });
324
-
325
- return Promise.resolve();
326
- };
327
-
328
- NwBuilder.prototype.downloadNwjs = async function () {
329
- let options = this.options;
330
- let built;
331
350
 
332
- built = await this.isCached(options.cacheDir);
333
- if (built === false) {
334
- await mkdir(options.cacheDir, { recursive: true });
335
- }
336
- for await (const os of options.platforms) {
337
- let platform = os.slice(0, os.length - 2)
338
- let arch = "x" + os.slice(os.length - 2);
339
- await get({
340
- version: options.version,
341
- flavor: options.flavor,
342
- platform: platform,
343
- arch: arch,
344
- downloadUrl: options.downloadUrl,
345
- cacheDir: options.cacheDir,
346
- cache: !options.forceDownload,
347
- ffmpeg: false,
351
+ var self = this;
352
+ var promises = [];
353
+
354
+ self._forEachPlatform(function (name, platform) {
355
+ promises.push(
356
+ new Promise(function (resolve, reject) {
357
+ var overrides = self._appPkg.platformOverrides;
358
+ if (overrides[name] || overrides[name.substr(0, name.length - 2)]) {
359
+ platformOverrides(
360
+ {
361
+ options: self._appPkg,
362
+ platform: name,
363
+ },
364
+ function (err, result) {
365
+ if (err) {
366
+ return reject(err);
367
+ }
368
+
369
+ platform.platformSpecificManifest = result;
370
+ resolve();
371
+ },
372
+ );
373
+ } else {
374
+ resolve();
375
+ }
376
+ }),
377
+ );
348
378
  });
349
- }
350
- };
351
379
 
352
- NwBuilder.prototype.buildGypModules = function () {
353
- // @todo
354
- // If we trigger a rebuild we have to copy
355
- // the node_modules to a tmp location because
356
- // we don't want to change the source files
357
- };
358
-
359
- NwBuilder.prototype.preparePlatformSpecificManifests = function () {
360
- if (
361
- !(
362
- this._appPkg.platformOverrides &&
363
- Object.keys(this._appPkg.platformOverrides).length
364
- )
365
- ) {
366
- return Promise.resolve();
380
+ return Promise.all(promises);
367
381
  }
368
382
 
369
- var self = this;
370
- var promises = [];
383
+ createReleaseFolder() {
384
+ var self = this,
385
+ releasePath,
386
+ directoryCreationPromises = [];
371
387
 
372
- self._forEachPlatform(function (name, platform) {
373
- promises.push(
374
- new Promise(function (resolve, reject) {
375
- var overrides = self._appPkg.platformOverrides;
376
- if (overrides[name] || overrides[name.substr(0, name.length - 2)]) {
377
- platformOverrides(
378
- {
379
- options: self._appPkg,
380
- platform: name,
381
- },
382
- function (err, result) {
383
- if (err) {
384
- return reject(err);
385
- }
386
-
387
- platform.platformSpecificManifest = result;
388
- resolve();
389
- },
390
- );
391
- } else {
392
- resolve();
393
- }
394
- }),
395
- );
396
- });
397
-
398
- return Promise.all(promises);
399
- };
400
-
401
- NwBuilder.prototype.createReleaseFolder = function () {
402
- var self = this,
403
- releasePath,
404
- directoryCreationPromises = [];
405
-
406
- if (_.isFunction(self.options.buildType)) {
407
- releasePath = self.options.buildType.call(self.options);
408
- } else {
409
- // buildTypes
410
- switch (self.options.buildType) {
411
- case "timestamped":
412
- releasePath =
413
- self.options.appName +
414
- " - " +
415
- Math.round(Date.now() / 1000).toString();
416
- break;
417
-
418
- case "versioned":
419
- releasePath = self.options.appName + " - v" + self.options.appVersion;
420
- break;
421
-
422
- default:
423
- releasePath = self.options.appName;
388
+ if (_.isFunction(self.options.buildType)) {
389
+ releasePath = self.options.buildType.call(self.options);
390
+ } else {
391
+ // buildTypes
392
+ switch (self.options.buildType) {
393
+ case "timestamped":
394
+ releasePath =
395
+ self.options.appName +
396
+ " - " +
397
+ Math.round(Date.now() / 1000).toString();
398
+ break;
399
+
400
+ case "versioned":
401
+ releasePath = self.options.appName + " - v" + self.options.appVersion;
402
+ break;
403
+
404
+ default:
405
+ releasePath = self.options.appName;
406
+ }
424
407
  }
425
- }
426
408
 
427
- this._forEachPlatform(function (name, platform) {
428
- directoryCreationPromises.push(
429
- new Promise(function (resolve, reject) {
430
- platform.releasePath = path.resolve(
431
- self.options.buildDir,
432
- releasePath,
433
- name,
434
- );
435
-
436
- // Ensure that there is a release Folder, delete and create it.
437
- fs.remove(platform.releasePath, function (err) {
438
- if (err) return reject(err);
409
+ this._forEachPlatform(function (name, platform) {
410
+ directoryCreationPromises.push(
411
+ new Promise(function (resolve, reject) {
412
+ platform.releasePath = path.resolve(
413
+ self.options.buildDir,
414
+ releasePath,
415
+ name,
416
+ );
439
417
 
440
- fs.mkdirp(platform.releasePath, function (err) {
418
+ // Ensure that there is a release Folder, delete and create it.
419
+ fs.remove(platform.releasePath, function (err) {
441
420
  if (err) return reject(err);
442
421
 
443
- self.emit(
444
- "log",
445
- "Create release folder in " + platform.releasePath,
446
- );
447
- resolve();
448
- });
449
- });
450
- }),
451
- );
452
- });
453
-
454
- return Promise.all(directoryCreationPromises);
455
- };
422
+ fs.mkdirp(platform.releasePath, function (err) {
423
+ if (err) return reject(err);
456
424
 
457
- NwBuilder.prototype.copyNwjs = async function () {
425
+ log.debug("Create release folder in " + platform.releasePath);
426
+ resolve();
427
+ });
428
+ });
429
+ }),
430
+ );
431
+ });
458
432
 
459
- for await (const os of this.options.platforms) {
460
- const platform = os.slice(0, os.length - 2);
461
- const arch = "x" + os.slice(os.length - 2);
433
+ return Promise.all(directoryCreationPromises);
434
+ }
462
435
 
463
- await rm(resolve(this.options.buildDir, this.options.appName, os), { recursive: true, force: true });
436
+ async copyNwjs() {
437
+ for await (const os of this.options.platforms) {
438
+ const platform = os.slice(0, os.length - 2);
439
+ const arch = "x" + os.slice(os.length - 2);
464
440
 
465
- const nwDir = resolve(
466
- this.options.cacheDir,
467
- `nwjs${this.options.flavor === "sdk" ? "-sdk" : ""}-v${this.options.version}-${platform}-${arch}`,
468
- );
441
+ await rm(resolve(this.options.buildDir, this.options.appName, os), {
442
+ recursive: true,
443
+ force: true,
444
+ });
469
445
 
470
- await cp(nwDir, resolve(this.options.buildDir, this.options.appName, os), { recursive: true });
446
+ const nwDir = resolve(
447
+ this.options.cacheDir,
448
+ `nwjs${this.options.flavor === "sdk" ? "-sdk" : ""}-v${
449
+ this.options.version
450
+ }-${platform}-${arch}`,
451
+ );
471
452
 
472
- for (const file of glob(this.options.files)) {
473
453
  await cp(
474
- file,
475
- resolve(
476
- this.options.buildDir, this.options.appName, os,
477
- platform !== "osx"
478
- ? "package.nw"
479
- : "nwjs.app/Contents/Resources/app.nw",
480
- file,
481
- ),
482
- { recursive: true, verbatimSymlinks: true },
454
+ nwDir,
455
+ resolve(this.options.buildDir, this.options.appName, os),
456
+ { recursive: true },
483
457
  );
458
+
459
+ for (const file of glob(this.options.files)) {
460
+ await cp(
461
+ file,
462
+ resolve(
463
+ this.options.buildDir,
464
+ this.options.appName,
465
+ os,
466
+ platform !== "osx"
467
+ ? "package.nw"
468
+ : "nwjs.app/Contents/Resources/app.nw",
469
+ file,
470
+ ),
471
+ { recursive: true, verbatimSymlinks: true },
472
+ );
473
+ }
484
474
  }
485
475
  }
486
- };
487
476
 
488
- NwBuilder.prototype.isPlatformNeedingZip = function (name, platform) {
489
- var self = this,
490
- needsZip = platform.needsZip;
477
+ isPlatformNeedingZip(name, platform) {
478
+ var self = this,
479
+ needsZip = platform.needsZip;
491
480
 
492
- if (name.indexOf("osx") === 0 && self.options.macZip != null) {
493
- deprecate("macZip is deprecated. Use the zip option instead.");
494
- needsZip = self.options.macZip;
495
- } else if (self.options.zip != null) {
496
- needsZip = self.options.zip;
497
- }
498
-
499
- return needsZip;
500
- };
481
+ if (name.indexOf("osx") === 0 && self.options.macZip != null) {
482
+ log.warn("macZip is deprecated. Use the zip option instead.");
483
+ needsZip = self.options.macZip;
484
+ } else if (self.options.zip != null) {
485
+ needsZip = self.options.zip;
486
+ }
501
487
 
502
- NwBuilder.prototype.zipAppFiles = function () {
503
- var self = this;
488
+ return needsZip;
489
+ }
504
490
 
505
- // Check if zip is needed
506
- var doAnyNeedZip = false,
507
- zipOptions = this.options.zipOptions,
508
- numberOfPlatformsWithoutOverrides = 0;
491
+ zipAppFiles() {
492
+ var self = this;
509
493
 
510
- self._zips = {};
494
+ // Check if zip is needed
495
+ var doAnyNeedZip = false,
496
+ zipOptions = this.options.zipOptions,
497
+ numberOfPlatformsWithoutOverrides = 0;
511
498
 
512
- this._forEachPlatform(function (name, platform) {
513
- var needsZip = self.isPlatformNeedingZip(name, platform);
499
+ self._zips = {};
514
500
 
515
- if (needsZip) {
516
- var platformSpecific = !!platform.platformSpecificManifest;
501
+ this._forEachPlatform(function (name, platform) {
502
+ var needsZip = self.isPlatformNeedingZip(name, platform);
517
503
 
518
- self._zips[name] = { platformSpecific: platformSpecific };
504
+ if (needsZip) {
505
+ var platformSpecific = !!platform.platformSpecificManifest;
519
506
 
520
- numberOfPlatformsWithoutOverrides += !platformSpecific;
521
- }
507
+ self._zips[name] = { platformSpecific: platformSpecific };
522
508
 
523
- doAnyNeedZip = doAnyNeedZip || needsZip;
524
- });
509
+ numberOfPlatformsWithoutOverrides += !platformSpecific;
510
+ }
525
511
 
526
- self._needsZip = doAnyNeedZip;
512
+ doAnyNeedZip = doAnyNeedZip || needsZip;
513
+ });
527
514
 
528
- return new Promise(function (resolve, reject) {
529
- if (!self._needsZip) {
530
- resolve();
531
- return;
532
- }
515
+ self._needsZip = doAnyNeedZip;
533
516
 
534
- // create (or don't create) a ZIP for multiple platforms
535
- new Promise(function (resolve, reject) {
536
- if (numberOfPlatformsWithoutOverrides > 1) {
537
- Utils.generateZipFile(self._files, self, null, zipOptions).then(
538
- function (zip) {
539
- resolve(zip);
540
- },
541
- reject,
542
- );
543
- } else {
517
+ return new Promise(function (resolve, reject) {
518
+ if (!self._needsZip) {
544
519
  resolve();
520
+ return;
545
521
  }
546
- }).then(function (platformAgnosticZip) {
547
- var zipPromises = [];
548
522
 
549
- _.forEach(self._zips, function (zip, platformName) {
550
- if (platformAgnosticZip && !zip.platformSpecific) {
551
- zip.file = platformAgnosticZip;
552
- return;
523
+ // create (or don't create) a ZIP for multiple platforms
524
+ new Promise(function (resolve, reject) {
525
+ if (numberOfPlatformsWithoutOverrides > 1) {
526
+ Utils.generateZipFile(self._files, self, null, zipOptions).then(
527
+ function (zip) {
528
+ resolve(zip);
529
+ },
530
+ reject,
531
+ );
532
+ } else {
533
+ resolve();
553
534
  }
535
+ }).then(function (platformAgnosticZip) {
536
+ var zipPromises = [];
537
+
538
+ _.forEach(self._zips, function (zip, platformName) {
539
+ if (platformAgnosticZip && !zip.platformSpecific) {
540
+ zip.file = platformAgnosticZip;
541
+ return;
542
+ }
543
+
544
+ zipPromises.push(
545
+ Utils.generateZipFile(
546
+ self._files,
547
+ self,
548
+ JSON.stringify(
549
+ self._platforms[platformName].platformSpecificManifest,
550
+ ),
551
+ zipOptions,
552
+ ).then(function (file) {
553
+ zip.file = file;
554
+ }),
555
+ );
556
+ });
554
557
 
555
- zipPromises.push(
556
- Utils.generateZipFile(
557
- self._files,
558
- self,
559
- JSON.stringify(
560
- self._platforms[platformName].platformSpecificManifest,
561
- ),
562
- zipOptions,
563
- ).then(function (file) {
564
- zip.file = file;
565
- }),
566
- );
567
- });
568
-
569
- Promise.all(zipPromises).then(resolve, reject);
570
- }, reject);
571
- });
572
- };
558
+ Promise.all(zipPromises).then(resolve, reject);
559
+ }, reject);
560
+ });
561
+ }
573
562
 
574
- NwBuilder.prototype.mergeAppFiles = function () {
575
- var self = this;
563
+ mergeAppFiles() {
564
+ var self = this;
576
565
 
577
- var copyPromises = [];
566
+ var copyPromises = [];
578
567
 
579
- this._forEachPlatform(function (name, platform) {
580
- var zipping = self.isPlatformNeedingZip(name, platform);
581
- // We copy the app files if we are on mac and don't force zip
582
- if (!zipping) {
583
- // no zip, copy the files
584
- self._files.forEach(function (file) {
585
- var dest;
568
+ this._forEachPlatform(function (name, platform) {
569
+ var zipping = self.isPlatformNeedingZip(name, platform);
570
+ // We copy the app files if we are on mac and don't force zip
571
+ if (!zipping) {
572
+ // no zip, copy the files
573
+ self._files.forEach(function (file) {
574
+ var dest;
575
+
576
+ if (name == "osx32" || name === "osx64") {
577
+ dest = path.resolve(
578
+ self.getResourcesDirectoryPath(platform),
579
+ "app.nw",
580
+ file.dest,
581
+ );
582
+ } else {
583
+ dest = path.resolve(platform.releasePath, file.dest);
584
+ }
585
+
586
+ if (
587
+ file.dest === "package.json" &&
588
+ platform.platformSpecificManifest
589
+ ) {
590
+ copyPromises.push(
591
+ self.writePlatformSpecificManifest(platform, dest),
592
+ );
593
+ } else {
594
+ copyPromises.push(Utils.copyFile(file.src, dest, self));
595
+ }
596
+ });
597
+ } else if (!self.options.mergeZip) {
598
+ // copy the zipped package.nw into the app directory
599
+ copyPromises.push(
600
+ Utils.copyFile(
601
+ self.getZipFile(name),
602
+ path.resolve(platform.releasePath, "package.nw"),
603
+ self,
604
+ ),
605
+ );
606
+ } else if (name == "osx32" || name == "osx64") {
607
+ // zip just copy the app.nw
608
+ copyPromises.push(
609
+ Utils.copyFile(
610
+ self.getZipFile(name),
611
+ path.resolve(self.getResourcesDirectoryPath(platform), "app.nw"),
612
+ self,
613
+ ),
614
+ );
615
+ } else {
616
+ var executableToMergeWith = self.getExecutableName(name);
617
+
618
+ // We cat the app.nw file into the .exe / nw
619
+ copyPromises.push(
620
+ Utils.mergeFiles(
621
+ path.resolve(platform.releasePath, executableToMergeWith),
622
+ self.getZipFile(name),
623
+ platform.chmod,
624
+ ),
625
+ );
626
+ }
627
+ });
586
628
 
587
- if (name == "osx32" || name === "osx64") {
588
- dest = path.resolve(
589
- self.getResourcesDirectoryPath(platform),
590
- "app.nw",
591
- file.dest,
592
- );
593
- } else {
594
- dest = path.resolve(platform.releasePath, file.dest);
595
- }
629
+ return Promise.all(copyPromises);
630
+ }
596
631
 
597
- if (file.dest === "package.json" && platform.platformSpecificManifest) {
598
- copyPromises.push(self.writePlatformSpecificManifest(platform, dest));
599
- } else {
600
- copyPromises.push(Utils.copyFile(file.src, dest, self));
601
- }
602
- });
603
- } else if (!self.options.mergeZip) {
604
- // copy the zipped package.nw into the app directory
605
- copyPromises.push(
606
- Utils.copyFile(
607
- self.getZipFile(name),
608
- path.resolve(platform.releasePath, "package.nw"),
609
- self,
610
- ),
611
- );
612
- } else if (name == "osx32" || name == "osx64") {
613
- // zip just copy the app.nw
614
- copyPromises.push(
615
- Utils.copyFile(
616
- self.getZipFile(name),
617
- path.resolve(self.getResourcesDirectoryPath(platform), "app.nw"),
618
- self,
619
- ),
620
- );
621
- } else {
622
- var executableToMergeWith = self.getExecutableName(name);
623
-
624
- // We cat the app.nw file into the .exe / nw
625
- copyPromises.push(
626
- Utils.mergeFiles(
627
- path.resolve(platform.releasePath, executableToMergeWith),
628
- self.getZipFile(name),
629
- platform.chmod,
630
- ),
631
- );
632
- }
633
- });
632
+ getZipFile(platformName) {
633
+ return (this._zips[platformName] && this._zips[platformName].file) || null;
634
+ }
634
635
 
635
- return Promise.all(copyPromises);
636
- };
636
+ writePlatformSpecificManifest(platform, dest) {
637
+ return new Promise(function (resolve, reject) {
638
+ var pkgParentDirectory = path.join(dest, "../");
639
+ if (!fs.existsSync(pkgParentDirectory)) fs.mkdirpSync(pkgParentDirectory);
637
640
 
638
- NwBuilder.prototype.getZipFile = function (platformName) {
639
- return (this._zips[platformName] && this._zips[platformName].file) || null;
640
- };
641
-
642
- NwBuilder.prototype.writePlatformSpecificManifest = function (platform, dest) {
643
- return new Promise(function (resolve, reject) {
644
- var pkgParentDirectory = path.join(dest, "../");
645
- if (!fs.existsSync(pkgParentDirectory)) fs.mkdirpSync(pkgParentDirectory);
641
+ fs.writeFile(
642
+ dest,
643
+ JSON.stringify(platform.platformSpecificManifest),
644
+ function (err) {
645
+ if (err) return reject(err);
646
+ resolve();
647
+ },
648
+ );
649
+ });
650
+ }
646
651
 
647
- fs.writeFile(
648
- dest,
649
- JSON.stringify(platform.platformSpecificManifest),
650
- function (err) {
651
- if (err) return reject(err);
652
- resolve();
653
- },
654
- );
655
- });
656
- };
652
+ handleLinuxApp() {
653
+ var self = this;
657
654
 
658
- NwBuilder.prototype.handleLinuxApp = function () {
659
- var self = this;
655
+ this._forEachPlatform(async function (name, platform) {
656
+ if (["linux64", "linux32"].indexOf(name) < 0) return;
660
657
 
661
- this._forEachPlatform(async function (name, platform) {
662
- if (["linux64", "linux32"].indexOf(name) < 0) return;
658
+ var executableName = self.getExecutableName(name);
663
659
 
664
- var executableName = self.getExecutableName(name);
660
+ await rename(
661
+ resolve(platform.releasePath, "nw"),
662
+ resolve(platform.releasePath, executableName),
663
+ );
664
+ });
665
+ }
665
666
 
666
- await rename(
667
- resolve(platform.releasePath, "nw"),
668
- resolve(platform.releasePath, executableName)
669
- );
670
- });
671
- }
667
+ handleMacApp() {
668
+ var self = this,
669
+ allDone = [];
672
670
 
673
- NwBuilder.prototype.handleMacApp = function () {
674
- var self = this,
675
- allDone = [];
671
+ this._forEachPlatform(async function (name, platform) {
672
+ if (["osx32", "osx64"].indexOf(name) < 0) return;
676
673
 
677
- this._forEachPlatform(async function (name, platform) {
678
- if (["osx32", "osx64"].indexOf(name) < 0) return;
674
+ var executableName = self.getExecutableName(name);
679
675
 
680
- var executableName = self.getExecutableName(name);
676
+ await rename(
677
+ resolve(platform.releasePath, "nwjs.app"),
678
+ resolve(platform.releasePath, executableName),
679
+ );
681
680
 
682
- await rename(
683
- resolve(platform.releasePath, "nwjs.app"),
684
- resolve(platform.releasePath, executableName)
685
- );
681
+ // Let's first handle the mac icon
682
+ if (self.options.macIcns) {
683
+ if (semver.satisfies(self._version.version, "<=0.12.3")) {
684
+ allDone.push(
685
+ Utils.copyFile(
686
+ self.options.macIcns,
687
+ path.resolve(self.getResourcesDirectoryPath(platform), "nw.icns"),
688
+ self,
689
+ ),
690
+ );
691
+ } else {
692
+ allDone.push(
693
+ Utils.copyFile(
694
+ self.options.macIcns,
695
+ path.resolve(
696
+ self.getResourcesDirectoryPath(platform),
697
+ "app.icns",
698
+ ),
699
+ self,
700
+ ),
701
+ );
702
+ allDone.push(
703
+ Utils.copyFile(
704
+ self.options.macIcns,
705
+ path.resolve(
706
+ self.getResourcesDirectoryPath(platform),
707
+ "document.icns",
708
+ ),
709
+ self,
710
+ ),
711
+ );
712
+ }
713
+ }
686
714
 
687
- // Let's first handle the mac icon
688
- if (self.options.macIcns) {
689
- if (semver.satisfies(self._version.version, "<=0.12.3")) {
715
+ // Handle mac credits
716
+ if (self.options.macCredits) {
690
717
  allDone.push(
691
718
  Utils.copyFile(
692
- self.options.macIcns,
693
- path.resolve(self.getResourcesDirectoryPath(platform), "nw.icns"),
694
- self,
695
- ),
696
- );
697
- } else {
698
- allDone.push(
699
- Utils.copyFile(
700
- self.options.macIcns,
701
- path.resolve(self.getResourcesDirectoryPath(platform), "app.icns"),
702
- self,
703
- ),
704
- );
705
- allDone.push(
706
- Utils.copyFile(
707
- self.options.macIcns,
719
+ self.options.macCredits,
708
720
  path.resolve(
709
721
  self.getResourcesDirectoryPath(platform),
710
- "document.icns",
722
+ "Credits.html",
711
723
  ),
712
724
  self,
713
725
  ),
714
726
  );
715
727
  }
716
- }
717
728
 
718
- // Handle mac credits
719
- if (self.options.macCredits) {
720
- allDone.push(
721
- Utils.copyFile(
722
- self.options.macCredits,
723
- path.resolve(
724
- self.getResourcesDirectoryPath(platform),
725
- "Credits.html",
726
- ),
727
- self,
728
- ),
729
+ // Let's handle the Plist
730
+ var PlistPath = path.resolve(
731
+ platform.releasePath,
732
+ self.options.appName + ".app",
733
+ "Contents",
734
+ "Info.plist",
729
735
  );
730
- }
731
736
 
732
- // Let's handle the Plist
733
- var PlistPath = path.resolve(
734
- platform.releasePath,
735
- self.options.appName + ".app",
736
- "Contents",
737
- "Info.plist",
738
- );
739
-
740
- // If the macPlist is a string we just copy the file
741
- if (typeof self.options.macPlist === "string") {
742
- allDone.push(Utils.copyFile(self.options.macPlist, PlistPath, self));
743
- } else {
744
- // Setup the Plist
745
- var plistOptions = Utils.getPlistOptions(
746
- {
747
- name: self.options.appName,
748
- version: self.options.appVersion,
749
- copyright: self._appPkg.copyright,
750
- },
751
- self.options.macPlist,
752
- );
753
-
754
- allDone.push(Utils.editPlist(PlistPath, PlistPath, plistOptions));
755
- }
756
- });
737
+ // If the macPlist is a string we just copy the file
738
+ if (typeof self.options.macPlist === "string") {
739
+ allDone.push(Utils.copyFile(self.options.macPlist, PlistPath, self));
740
+ } else {
741
+ // Setup the Plist
742
+ var plistOptions = Utils.getPlistOptions(
743
+ {
744
+ name: self.options.appName,
745
+ version: self.options.appVersion,
746
+ copyright: self._appPkg.copyright,
747
+ },
748
+ self.options.macPlist,
749
+ );
757
750
 
758
- return Promise.all(allDone);
759
- };
751
+ allDone.push(Utils.editPlist(PlistPath, PlistPath, plistOptions));
752
+ }
753
+ });
760
754
 
761
- NwBuilder.prototype.handleWinApp = function () {
762
- var self = this,
763
- allDone = [];
755
+ return Promise.all(allDone);
756
+ }
764
757
 
765
- this._forEachPlatform(async function (name, platform) {
766
- if (
767
- (!self.options.winIco && !self.options.winVersionString) ||
768
- ["win32", "win64"].indexOf(name) < 0
769
- )
770
- return;
758
+ handleWinApp() {
759
+ var self = this,
760
+ allDone = [];
771
761
 
772
- var executableName = self.getExecutableName(name);
773
- var executablePath = path.resolve(platform.releasePath, executableName);
762
+ this._forEachPlatform(async function (name, platform) {
763
+ if (
764
+ (!self.options.winIco && !self.options.winVersionString) ||
765
+ ["win32", "win64"].indexOf(name) < 0
766
+ )
767
+ return;
774
768
 
775
- await rename(
776
- resolve(platform.releasePath, "nw.exe"),
777
- resolve(platform.releasePath, executableName),
778
- );
769
+ var executableName = self.getExecutableName(name);
770
+ var executablePath = path.resolve(platform.releasePath, executableName);
779
771
 
780
- var rcConf = {};
781
- if (self.options.winVersionString) {
782
- rcConf["version-string"] = Object.assign(
783
- {},
784
- {
785
- // The process name used in the Task Manager
786
- FileDescription: self.options.appName,
787
- },
788
- self.options.winVersionString,
772
+ await rename(
773
+ resolve(platform.releasePath, "nw.exe"),
774
+ resolve(platform.releasePath, executableName),
789
775
  );
790
- }
791
- if (self.options.winIco && self.options.useRcedit) {
792
- rcConf["icon"] = path.resolve(self.options.winIco);
793
- }
794
776
 
795
- var updateVersionStringPromise = rcedit(executablePath, rcConf);
777
+ var rcConf = {};
778
+ if (self.options.winVersionString) {
779
+ rcConf["version-string"] = Object.assign(
780
+ {},
781
+ {
782
+ // The process name used in the Task Manager
783
+ FileDescription: self.options.appName,
784
+ },
785
+ self.options.winVersionString,
786
+ );
787
+ }
788
+ if (self.options.winIco && self.options.useRcedit) {
789
+ rcConf["icon"] = path.resolve(self.options.winIco);
790
+ }
796
791
 
797
- var updateIconsPromise = updateVersionStringPromise.then(function () {
798
- return new Promise(function (resolve, reject) {
799
- if (!self.options.winIco || self.options.useRcedit) {
800
- resolve();
801
- } else {
802
- self.emit("log", "Update " + name + " executable icon");
803
- // Set icon
804
- winresourcer(
805
- {
806
- operation: "Update",
807
- exeFile: executablePath,
808
- resourceType: "Icongroup",
809
- resourceName: "IDR_MAINFRAME",
810
- lang: 1033, // Required, except when updating or deleting
811
- resourceFile: path.resolve(self.options.winIco),
812
- },
813
- function (err) {
814
- if (!err) {
815
- resolve();
816
- } else {
817
- reject(
818
- "Error while updating the Windows icon." +
819
- (process.platform !== "win32"
820
- ? " Wine (winehq.org) must be installed to add custom icons from Mac and Linux."
821
- : ""),
822
- );
823
- }
824
- },
825
- );
826
- }
792
+ var updateVersionStringPromise = rcedit(executablePath, rcConf);
793
+
794
+ var updateIconsPromise = updateVersionStringPromise.then(function () {
795
+ return new Promise(function (resolve, reject) {
796
+ if (!self.options.winIco || self.options.useRcedit) {
797
+ resolve();
798
+ } else {
799
+ log.debug("Update " + name + " executable icon");
800
+ // Set icon
801
+ winresourcer(
802
+ {
803
+ operation: "Update",
804
+ exeFile: executablePath,
805
+ resourceType: "Icongroup",
806
+ resourceName: "IDR_MAINFRAME",
807
+ lang: 1033, // Required, except when updating or deleting
808
+ resourceFile: path.resolve(self.options.winIco),
809
+ },
810
+ function (err) {
811
+ if (!err) {
812
+ resolve();
813
+ } else {
814
+ reject(
815
+ "Error while updating the Windows icon." +
816
+ (process.platform !== "win32"
817
+ ? " Wine (winehq.org) must be installed to add custom icons from Mac and Linux."
818
+ : ""),
819
+ );
820
+ }
821
+ },
822
+ );
823
+ }
824
+ });
827
825
  });
828
- });
829
826
 
830
- // build a promise chain
831
- allDone.push(updateIconsPromise);
832
- });
827
+ // build a promise chain
828
+ allDone.push(updateIconsPromise);
829
+ });
833
830
 
834
- return Promise.all(allDone);
835
- };
831
+ return Promise.all(allDone);
832
+ }
836
833
 
837
- NwBuilder.prototype.runApp = async function () {
838
- const options = this.options;
834
+ async runApp() {
835
+ const options = this.options;
839
836
 
840
- let platform = options.currentPlatform.slice(0, options.currentPlatform.length - 2)
841
- let arch = "x" + options.currentPlatform.slice(options.currentPlatform.length - 2);
837
+ let platform = options.currentPlatform.slice(
838
+ 0,
839
+ options.currentPlatform.length - 2,
840
+ );
841
+ let arch =
842
+ "x" + options.currentPlatform.slice(options.currentPlatform.length - 2);
842
843
 
843
- await run({
844
- version: options.version,
845
- flavor: options.flavor,
846
- platform: platform,
847
- arch: arch,
848
- srcDir: options.files,
849
- cacheDir: options.cacheDir,
850
- argv: options.argv,
851
- });
844
+ await run({
845
+ version: options.version,
846
+ flavor: options.flavor,
847
+ platform: platform,
848
+ arch: arch,
849
+ srcDir: options.files,
850
+ cacheDir: options.cacheDir,
851
+ argv: options.argv,
852
+ });
853
+ }
852
854
 
853
- };
855
+ isAppRunning() {
856
+ return this._nwProcess !== undefined;
857
+ }
854
858
 
855
- NwBuilder.prototype.isAppRunning = function () {
856
- return this._nwProcess !== undefined;
857
- };
859
+ getAppProcess() {
860
+ return this._nwProcess;
861
+ }
858
862
 
859
- NwBuilder.prototype.getAppProcess = function () {
860
- return this._nwProcess;
861
- };
863
+ _forEachPlatform(fn) {
864
+ _.forEach(this._platforms, function (platform, name) {
865
+ return fn(name, platform);
866
+ });
867
+ }
862
868
 
863
- NwBuilder.prototype._forEachPlatform = function (fn) {
864
- _.forEach(this._platforms, function (platform, name) {
865
- return fn(name, platform);
866
- });
867
- };
869
+ // Mac only
870
+ getResourcesDirectoryPath(platform) {
871
+ return path.resolve(
872
+ platform.releasePath,
873
+ this.options.appName + ".app",
874
+ "Contents",
875
+ "Resources",
876
+ );
877
+ }
868
878
 
869
- // Mac only
870
- NwBuilder.prototype.getResourcesDirectoryPath = function (platform) {
871
- return path.resolve(
872
- platform.releasePath,
873
- this.options.appName + ".app",
874
- "Contents",
875
- "Resources",
876
- );
877
- };
879
+ // Don't use if legacy version
880
+ getExecutableName(platform) {
881
+ var executableExtension = "";
878
882
 
879
- // Don't use if legacy version
880
- NwBuilder.prototype.getExecutableName = function (platform) {
881
- var executableExtension = "";
883
+ if (platform.indexOf("osx") === 0) {
884
+ executableExtension = ".app";
885
+ } else if (platform.indexOf("win") === 0) {
886
+ executableExtension = ".exe";
887
+ }
882
888
 
883
- if (platform.indexOf("osx") === 0) {
884
- executableExtension = ".app";
885
- } else if (platform.indexOf("win") === 0) {
886
- executableExtension = ".exe";
889
+ return this.options.appName + executableExtension;
887
890
  }
888
891
 
889
- return this.options.appName + executableExtension;
890
- };
891
-
892
- NwBuilder.prototype.setPlatformCacheDirectory = function (
893
- platformName,
894
- platform,
895
- version,
896
- flavor,
897
- ) {
898
- if (!platform.cache) {
899
- platform.cache = path.resolve(
900
- this.options.cacheDir,
901
- version + "-" + flavor,
902
- platformName,
903
- );
892
+ setPlatformCacheDirectory(platformName, platform, version, flavor) {
893
+ if (!platform.cache) {
894
+ platform.cache = path.resolve(
895
+ this.options.cacheDir,
896
+ version + "-" + flavor,
897
+ platformName,
898
+ );
899
+ }
904
900
  }
905
- };
906
-
907
- NwBuilder.prototype.isPlatformCached = function (
908
- platformName,
909
- platform,
910
- version,
911
- flavor,
912
- ) {
913
- this.setPlatformCacheDirectory(platformName, platform, version, flavor);
914
- if (this.options.forceDownload) {
915
- return false;
916
- }
917
- this.preparePlatformFiles(platformName, platform, version);
918
- return checkCache(platform.cache, platform.files);
919
- };
920
901
 
921
- // returns a Boolean; true if the desired platform is supported
922
- NwBuilder.prototype.preparePlatformFiles = function (
923
- platformName,
924
- platform,
925
- version,
926
- ) {
927
- // return if platform.files is already prepared
928
- if (
929
- Object.keys(platform.files)[0] !==
930
- Object.keys(Platforms[platformName].files)[0]
931
- ) {
932
- return true;
902
+ isPlatformCached(platformName, platform, version, flavor) {
903
+ this.setPlatformCacheDirectory(platformName, platform, version, flavor);
904
+ if (this.options.forceDownload) {
905
+ return false;
906
+ }
907
+ this.preparePlatformFiles(platformName, platform, version);
908
+ return checkCache(platform.cache, platform.files);
933
909
  }
934
910
 
935
- if (semver.satisfies(version, "<0.12.3")) {
936
- return !Object.keys(platform.files).every(function (range) {
937
- if (semver.satisfies(version, range)) {
938
- platform.files = platform.files[range];
939
- if ("string" === typeof platform.files) {
940
- platform.files = [platform.files];
941
- }
942
- return false;
943
- }
911
+ // returns a Boolean; true if the desired platform is supported
912
+ preparePlatformFiles(platformName, platform, version) {
913
+ // return if platform.files is already prepared
914
+ if (
915
+ Object.keys(platform.files)[0] !==
916
+ Object.keys(Platforms[platformName].files)[0]
917
+ ) {
944
918
  return true;
945
- });
946
- }
919
+ }
947
920
 
948
- platform.files = ["*"]; // otherwise bad stuff will happen like at attempt to download legacy version files
949
- // all we can do here is assume it's oke because this._version might not exist yet, but callers of this function
950
- // will check properly where necessary
951
- return true;
952
- };
921
+ if (semver.satisfies(version, "<0.12.3")) {
922
+ return !Object.keys(platform.files).every(function (range) {
923
+ if (semver.satisfies(version, range)) {
924
+ platform.files = platform.files[range];
925
+ if ("string" === typeof platform.files) {
926
+ platform.files = [platform.files];
927
+ }
928
+ return false;
929
+ }
930
+ return true;
931
+ });
932
+ }
933
+
934
+ platform.files = ["*"]; // otherwise bad stuff will happen like at attempt to download legacy version files
935
+ // all we can do here is assume it's oke because this._version might not exist yet, but callers of this function
936
+ // will check properly where necessary
937
+ return true;
938
+ }
939
+ }
953
940
 
954
941
  const nwbuild = (options) => {
955
942
  let nw = new NwBuilder(options);
@@ -962,7 +949,7 @@ const nwbuild = (options) => {
962
949
  nw.run();
963
950
  return 0;
964
951
  } else {
965
- console.error("[ WARN ] Invalid mode option.");
952
+ log.warn("[ WARN ] Invalid mode option.");
966
953
  return 1;
967
954
  }
968
955
  };