Skip to content

Instantly share code, notes, and snippets.

@tibawatanabe
Created September 24, 2017 20:34
Show Gist options
  • Save tibawatanabe/c2e002dd02727ba5df74ee1bfe9216cf to your computer and use it in GitHub Desktop.
Save tibawatanabe/c2e002dd02727ba5df74ee1bfe9216cf to your computer and use it in GitHub Desktop.
Node script to install peer-dependencies
'use strict'
const exec = require('child_process').exec;
const { promisify } = require('util');
const execAsPromise = promisify(exec);
const packageJson = require('./package.json');
const commands = Object.entries(packageJson.peerDependencies)
.map(([key, value]) => `npm install ${key}@${value}`)
.map(command => {
return Promise.resolve()
.then(() => console.log(`[BEGIN] ${command}`))
.then(execAsPromise(command))
.then(() => console.log(`[DONE] ${command}`));
});
async function install() {
try {
await Promise.all(commands);
console.log('Installed peer dependencies');
} catch (err) {
console.error(err);
}
}
install().then();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment