Debian Codegraph @

bin/grunt

raw ◀ ▶
1 Debian patch touch this file
1 #!/usr/bin/env node
2
3 'use strict';
4
5 process.title = 'grunt';
6
7 var Liftup = require('liftup');
8 var v8flags = require('v8flags');
9 var extensions = require('interpret').jsVariants;
10 var nopt = require('nopt');
11 var gruntOptions = require('grunt-known-options');
12 var completion = require('../lib/completion.js');
13 var info = require('../lib/info.js');
14 var pkg = require('../package.json');
15
16 // Parse `gruntOptions` into a form that nopt can handle.
17 var aliases = {};
18 var known = {};
19
20 Object.keys(gruntOptions).forEach(function(key) {
21 var short = gruntOptions[key].short;
22 if (short) {
23 aliases[short] = '--' + key;
24 }
25 known[key] = gruntOptions[key].type;
26 });
27
28 // Parse them and return an options object.
29 var options = nopt(known, aliases, process.argv, 2);
30
31 if ('completion' in options) {
32 completion.print(options.completion);
33 } else if (options.version) {
34 console.log('grunt-cli v' + pkg.version);
35 }
36
37 v8flags(function (err, v8flags) {
38 var Grunt = new Liftup({
39 name: 'grunt',
40 configName: 'Gruntfile',
41 // Support a number of languages based on file extension
42 extensions: extensions,
43 // Flags that are v8 flags will be loaded into node instead of Gruntfile
44 v8flags: v8flags
45 });
46 Grunt.prepare({
47 cwd: options.base,
48 configPath: options.gruntfile,
49 require: options.require,
50 preload: options.preload,
51 verbose: options.verbose
52 }, function (env) {
53 Grunt.execute(env, function(env) {
54 var tasks = options.argv.remain;
55 delete options.argv;
•56 // look for global grunt install
57 if (!env.modulePath)
58 try {
59 env.modulePath = require.resolve('grunt');
60 } catch (ex) { }
61 // No grunt install found!
62 if (!env.modulePath) {
63 if (options.version) {
64 process.exit();
65 }
66 if (options.help) {
67 info.help();
68 }
69 info.fatal('Unable to find local grunt.', 99);
70 } else {
71 options.gruntfile = env.configPath;
72 var grunt = require(env.modulePath);
73 grunt.tasks(tasks, options);
74 }
75 });
76 });
77 });