-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
bin.js
51 lines (42 loc) · 1.27 KB
/
bin.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
#!/usr/bin/env node
var makeTap = require('./index.js')
var cp = require('child_process')
var minimist = require('minimist')
var path = require('path')
var concat = require('concat-stream')
var STANDARD_CMD = path.join(require.resolve('standard'), '../.bin/standard')
if (/^win/.test(process.platform)) STANDARD_CMD += '.cmd'
var argv = minimist(process.argv.slice(2), {
boolean: [
'stdin'
]
})
process.stdout.on('error', function () {})
var stream
if (!process.stdin.isTTY || argv._[0] === '-' || argv.stdin) {
stream = process.stdin
} else {
var args = process.argv.slice(2)
var standard = cp.spawn(STANDARD_CMD, args)
standard.stderr.pipe(process.stderr)
stream = standard.stdout
var standardCode
standard.on('exit', function (code) { standardCode = code })
process.on('exit', function (code) {
if (code === 0 && standardCode !== 0) {
console.error('non-zero exit from the `standard` command')
process.exit(standardCode)
}
})
}
var concatStream = concat({ encoding: 'string' }, function (data) {
var output = makeTap(data, { complex: true })
console.log(output.output)
if (output.errors) process.exit(1)
})
stream.pipe(concatStream)
stream.on('error', handleError)
function handleError (err) {
console.error(err)
process.exit(1)
}