1 | #!/usr/bin/env node
|
2 |
|
3 | var updateNotifier = require('update-notifier');
|
4 | var notifier = updateNotifier();
|
5 | if (notifier.update) {
|
6 | notifier.notify();
|
7 | }
|
8 |
|
9 | var path = require('path');
|
10 | var verify = require('check-types').verify;
|
11 | var xplain = require('./src/xplain');
|
12 | var package = require('./package.json');
|
13 |
|
14 | var info = 'xplain - JavaScript API documentation generator\n' +
|
15 | ' version: ' + package.version + '\n' +
|
16 | ' author: ' + JSON.stringify(package.author);
|
17 |
|
18 | var program = require('optimist')
|
19 | .usage(info)
|
20 | .options('input', {
|
21 | alias: 'i',
|
22 | string: true,
|
23 | description: 'input file(s), you can use wildcards'
|
24 | })
|
25 | .options('output', {
|
26 | alias: 'o',
|
27 | string: true,
|
28 | description: 'output folder name / Markdown filename',
|
29 | default: 'docs'
|
30 | })
|
31 | .options('title', {
|
32 | alias: 't',
|
33 | string: true,
|
34 | description: 'API title to use',
|
35 | default: ''
|
36 | })
|
37 | .options('version', {
|
38 | alias: 'v',
|
39 | string: true,
|
40 | description: 'API version to add to title',
|
41 | default: ''
|
42 | })
|
43 | .options('framework', {
|
44 | alias: 'f',
|
45 | string: true,
|
46 | description: 'unit testing framework name',
|
47 | default: 'qunit',
|
48 | check: xplain.isSupported
|
49 | })
|
50 | .options('header', {
|
51 | alias: 'e',
|
52 | string: true,
|
53 | description: 'optional Markdown doc to use as header',
|
54 | default: '',
|
55 | check: function (value) {
|
56 | return (/\.md$/).test(value);
|
57 | }
|
58 | })
|
59 | .demand(['input'])
|
60 | .argv;
|
61 |
|
62 | if (!xplain.isSupported(program.framework)) {
|
63 | console.error('Invalid framework ' + program.framework);
|
64 | console.error('Available', xplain.supportedFrameworks());
|
65 | process.exit(-1);
|
66 | }
|
67 |
|
68 | var inputFiles = program.input;
|
69 | if (typeof inputFiles === 'string') {
|
70 | inputFiles = [inputFiles];
|
71 | }
|
72 | verify.array(inputFiles, 'missing input pattern array ' + inputFiles);
|
73 | verify.string(program.output, 'missing output folder ' + JSON.stringify(program, null, 2));
|
74 | var fullFolder = path.resolve(process.cwd(), program.output);
|
75 | console.log('generating docs from', inputFiles, 'target', fullFolder);
|
76 |
|
77 | if (program.version) {
|
78 | program.version = '' + program.version;
|
79 | if (program.version) {
|
80 | verify.string(program.version, 'invalid API version ' + program.version);
|
81 | }
|
82 | }
|
83 | if (program.title) {
|
84 | program.title = '' + program.title;
|
85 | if (program.title) {
|
86 | verify.string(program.title, 'invalid API title ' + program.title);
|
87 | }
|
88 | }
|
89 | if (program.title) {
|
90 | console.log('title', program.title);
|
91 | }
|
92 | if (program.version) {
|
93 | console.log('version', program.version);
|
94 | }
|
95 | if (program.header) {
|
96 | console.log('header', program.header);
|
97 | }
|
98 |
|
99 | verify.fn(xplain.document, 'xplain have document function');
|
100 | xplain.document({
|
101 | patterns: inputFiles,
|
102 | outputFolder: fullFolder,
|
103 | title: program.title,
|
104 | apiVersion: program.version,
|
105 | framework: program.framework,
|
106 | header: program.header
|
107 | }); |
\ | No newline at end of file |