#!/usr/bin/env node 'use strict'; const fs = require('fs'); const chalk = require('chalk'); const updateNotifier = require('update-notifier'); const doxdox = require('../lib/doxdox'); const findPackageFileInPath = require('../lib/utils').findPackageFileInPath; const pkg = require('../package'); const args = require('parse-cmd-args')(null, { 'allowMultipleInputs': true, 'requireUserInput': true }); updateNotifier({ 'defer': true, pkg }).notify(); if (args.flags['--version'] || args.flags['-v']) { process.stdout.write(`${pkg.version}\n`); process.exit(); } else if (!args.inputs.length || args.flags['--help'] || args.flags['-h']) { process.stdout.write(` ${chalk.blue(' Usage:')} doxdox ... [options] Options: ${chalk.yellow(' -h, --help')} Display this help message. ${chalk.yellow(' -v, --version')} Display the current installed version. ${chalk.yellow(' -d, --description')} Sets description. ${chalk.yellow(' -i, --ignore')} Comma separated list of paths to ignore. ${chalk.yellow(' -l, --layout')} Template to render the documentation with. ${chalk.yellow(' -o, --output')} File to save documentation to. Defaults to stdout. ${chalk.yellow(' -p, --package')} Sets location of package.json file. ${chalk.yellow(' -t, --title')} Sets title. Included Layouts: - Markdown (default) (http://daringfireball.net/projects/markdown/) - Bootstrap (http://getbootstrap.com/) - Handlebars (http://handlebarsjs.com/) `); process.exit(); } else { const projectPkgPath = findPackageFileInPath(args.flags['--package'] || args.flags['-p']); let projectPkg = {}; try { const projectPkgStats = fs.statSync(projectPkgPath); if (projectPkgStats.isFile()) { projectPkg = require(projectPkgPath); } } catch (err) { process.stderr.write(`${err.toString()}\n`); } const config = { 'description': args.flags['--description'] || args.flags['-d'] || projectPkg.description || '', 'ignore': (args.flags['--ignore'] || args.flags['-i'] || '').split(/\s*,\s*/), 'layout': (args.flags['--layout'] || args.flags['-l'] || 'markdown').toLowerCase(), 'parser': (args.flags['--parser'] || args.flags['-r'] || 'dox').toLowerCase(), 'title': args.flags['--title'] || args.flags['-t'] || projectPkg.name || 'Untitled Project' }; const output = args.flags['--output'] || args.flags['-o'] || null; doxdox.parseInputs(args.inputs, Object.assign({ 'pkg': projectPkg }, config)) .then(content => { if (output) { fs.writeFileSync(output, content, 'utf8'); } else { process.stdout.write(content); } }) .catch(err => { process.stderr.write(`${err.toString()}\n`); }); }