/
cli.js
executable file
·54 lines (44 loc) · 1.2 KB
/
cli.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
#!/usr/bin/env node
var quote = require('shell-quote').quote
var minimist = require('minimist')
var path = require('path')
var bulk = require('./')
var fs = require('fs')
var cwd = process.cwd()
var argv = []
var cmd = []
for (var i = 2; i < process.argv.length; i++) {
var arg = process.argv[i]
if (arg.charAt(0) === '-') {
argv.push(arg)
continue
}
cmd = process.argv.slice(i)
break
}
// Currently extracting command-line arguments
// in the hopes of avoiding backwards-compatibility
// issues later
var name = cmd.shift()
argv = minimist(argv)
cmd = quote(cmd)
if (!name) return bail('Please specify a package namespace to use.')
if (!cmd.trim()) return bail('Please specify a command to run.')
bulk(name, cmd, cwd, function(err) {
if (err) throw err
}).on('spawn', function(CWD, proc) {
console.error()
console.error(path.relative(cwd, CWD))
console.error('> ' + cmd)
console.error()
proc.stdout.pipe(process.stdout)
proc.stderr.pipe(process.stderr)
})
function bail(err) {
console.error()
console.error(err)
console.error()
fs.createReadStream(path.join(__dirname, 'usage.txt'))
.once('close', function() { console.error() })
.pipe(process.stderr)
}