Skip to content

Instantly share code, notes, and snippets.

@aalemayhu
Created August 8, 2019 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aalemayhu/7107306859437604949bad0192702cdf to your computer and use it in GitHub Desktop.
Save aalemayhu/7107306859437604949bad0192702cdf to your computer and use it in GitHub Desktop.
Install all of the requires from a Javascript file using yarn
const { execFile } = require('child_process');
const fs = require('fs');
fs.readFile('./input-file.js', (err, data) => {
if (err) throw err;
let payload = data.toString();
let lines = payload.split('\n').filter(x => x.includes('require'));
let requires = lines.map(x => x.split('require')[1]);
let modules = requires.map(x => x.split("'")[1]);
for (const m of modules) {
const child = execFile('/usr/bin/yarn', ['add', m], (error, stdout, stderr) => {
if (error) {
throw error;
}
console.log(stdout);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment