Created
May 19, 2018 12:22
-
-
Save MatthieuLemoine/522f829764abd4e6b08a1819993c9d08 to your computer and use it in GitHub Desktop.
Install dependencies for all projects in current dir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
const { promisify } = require('util'); | |
const { exec: childExec } = require('child_process'); | |
const ProgressBar = require('ascii-progress'); | |
const readDir = promisify(fs.readdir); | |
const exec = promisify(childExec); | |
const workingDir = process.cwd(); | |
(async () => { | |
try { | |
const projects = await readDir(workingDir); | |
const bar = new ProgressBar({ | |
total: projects.length, | |
schema: ' |:bar| :current/:total :percent :elapseds :etas :name', | |
}); | |
const failures = (await Promise.all(projects.map(async (project) => { | |
const directory = path.join(workingDir, project); | |
try { | |
await exec( | |
`yarn --ignore-engines --cache-folder=${path.join( | |
'/', | |
'tmp', | |
project, | |
'.yarn-cache', | |
)} `, | |
{ cwd: directory }, | |
); | |
bar.tick({ | |
name: `success: ${project}`, | |
}); | |
return null; | |
} catch (error) { | |
bar.tick({ | |
name: `failure: ${project}`, | |
}); | |
return { project, error }; | |
} | |
}))).filter(_ => _); | |
console.log(`${failures.length} have failed`); | |
console.log(failures); | |
} catch (e) { | |
console.error(e); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment