This repository has been archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·64 lines (54 loc) · 1.55 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env node
const program = require('commander')
const glob = require('glob')
const fs = require('fs')
const util = require('util')
const analyze = require('./index')
program
.name('custom-element-analyzer')
.usage('[options] <directory or file> ...')
.option('-d, --debug', 'output extra debugging and output to console instead of file')
.option('-o, --out <file-name>', 'output file name. Defaults to custom-elements.json')
.option('-n, --no-cache', 'disable jsdoc caching to force regenerating source jsdoc')
.parse(process.argv)
if (program.debug) console.log(program.opts())
if (program.debug) {
console.log(program.args)
}
const files = []
if (program.args.length > 0) {
program.args.forEach((token) => {
try {
const stats = fs.lstatSync(token)
if (stats.isFile()) {
files.push(token)
} else {
// glob the path
const filesFound = glob.sync(`${token}/**/*.js`)
files.splice(files.length, 0, ...filesFound)
}
} catch (e) {
// glob the path
const filesFound = glob.sync(`${token}/**/*.js`)
files.splice(files.length, 0, ...filesFound)
}
})
} else {
program.help()
}
if (program.debug) {
console.log('Found files', files)
}
const document = analyze(files)
const json = JSON.stringify(document, null, 2)
if (program.debug) {
console.log('Output', json)
} else {
const outFile = program.out || 'custom-elements.json'
try {
fs.writeFileSync(outFile, json)
console.log(`Finished writing file ${outFile}`)
} catch (e) {
console.error(err)
}
}