File size: 1,265 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
// @flow
const { readdirSync, statSync } = require('fs');
const { join } = require('path');
const { spawn } = require('child_process');
const getDirs = p =>
readdirSync(p).filter(f => statSync(join(p, f)).isDirectory());
// Get a list of all non-build directories in the root folder
const rootDirs = getDirs(join(__dirname, '..')).filter(
dir => dir.indexOf('build') === -1
);
// Filter them by directories that have a package.json
const workerDirs = rootDirs.filter(dir => {
let result = false;
readdirSync(dir).forEach(file => {
if (file === 'package.json') {
result = true;
}
});
return result;
});
const installDeps = (dir, callback) => {
const stream = spawn(
process.platform === 'win32' ? 'yarn.cmd' : 'yarn',
['install', '--no-progress', '--non-interactive'],
{ cwd: join(__dirname, '..', dir), stdio: 'inherit' }
);
stream.on('close', code => {
callback();
});
};
const installWorkerDeps = index => {
const dir = workerDirs[index];
if (!dir) return process.exit(0);
installDeps(dir, () => {
installWorkerDeps(index + 1);
});
};
// Install the dependencies in the root folder first
// then recursilvey install them for all the workers
installDeps('/', () => {
installWorkerDeps(0);
});
|