Skip to content

Commit 7bd4be8

Browse files
chore: refactor platform parsing logic
1 parent 305e543 commit 7bd4be8

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

lib/index.cjs

+13-15
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ const {
2828
class NwBuilder {
2929
constructor(options) {
3030
this.init(options).then(() => {
31-
this._platforms = { ...Platforms };
32-
33-
// clear all unused platforms
34-
for (const name in this._platforms) {
35-
if (
36-
this.options.platforms &&
37-
this.options.platforms.indexOf(name) === -1
38-
)
39-
delete this._platforms[name];
31+
/* Make a shallow copy of the Platforms object */
32+
this.platforms = Object.assign({}, Platforms);
33+
/* Clear all unused platforms */
34+
for (const platform of Object.keys(this.platforms)) {
35+
if (!options.platforms.includes(platform)) {
36+
delete this.platforms[platform];
37+
}
4038
}
4139
}).catch((error) => {
4240
console.error(error);
@@ -467,7 +465,7 @@ class NwBuilder {
467465
self._files,
468466
self,
469467
JSON.stringify(
470-
self._platforms[platformName].platformSpecificManifest,
468+
self.platforms[platformName].platformSpecificManifest,
471469
),
472470
zipOptions,
473471
).then(function (file) {
@@ -595,8 +593,8 @@ class NwBuilder {
595593
var executableName = self.getExecutableName(name);
596594

597595
await fs.promises.rename(
598-
resolve(platform.releasePath, "nwjs.app"),
599-
resolve(platform.releasePath, executableName),
596+
path.resolve(platform.releasePath, "nwjs.app"),
597+
path.resolve(platform.releasePath, executableName),
600598
);
601599

602600
// Let's first handle the mac icon
@@ -691,8 +689,8 @@ class NwBuilder {
691689
var executablePath = path.resolve(platform.releasePath, executableName);
692690

693691
await fs.promises.rename(
694-
resolve(platform.releasePath, "nw.exe"),
695-
resolve(platform.releasePath, executableName),
692+
path.resolve(platform.releasePath, "nw.exe"),
693+
path.resolve(platform.releasePath, executableName),
696694
);
697695

698696
var rcConf = {};
@@ -782,7 +780,7 @@ class NwBuilder {
782780
}
783781

784782
_forEachPlatform(fn) {
785-
_.forEach(this._platforms, function (platform, name) {
783+
_.forEach(this.platforms, function (platform, name) {
786784
return fn(name, platform);
787785
});
788786
}

test/demo.cjs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const NwBuilder = require('nw-builder');
2-
const { version } = require('yargs');
32

43
const nw = new NwBuilder({
54
version: '0.86.0',

0 commit comments

Comments
 (0)