Skip to content
Permalink
Browse files

fix(installer): await promises through the linux install chain

  • Loading branch information
MarshallOfSound committed Dec 31, 2016
1 parent 0b04413 commit a0b5ac703f269d91b13e183140791c1f895d676a
Showing with 21 additions and 17 deletions.
  1. +1 −1 src/installers/linux/deb.js
  2. +1 −1 src/installers/linux/rpm.js
  3. +19 −15 src/util/linux-installer.js
@@ -1,5 +1,5 @@
import { sudo } from '../../util/linux-installer';

export default async (filePath) => {
sudo('Debian', 'gdebi', `-n ${filePath}`);
await sudo('Debian', 'gdebi', `-n ${filePath}`);
};
@@ -1,5 +1,5 @@
import { sudo } from '../../util/linux-installer';

export default async (filePath) => {
sudo('RPM', 'dnf', `--assumeyes --nogpgcheck install ${filePath}`);
await sudo('RPM', 'dnf', `--assumeyes --nogpgcheck install ${filePath}`);
};
@@ -1,25 +1,29 @@
import { spawnSync } from 'child_process';
import { default as Sudoer } from 'electron-sudo';

async function which(type, prog, promise) {
const which = async (type, prog, promise) => {
if (spawnSync('which', [prog]).status === 0) {
await promise;
} else {
throw new Error(`${prog} is required to install ${type} packages`);
}
}
};

async function sudo(type, prog, args) {
const sudoer = new Sudoer({ name: 'Electron Forge' });
which(type, prog, sudoer.spawn(`${prog} ${args}`).then((child) => {
child.on('exit', async (code) => {
if (code !== 0) {
console.error(child.output.stdout.toString('utf8'));
console.error(child.output.stderr.toString('utf8'));
throw new Error(`${prog} failed with status code ${code}`);
}
});
}));
}
export const sudo = (type, prog, args) =>
new Promise((resolve, reject) => {
const sudoer = new Sudoer({ name: 'Electron Forge' });

export { which as default, sudo };
which(type, prog, sudoer.spawn(`${prog} ${args}`)
.then((child) => {
child.on('exit', async (code) => {
if (code !== 0) {
console.error(child.output.stdout.toString('utf8').red);
console.error(child.output.stderr.toString('utf8').red);
return reject(new Error(`${prog} failed with status code ${code}`));
}
resolve();
});
}));
});

export default which;

0 comments on commit a0b5ac7

Please sign in to comment.
You can’t perform that action at this time.