-
Notifications
You must be signed in to change notification settings - Fork 10
/
yarn-recursive.js
executable file
·46 lines (35 loc) · 1.19 KB
/
yarn-recursive.js
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
#!/usr/bin/env node
const path = require('path');
const shell = require('shelljs');
const argv = require('yargs').argv;
const clc = require('cli-color');
function packageJsonLocations(dirname) {
return shell.find(dirname)
.filter(fname => !(fname.indexOf('node_modules') > -1 || fname[0] === '.') && path.basename(fname) === 'package.json')
.map(fname => path.dirname(fname));
}
function yarn(directoryName) {
let command = 'yarn';
if (argv.cmd)
command += ' ' + argv.cmd;
if (argv.opt)
command += ' ' + argv.opt;
console.log(clc.blueBright('Current yarn path: ' + directoryName + path.sep + 'package.json...'));
shell.cd(directoryName);
let result = shell.exec(command);
return {
directoryName: directoryName,
exitCode: result.code
};
}
function filterRoot(directoryName) {
return path.normalize(directoryName) !== path.normalize(process.cwd());
}
if (require.main === module) {
let exitCode = packageJsonLocations(process.cwd())
.filter(argv.skipRoot ? filterRoot : filtered => filtered)
.map(yarn)
.reduce((code, result) =>result.exitCode > code ? result.exitCode : code, 0);
console.log(clc.green('End of yarns'));
process.exit(exitCode);
}