Generate docs from javascript source via AST parsing
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

45 lines
1.6 KiB

#!/usr/bin/env node
var docast = require('docast');
var docopt = require('docopt');
var fs = require('fs');
var path = require('path');
var doc = [
'Usage:',
' docast (-h | --help)',
' docast (-v | --version)',
' docast extract [-o <output>] <input_files>...',
' docast generate [-f <formatter>] [-b <output>] <input_files>...',
'',
'Options:',
' -h --help Show this help text',
' -v --version Show docast version information',
'Extract:',
' Parse docs from javascript files and output as json to a file',
' -o --output <output> File to output to [default: out.json]',
' <input_files> List of javascript files to fetch docs from',
'Generate:',
' Provide a script used to generate documentation from the parsed docs',
' -b --build <output> Folderto output to [default: build]',
' -f --formatter <formatter> Script to import as formatter, default uses internal',
' <input_files> List of javascript files to fetch docs from',
].join('\r\n');
var args = docopt.docopt(doc, {version: require('../package.json').version});
var comments = {};
args['<input_files>'].forEach(function(file){
comments[file] = docast.parse(file);
});
if(args.extract){
fs.writeFileSync(args['--output'], JSON.stringify(comments));
} else if(args.generate){
var options = {build: args['--build']};
var formatter = new docast.formatter(options);
if(args['--formatter']){
var loc = path.join(process.cwd(), args['--formatter']);
formatter = new (require(loc))(options);
}
formatter.format(comments);
}