-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
70 lines (60 loc) · 1.29 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
65
66
67
68
69
70
#!/usr/bin/env node
var apiez = require('./index'),
args = process.argv.slice(2),
api,
x,
f;
if (!args.length) {
console.log('Usage:\n\n apiez package [formatter]')
process.exit(0)
}
try {
x = require(args[0])
if (args.length > 1)
f = require(args[1])
f = typeof f == 'function' && f || null
} catch (e) {
console.error(e.message)
process.exit(1)
}
api = apiez(x)
if (f) {
console.log(f(api))
} else
echo(api)
function echo(api) {
Object.keys(api).forEach(function(name) {
console.log(format('', name, api[name]).join('\n'))
}, api)
}
function format(prefix, name, x, lines) {
lines = lines || []
lines.push(prefix + name);
if (x.extends) lines.push(
prefix + ' extends ' + x.extends)
if (x.params) {
lines.push(prefix + ' params');
x.params.forEach(function(a) {
lines.push(prefix + ' ' + a[0])
a.forEach(function(c, i) {
if (!i) return
lines.push(prefix + ' ' + c)
})
})
}
if (x.notes) {
lines.push(prefix + ' notes');
x.notes.forEach(function(c) {
lines.push(prefix + ' ' + c)
})
}
if (x.methods) {
lines.push(prefix + ' methods');
Object.keys(x.methods).forEach(function(name) {
format(prefix + ' ', name, x.methods[name], lines)
})
} else
lines.push('\n')
return lines
}
process.exit(0)