-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.js
executable file
·47 lines (38 loc) · 868 Bytes
/
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
#!/usr/bin/env node
var concat = require('concat-stream')
, jsdom_eval = require('./index')
, path = require('path')
, fs = require('fs')
var remaining = 2
, html
, js
var argv = require('minimist')(process.argv.slice(2))
if(!process.stdin.isTTY) {
process.stdin.pipe(concat(got_js))
} else if(argv._.length) {
fs.createReadStream(path.resolve(process.cwd(), argv._[0]))
.pipe(concat(got_js))
} else {
--remaining
}
if(argv.html || argv.H) {
fs.createReadStream(path.resolve(process.cwd(), argv.html || argv.H))
.pipe(concat(got_html))
} else {
--remaining
}
function got_js(data) {
js = data.toString()
if(!--remaining) {
jsdom_eval(js, html, log)
}
}
function got_html(data) {
html = data.toString()
if(!--remaining) {
jsdom_eval(js, html, log)
}
}
function log(data) {
console[data.method](data.message)
}