1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- (function() {
- var chalk, extendOptions, globalOptions, logger, main, parseArgv, path, usage,
- indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
- chalk = require('chalk');
- parseArgv = require('minimist');
- path = require('path');
- logger = require('./../core/logger').logger;
- extendOptions = require('./common').extendOptions;
- usage = "\nusage: wintersmith [options] [command]\n\ncommands:\n\n " + (chalk.bold('build')) + " [options] - build a site\n " + (chalk.bold('preview')) + " [options] - run local webserver\n " + (chalk.bold('new')) + " <location> - create a new site\n " + (chalk.bold('plugin')) + " - manage plugins\n\n also see [command] --help\n\nglobal options:\n\n -v, --verbose show debug information\n -q, --quiet only output critical errors\n -V, --version output version and exit\n -h, --help show help\n";
- globalOptions = {
- boolean: ['verbose', 'quiet', 'version', 'help'],
- alias: {
- verbose: 'v',
- quiet: 'q',
- version: 'V',
- help: 'h'
- }
- };
- main = function(argv) {
- var cmd, error, opts;
- opts = parseArgv(argv, globalOptions);
- cmd = opts._[2];
- if (cmd != null) {
- try {
- cmd = require("./" + cmd);
- } catch (error1) {
- error = error1;
- if (error.code === 'MODULE_NOT_FOUND') {
- console.log("'" + cmd + "' - no such command");
- process.exit(1);
- } else {
- throw error;
- }
- }
- }
- if (opts.version) {
- console.log(require('./version'));
- process.exit(0);
- }
- if (opts.help || !cmd) {
- console.log(cmd ? cmd.usage : usage);
- process.exit(0);
- }
- if (opts.verbose) {
- if (indexOf.call(argv, '-vv') >= 0) {
- logger.transports[0].level = 'silly';
- } else {
- logger.transports[0].level = 'verbose';
- }
- }
- if (opts.quiet) {
- logger.transports[0].quiet = true;
- }
- if (cmd) {
- extendOptions(cmd.options, globalOptions);
- opts = parseArgv(argv, cmd.options);
- return cmd(opts);
- }
- };
- module.exports.main = main;
- }).call(this);
|