UNPKG

2.69 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3var updateNotifier = require('update-notifier');
4var notifier = updateNotifier();
5if (notifier.update) {
6 notifier.notify();
7}
8
9var path = require('path');
10var verify = require('check-types').verify;
11var xplain = require('./src/xplain');
12var package = require('./package.json');
13
14var info = 'xplain - JavaScript API documentation generator\n' +
15' version: ' + package.version + '\n' +
16' author: ' + JSON.stringify(package.author);
17
18var 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
62if (!xplain.isSupported(program.framework)) {
63 console.error('Invalid framework ' + program.framework);
64 console.error('Available', xplain.supportedFrameworks());
65 process.exit(-1);
66}
67
68var inputFiles = program.input;
69if (typeof inputFiles === 'string') {
70 inputFiles = [inputFiles];
71}
72verify.array(inputFiles, 'missing input pattern array ' + inputFiles);
73verify.string(program.output, 'missing output folder ' + JSON.stringify(program, null, 2));
74var fullFolder = path.resolve(process.cwd(), program.output);
75console.log('generating docs from', inputFiles, 'target', fullFolder);
76
77if (program.version) {
78 program.version = '' + program.version;
79 if (program.version) {
80 verify.string(program.version, 'invalid API version ' + program.version);
81 }
82}
83if (program.title) {
84 program.title = '' + program.title;
85 if (program.title) {
86 verify.string(program.title, 'invalid API title ' + program.title);
87 }
88}
89if (program.title) {
90 console.log('title', program.title);
91}
92if (program.version) {
93 console.log('version', program.version);
94}
95if (program.header) {
96 console.log('header', program.header);
97}
98
99verify.fn(xplain.document, 'xplain have document function');
100xplain.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