UNPKG

docpad

Version:

DocPad is a dynamic static site generator. Write your content as files, or import your content from other external sources. Render the content with plugins. And deploy your static or dynamic website to your favourite hosting provider.

161 lines (151 loc) 5.5 kB
// Generated by CoffeeScript 2.5.1 var indexOf = [].indexOf; module.exports = function() { var DocPad, Errlop, cli, docpad, docpadUtil, extendr, instanceConfig, locale, result; // --------------------------------- // Are we the desired DocPad installation? // Prepare docpadUtil = require('./util'); // Continue if we explcitly want to use the global installation if (indexOf.call(process.argv, '--global') >= 0) { // remove them to workaround https://github.com/cacjs/cac/issues/25 process.argv = process.argv.filter(function(arg) { return arg !== '--global'; }); // continue // Continue if we are already the local installation } else if (docpadUtil.isLocalDocPadExecutable()) { // continue // Continue if the local installation doesn't exist } else if (docpadUtil.getLocalDocPadExecutableExistance() === false) { } else { // return // continue // Otherwise forward to the local installation return docpadUtil.startLocalDocPadExecutable(); } // --------------------------------- // We are the desired DocPad installation // Prepare extendr = require('extendr'); cli = require('cac')(); locale = require('./locale/en'); DocPad = require('./docpad'); Errlop = require('errlop').default; docpad = null; instanceConfig = {}; // Global options cli.option('--outpath <outPath>', locale.consoleOptionOutPath, { type: 'string' }).option('--config <configPaths>', locale.consoleOptionConfig, { type: 'string' }).option('--env <environment>', locale.consoleOptionEnv, { type: 'string' }).option('--log <logLevel>', locale.consoleOptionLogLevel, { type: 'string' }).option('--verbose, -v', locale.consoleOptionVerbose, { type: 'boolean' }).option('--debug, -d', locale.consoleOptionDebug, { type: 'boolean' }).option('--global', locale.consoleOptionGlobal, { type: 'boolean' }).option('--color, --colour', locale.consoleOptionColor, { default: true, type: 'boolean' }).option('--silent', locale.consoleOptionSilent, { type: 'boolean' }).option('--progress', locale.consoleOptionProgress, { default: true, type: 'boolean' }); // Commands cli.command('run', locale.consoleDescriptionRun).action(function() { return docpad != null ? docpad.action('run') : void 0; }); cli.command('init', locale.consoleDescriptionInit).action(function() { return docpad != null ? docpad.action('init') : void 0; }); cli.command('generate', locale.consoleDescriptionGenerate).action(function() { return docpad != null ? docpad.action('generate') : void 0; }); cli.command('render [input]', locale.consoleDescriptionRender).action(function(input, options) { var ref; instanceConfig.silent = true; return docpad != null ? docpad.action('render', { filename: input, renderSingleExtensions: 'auto', output: (ref = options != null ? options.output : void 0) != null ? ref : true, stdin: options != null ? options.stdin : void 0 }) : void 0; }).option('--output <output>', locale.consoleOptionOutput, { type: 'string' }).option('--stdin', locale.consoleOptionStdin, { type: 'boolean' }).example('docpad render <filename>').example('docpad render <filepath>').example("echo '*example*' | docpad render"); cli.command('watch', locale.consoleDescriptionWatch).action(function() { return docpad != null ? docpad.action('generate watch') : void 0; }); cli.command('clean', locale.consoleDescriptionClean).action(function() { return docpad != null ? docpad.action('clean') : void 0; }); cli.command('update', locale.consoleDescriptionUpdate).action(function() { return docpad != null ? docpad.action('clean update') : void 0; }); cli.command('upgrade', locale.consoleDescriptionUpdate).action(function() { return docpad != null ? docpad.action('upgrade') : void 0; }); cli.command('install', locale.consoleDescriptionInstall).action(function() { return docpad != null ? docpad.action('install', { plugin: input[0] }) : void 0; }).example('install <plugin>'); cli.command('uninstall', locale.consoleDescriptionUninstall).action(function() { return docpad != null ? docpad.action('uninstall', { plugin: input[0] }) : void 0; }).example('uninstall <plugin>'); cli.command('info', locale.consoleDescriptionInfo).action(function() { instanceConfig.silent = true; return docpad != null ? docpad.action('info') : void 0; }); // Help cli.help(); // Unknown cli.on('command:*', function() { return cli.showHelp(); }); // --------------------------------- // DocPad // Fetch options result = cli.parse(); // Exit if we are help if (result.options.help) { return; } // Otherwise, apply the configuration options to the instanceConfig Object.keys(DocPad.prototype.initialConfig).forEach(function(name) { var value; value = result.options[name]; if (value != null) { return instanceConfig[name] != null ? instanceConfig[name] : instanceConfig[name] = value; } }); // Create return docpad = new DocPad(instanceConfig, function(err) { if (err) { console.error(err); return docpad.fatal(err); } // CLI return docpad.emitSerial('consoleSetup', { cac: cli }, function(err) { if (err) { console.error(err); return docpad.fatal(err); } // Run the command return cli.parse(); }); }); };