1 | #!/usr/bin/env node
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | const fs = require('fs');
|
6 | const chalk = require('chalk');
|
7 | const updateNotifier = require('update-notifier');
|
8 |
|
9 | const doxdox = require('../lib/doxdox');
|
10 |
|
11 | const findPackageFileInPath = require('../lib/utils').findPackageFileInPath;
|
12 |
|
13 | const pkg = require('../package');
|
14 |
|
15 | const args = require('parse-cmd-args')(null, {
|
16 | 'allowMultipleInputs': true,
|
17 | 'requireUserInput': true
|
18 | });
|
19 |
|
20 | updateNotifier({
|
21 | 'defer': true,
|
22 | pkg
|
23 | }).notify();
|
24 |
|
25 | if (args.flags['--version'] || args.flags['-v']) {
|
26 |
|
27 | process.stdout.write(`${pkg.version}\n`);
|
28 | process.exit();
|
29 |
|
30 | } else if (!args.inputs.length || args.flags['--help'] || args.flags['-h']) {
|
31 |
|
32 | process.stdout.write(`
|
33 | ${chalk.blue(' Usage:')} doxdox <path> ... [options]
|
34 |
|
35 | Options:
|
36 |
|
37 | ${chalk.yellow(' -h, --help')} Display this help message.
|
38 | ${chalk.yellow(' -v, --version')} Display the current installed version.
|
39 | ${chalk.yellow(' -d, --description')} Sets description.
|
40 | ${chalk.yellow(' -i, --ignore')} Comma separated list of paths to ignore.
|
41 | ${chalk.yellow(' -l, --layout')} Template to render the documentation with.
|
42 | ${chalk.yellow(' -o, --output')} File to save documentation to. Defaults to stdout.
|
43 | ${chalk.yellow(' -p, --package')} Sets location of package.json file.
|
44 | ${chalk.yellow(' -t, --title')} Sets title.
|
45 |
|
46 | Included Layouts:
|
47 |
|
48 | - Markdown (default) (http://daringfireball.net/projects/markdown/)
|
49 | - Bootstrap (http://getbootstrap.com/)
|
50 | - Handlebars (http://handlebarsjs.com/)
|
51 |
|
52 | `);
|
53 | process.exit();
|
54 |
|
55 | } else {
|
56 |
|
57 | const projectPkgPath = findPackageFileInPath(args.flags['--package'] || args.flags['-p']);
|
58 |
|
59 | let projectPkg = {};
|
60 |
|
61 | try {
|
62 |
|
63 | const projectPkgStats = fs.statSync(projectPkgPath);
|
64 |
|
65 | if (projectPkgStats.isFile()) {
|
66 |
|
67 | projectPkg = require(projectPkgPath);
|
68 |
|
69 | }
|
70 |
|
71 | } catch (err) {
|
72 |
|
73 | process.stderr.write(`${err.toString()}\n`);
|
74 |
|
75 | }
|
76 |
|
77 | const config = {
|
78 | 'description': args.flags['--description'] || args.flags['-d'] || projectPkg.description || '',
|
79 | 'ignore': (args.flags['--ignore'] || args.flags['-i'] || '').split(/\s*,\s*/),
|
80 | 'layout': (args.flags['--layout'] || args.flags['-l'] || 'markdown').toLowerCase(),
|
81 | 'parser': (args.flags['--parser'] || args.flags['-r'] || 'dox').toLowerCase(),
|
82 | 'title': args.flags['--title'] || args.flags['-t'] || projectPkg.name || 'Untitled Project'
|
83 | };
|
84 |
|
85 | const output = args.flags['--output'] || args.flags['-o'] || null;
|
86 |
|
87 | doxdox.parseInputs(args.inputs, Object.assign({
|
88 | 'pkg': projectPkg
|
89 | }, config))
|
90 | .then(content => {
|
91 |
|
92 | if (output) {
|
93 |
|
94 | fs.writeFileSync(output, content, 'utf8');
|
95 |
|
96 | } else {
|
97 |
|
98 | process.stdout.write(content);
|
99 |
|
100 | }
|
101 |
|
102 | })
|
103 | .catch(err => {
|
104 |
|
105 | process.stderr.write(`${err.toString()}\n`);
|
106 |
|
107 | });
|
108 |
|
109 | }
|