-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·35 lines (30 loc) · 1.16 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
#!/usr/bin/env node
const program = require('commander')
const chalk = require('chalk')
const pkg = require('./package.json')
const runParseCode = require('./lib/index')
const log = console.log
program
.version(pkg.version)
.arguments('[parseFiles...]')
.option('-m, --module', 'a modular way to parse code', 'script')
.option('-a, --all', 'check code use all rules: include instance method & static method', false)
.option('-mini, --miniprogram', 'check miniprogram grammar', false)
.option('-o, --output <output>', 'output path of result log', 'es-check.log')
.option('-e, --ecma <version>', 'version of rules applied', '')
.action((parseFiles, options) => {
const files = parseFiles.length ? parseFiles : []
const esmodule = options.module
const checkMiniprogram = options.miniprogram
const version = options.ecma
const useAllRules = options.all
const output = options.output
const rs = runParseCode({ version, esmodule, files, useAllRules, output, checkMiniprogram })
if (rs.code !== 0) {
log(chalk.red(rs.msg))
process.exitCode = rs.code
} else {
log(chalk.green(rs.msg))
}
})
program.parse(process.argv)