forked from emgeee/recursive-install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recursive-install.js
executable file
·56 lines (47 loc) · 1.25 KB
/
recursive-install.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
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
var path = require('path')
var shell = require('shelljs')
var argv = require('yargs').argv
function noop (x) { return x }
function getPackageJsonLocations (dirname) {
return shell.find(dirname)
.filter(function (fname) {
return !(fname.indexOf('node_modules') > -1 || fname[0] === '.') &&
path.basename(fname) === 'package.json'
})
.map(function (fname) {
return path.dirname(fname)
})
}
function npmInstall (dir) {
shell.cd(dir)
console.log('Installing ' + dir + '/package.json...')
var result = shell.exec('npm install')
console.log('')
return {
dirname: dir,
exitCode: result.code
}
}
function filterRoot (dir) {
if (path.normalize(dir) === path.normalize(process.cwd())) {
console.log('Skipping root package.json...')
return false
} else {
return true
}
}
if (require.main === module) {
var exitCode = getPackageJsonLocations(process.cwd())
.filter(argv.skipRoot ? filterRoot : noop)
.map(npmInstall)
.reduce(function (code, result) {
return result.exitCode > code ? result.exitCode : code
}, 0)
process.exit(exitCode)
}
module.exports = {
getPackageJsonLocations: getPackageJsonLocations,
npmInstall: npmInstall,
filterRoot: filterRoot
};