mirror of
https://github.com/documentationjs/documentation.git
synced 2026-01-18 14:17:30 +00:00
42 lines
1.1 KiB
JavaScript
Executable File
42 lines
1.1 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
/* eslint no-console: 0 */
|
|
|
|
'use strict';
|
|
|
|
var documentation = require('../'),
|
|
streamArray = require('stream-array'),
|
|
fs = require('fs'),
|
|
vfs = require('vinyl-fs'),
|
|
formatError = require('../lib/format_error'),
|
|
args = require('../lib/args.js');
|
|
|
|
var parsedArgs = args(process.argv.slice(2)),
|
|
formatterOptions = parsedArgs.formatterOptions,
|
|
outputLocation = parsedArgs.output,
|
|
formatter = documentation.formats[parsedArgs.formatter];
|
|
|
|
documentation(parsedArgs.inputs, parsedArgs.options, function (err, result) {
|
|
if (err) {
|
|
throw err;
|
|
}
|
|
|
|
result.forEach(function (comment) {
|
|
comment.errors.forEach(function (error) {
|
|
console.error(formatError(comment, error));
|
|
});
|
|
});
|
|
|
|
formatter(result, formatterOptions, function (err, output) {
|
|
if (outputLocation !== 'stdout') {
|
|
if (parsedArgs.formatter === 'html') {
|
|
streamArray(output).pipe(vfs.dest(outputLocation));
|
|
} else {
|
|
fs.writeFileSync(outputLocation, output);
|
|
}
|
|
} else {
|
|
process.stdout.write(output);
|
|
}
|
|
});
|
|
});
|