-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·84 lines (69 loc) · 1.59 KB
/
index.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/local/bin/node
'use strict'
const chalk = require('chalk')
const CLI = require('clui')
const exec = require('child_process').exec
const figlet = require('figlet')
const fs = require('fs')
const path = require('path')
const async = require('async')
const Spinner = CLI.Spinner
const Progress = CLI.Progress
const progress_bar = new Progress(50)
const count = {
current: 0
, total: 0
, installed: 0
}
console.log(
chalk.blue(
figlet.textSync('install-all')
)
)
function runInstall(dir, cb) {
exec('npm install', { cwd: path.join('.', dir) }, (err, stdout, stderr) => {
if (err) {
return cb(err)
}
// Update counts and update progress bar
count.installed++
count.current++
console.log(
chalk.yellowBright(dir), progress_bar.update(count.current, count.total)
)
cb()
})
}
function checkDirForPackage(dir, cb) {
const workingDir = path.join('.', dir)
if (!fs.lstatSync(workingDir).isDirectory()) {
return cb()
}
fs.readdir(workingDir, (err, files) => {
if (err) return cb(err)
if (!files.includes('package.json')) {
count.current++
progress_bar.update(count.current, count.total)
return cb()
}
runInstall(dir, cb)
})
}
function readDirs(cb) {
fs.readdir('.', (err, files) => {
if (err) throw err
count.total = files.length
async.eachLimit(files, 4, checkDirForPackage, (err) => {
if (err) throw err
cb()
})
})
}
readDirs(() => {
console.log(
chalk.green(
'\nPackage install complete' +
`\n${count.installed} package installations performed.`
)
)
})