~stephen-stewart/+junk/add-grunt

« back to all changes in this revision

Viewing changes to node_modules/grunt/lib/grunt/cli.js

  • Committer: Stephen Stewart
  • Date: 2014-05-13 01:26:55 UTC
  • Revision ID: stephen.stewart@canonical.com-20140513012655-wx8xbwcdohofxoyj
add --production node_modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * grunt
 
3
 * http://gruntjs.com/
 
4
 *
 
5
 * Copyright (c) 2014 "Cowboy" Ben Alman
 
6
 * Licensed under the MIT license.
 
7
 * https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
 
8
 */
 
9
 
 
10
'use strict';
 
11
 
 
12
var grunt = require('../grunt');
 
13
 
 
14
// Nodejs libs.
 
15
var path = require('path');
 
16
 
 
17
// External libs.
 
18
var nopt = require('nopt');
 
19
 
 
20
// This is only executed when run via command line.
 
21
var cli = module.exports = function(options, done) {
 
22
  // CLI-parsed options override any passed-in "default" options.
 
23
  if (options) {
 
24
    // For each default option...
 
25
    Object.keys(options).forEach(function(key) {
 
26
      if (!(key in cli.options)) {
 
27
        // If this option doesn't exist in the parsed cli.options, add it in.
 
28
        cli.options[key] = options[key];
 
29
      } else if (cli.optlist[key].type === Array) {
 
30
        // If this option's type is Array, append it to any existing array
 
31
        // (or create a new array).
 
32
        [].push.apply(cli.options[key], options[key]);
 
33
      }
 
34
    });
 
35
  }
 
36
 
 
37
  // Run tasks.
 
38
  grunt.tasks(cli.tasks, cli.options, done);
 
39
};
 
40
 
 
41
// Default options.
 
42
var optlist = cli.optlist = {
 
43
  help: {
 
44
    short: 'h',
 
45
    info: 'Display this help text.',
 
46
    type: Boolean
 
47
  },
 
48
  base: {
 
49
    info: 'Specify an alternate base path. By default, all file paths are relative to the Gruntfile. (grunt.file.setBase) *',
 
50
    type: path
 
51
  },
 
52
  color: {
 
53
    info: 'Disable colored output.',
 
54
    type: Boolean,
 
55
    negate: true
 
56
  },
 
57
  gruntfile: {
 
58
    info: 'Specify an alternate Gruntfile. By default, grunt looks in the current or parent directories for the nearest Gruntfile.js or Gruntfile.coffee file.',
 
59
    type: path
 
60
  },
 
61
  debug: {
 
62
    short: 'd',
 
63
    info: 'Enable debugging mode for tasks that support it.',
 
64
    type: [Number, Boolean]
 
65
  },
 
66
  stack: {
 
67
    info: 'Print a stack trace when exiting with a warning or fatal error.',
 
68
    type: Boolean
 
69
  },
 
70
  force: {
 
71
    short: 'f',
 
72
    info: 'A way to force your way past warnings. Want a suggestion? Don\'t use this option, fix your code.',
 
73
    type: Boolean
 
74
  },
 
75
  tasks: {
 
76
    info: 'Additional directory paths to scan for task and "extra" files. (grunt.loadTasks) *',
 
77
    type: Array
 
78
  },
 
79
  npm: {
 
80
    info: 'Npm-installed grunt plugins to scan for task and "extra" files. (grunt.loadNpmTasks) *',
 
81
    type: Array
 
82
  },
 
83
  write: {
 
84
    info: 'Disable writing files (dry run).',
 
85
    type: Boolean,
 
86
    negate: true
 
87
  },
 
88
  verbose: {
 
89
    short: 'v',
 
90
    info: 'Verbose mode. A lot more information output.',
 
91
    type: Boolean
 
92
  },
 
93
  version: {
 
94
    short: 'V',
 
95
    info: 'Print the grunt version. Combine with --verbose for more info.',
 
96
    type: Boolean
 
97
  },
 
98
  // Even though shell auto-completion is now handled by grunt-cli, leave this
 
99
  // option here for display in the --help screen.
 
100
  completion: {
 
101
    info: 'Output shell auto-completion rules. See the grunt-cli documentation for more information.',
 
102
    type: String
 
103
  },
 
104
};
 
105
 
 
106
// Parse `optlist` into a form that nopt can handle.
 
107
var aliases = {};
 
108
var known = {};
 
109
 
 
110
Object.keys(optlist).forEach(function(key) {
 
111
  var short = optlist[key].short;
 
112
  if (short) {
 
113
    aliases[short] = '--' + key;
 
114
  }
 
115
  known[key] = optlist[key].type;
 
116
});
 
117
 
 
118
var parsed = nopt(known, aliases, process.argv, 2);
 
119
cli.tasks = parsed.argv.remain;
 
120
cli.options = parsed;
 
121
delete parsed.argv;
 
122
 
 
123
// Initialize any Array options that weren't initialized.
 
124
Object.keys(optlist).forEach(function(key) {
 
125
  if (optlist[key].type === Array && !(key in cli.options)) {
 
126
    cli.options[key] = [];
 
127
  }
 
128
});