All files cli.js

25% Statements 2/8
0% Branches 0/4
0% Functions 0/2
25% Lines 2/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60                                  1x           1x                                                                        
// Command Line Interface
// ----------------------
// The core part of the CLI is here. Mostly it provides a useful, simplifed
// interface around the component parts. Running it locally is as simple as
// `cli(opts)`, in fact this is how the binary works internally.
//
// Import our external dependancies.
import commander from "commander";
import fs from "fs-extra";
import path from "path";
 
// Import our internal dependancies
import defaults from "./defaults";
import document from "./document";
 
// Extract the docco version from `package.json`
// We're exporting this so it is available elsewhere.
export const version = JSON.parse(fs.readFileSync(path.join(__dirname, "../package.json"))).version;
 
// Finally, let's define the interface to run Docco from the command line.
// Parse options using [Commander](https://github.com/visionmedia/commander.js).
// Programatically using the CLI function is possible by simply importing it and
// then running `cli({...yourArguments})`
export const cli = function(args = process.argv, generate = document) {
	// First, log the logo/description.
	global.console.log(`
	       __
	  ____/ /___  ______________        ___  _____
	 / __  / __ \\/ ___/ ___/ __ \\______/ _ \\/ ___/
	/ /_/ / /_/ / /__/ /__/ /_/ /_____/  __(__  )
	\\__,_/\\____/\\___/\\___/\\____/      \\___/____/
 
   The Quick & Simple Literate Doccumentation Generator
	`);
	// Now we use Commander to both describe the options and then parse the arguments.
	commander.version(version)
		.usage("[options] files")
		.option("-L, --languages [file]", "use a custom languages.json", (...args) => JSON.parse(fs.readFileSync(...args)))
		.option("-l, --layout [name]", "choose a layout (parallel, linear or classic)", defaults.layout)
		.option("-o, --output [path]", "output to a given folder", defaults.output)
		.option("-c, --css [file]", "use a custom css file", defaults.css)
		.option("-t, --template [file]", "use a custom .jst template", defaults.template)
		.option("-e, --extension [ext]", "assume a file extension for all inputs", defaults.extension)
		.option("-m, --marked [file]", "use custom marked options", defaults.marked)
		.option("-d, --dryrun", "don't write any files, just process them", defaults.dryrun)
		.option("-T, --throw", "throw errors if code syntax highlighting fails", defaults.throw)
		.option("-v, --verbose", "shows all files as they are proccessed rather than a summary", defaults.verbose)
		.option("-z, --zip [file]", "use a compressed layout (a zip with a .jst + optional .css file)", defaults.zip)
		.parse(args).name = "docco";
	// If we have parse arguments then we were called with files.
	// Lets try to build the documentation.
	if (commander.args.length) {
		return generate(commander);
	}
	// If we weren't, then just log the help text (a description of the options above).
	return global.console.log(commander.helpInformation());
};
 
export default cli;