-
Notifications
You must be signed in to change notification settings - Fork 11
/
cli.js
executable file
·35 lines (30 loc) · 1003 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
#! /usr/bin/env node
const program = require('commander')
const pkg = require('../package.json')
const Validator = require('..')
const path = require('path')
const Buffer = require('buffer').Buffer
program
.version(pkg.version)
.option('-c, --conf [path]', 'validator configuration file [rules.json]')
.option('-f, --fast', 'use fast mode, abort on first error')
.option('-t, --type <type>', 'optional, specify the type of mip page')
.parse(process.argv)
var html = Buffer.alloc(0)
var config
if (program['conf']) {
var configPath = path.resolve(process.cwd(), program['conf'])
config = require(configPath)
}
var validator = config ? Validator(config) : Validator()
process.stdin.on('data', function(buf) {
html = Buffer.concat([html, buf])
})
process.stdin.on('end', function() {
var result = validator.validate(html, {
fastMode: program['fast'],
type: program['type']
})
var str = JSON.stringify(result, null, 4)
console.log(str)
})