-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
71 lines (67 loc) · 1.74 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
71
const commander = require('commander');
const logger = require('utils/logger');
const process = require('process');
const Jsdoc = require('./index');
const path = require('path');
const fs = require('fs');
const dumper = require('utils/dumper');
const shelljs = require('shelljs');
function list(val) {
return val.split(',');
}
const plugins = [
'commentConvert',
'commentsOnly',
'escapeHtml',
'eventDumper',
'overloadHelper',
'partial',
'postman',
'railsTemplate',
'shout',
'sourcetag',
'summarize',
'underscore'
];
commander
.version('0.0.1')
.option('-p, --plugin <items>', `
default: [postman]
plugin supported:
${plugins.join('\n')}
`, (val) => {
const values = val.split(',');
const ret = [];
values.forEach((value) => {
if (plugins.indexOf(value) === -1) {
logger.error(`not support plugin: ${value}`);
} else {
ret.push(value);
}
});
return ret;
})
.option('-f, --files <items>', 'the files you want to parse', list)
.option('-o, --out [out]', 'out dir')
.parse(process.argv);
const outDir = commander.out || process.cwd();
const files = commander.files || ['.'];
const plugin = commander.plugin || [];
console.log(process.execPath)
new Jsdoc({
sourceFiles: files,
plugins: plugin.concat(['postman']),
converters: {
postman(collections) {
if (collections && collections.length) {
collections.forEach((collection) => {
const name = collection.info.name;
logger.info('write json file:', path.join(outDir, `${name}.json`));
fs.writeFileSync(path.join(outDir, `${name}.json`), dumper.dump(collection));
console.log(`./newman run ${name}.json`);
shelljs.exec(`${path.resolve(__dirname, '../.bin/newman')} run ${name}.json`);
});
}
}
}
}).runCommand();