Skip to content

Commit

Permalink
chore: refactor platform parsing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushmanchhabra committed Apr 12, 2024
1 parent 305e543 commit 7bd4be8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
28 changes: 13 additions & 15 deletions lib/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ const {
class NwBuilder {
constructor(options) {
this.init(options).then(() => {
this._platforms = { ...Platforms };

// clear all unused platforms
for (const name in this._platforms) {
if (
this.options.platforms &&
this.options.platforms.indexOf(name) === -1
)
delete this._platforms[name];
/* Make a shallow copy of the Platforms object */
this.platforms = Object.assign({}, Platforms);
/* Clear all unused platforms */
for (const platform of Object.keys(this.platforms)) {
if (!options.platforms.includes(platform)) {
delete this.platforms[platform];
}
}
}).catch((error) => {
console.error(error);
Expand Down Expand Up @@ -467,7 +465,7 @@ class NwBuilder {
self._files,
self,
JSON.stringify(
self._platforms[platformName].platformSpecificManifest,
self.platforms[platformName].platformSpecificManifest,
),
zipOptions,
).then(function (file) {
Expand Down Expand Up @@ -595,8 +593,8 @@ class NwBuilder {
var executableName = self.getExecutableName(name);

await fs.promises.rename(
resolve(platform.releasePath, "nwjs.app"),
resolve(platform.releasePath, executableName),
path.resolve(platform.releasePath, "nwjs.app"),
path.resolve(platform.releasePath, executableName),
);

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

await fs.promises.rename(
resolve(platform.releasePath, "nw.exe"),
resolve(platform.releasePath, executableName),
path.resolve(platform.releasePath, "nw.exe"),
path.resolve(platform.releasePath, executableName),
);

var rcConf = {};
Expand Down Expand Up @@ -782,7 +780,7 @@ class NwBuilder {
}

_forEachPlatform(fn) {
_.forEach(this._platforms, function (platform, name) {
_.forEach(this.platforms, function (platform, name) {
return fn(name, platform);
});
}
Expand Down
1 change: 0 additions & 1 deletion test/demo.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const NwBuilder = require('nw-builder');
const { version } = require('yargs');

const nw = new NwBuilder({
version: '0.86.0',
Expand Down

0 comments on commit 7bd4be8

Please sign in to comment.