/
index.js
41 lines (36 loc) · 1.01 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
36
37
38
39
40
41
#!/usr/bin/env node
var pjson = require('./package.json')
var path = require('path')
var Command = require('commander').Command
var fs = require('graceful-fs')
var program = new Command(pjson.name)
var crc2json = require('./crc2json.js'), cwd
program
.version(pjson.version)
.option("-o, --output <file>", 'saves json to <file>')
.option("-p, --pretty", 'output as pretty print json')
.option("-d, --directory <dir>", "scan <dir> or current directory if omitted")
.parse(process.argv)
if (program.directory) {
cwd = path.resolve(program.directory)
} else {
cwd = process.cwd()
}
crc2json(cwd, complete)
function complete(map) {
var content
if (program.pretty) {
content = JSON.stringify(map, null, '\t')
} else {
content = JSON.stringify(map)
}
if (program.output) {
var resolvedOutputFile = path.resolve(program.output)
fs.writeFile(resolvedOutputFile, content, function(err) {
if (err) throw err
console.log("Written to %s", resolvedOutputFile)
})
} else {
console.log(content)
}
}