1 | 'use strict';
|
2 |
|
3 |
|
4 | var path = require('path');
|
5 |
|
6 |
|
7 | try {
|
8 |
|
9 |
|
10 | require('coffeescript/register');
|
11 | } catch (e) {
|
12 |
|
13 |
|
14 | if (require.extensions) {
|
15 | var FILE_EXTENSIONS = ['.coffee', '.litcoffee', '.coffee.md'];
|
16 | for (var i = 0; i < FILE_EXTENSIONS.length; i++) {
|
17 | require.extensions[FILE_EXTENSIONS[i]] = function() {
|
18 | throw new Error(
|
19 | 'Grunt attempted to load a .coffee file but CoffeeScript was not installed.\n' +
|
20 | 'Please run `npm install --dev coffeescript` to enable loading CoffeeScript.'
|
21 | );
|
22 | };
|
23 | }
|
24 | }
|
25 | }
|
26 |
|
27 |
|
28 | var grunt = module.exports = {};
|
29 |
|
30 |
|
31 | function gRequire(name) {
|
32 | return grunt[name] = require('./grunt/' + name);
|
33 | }
|
34 |
|
35 | var util = require('grunt-legacy-util');
|
36 | grunt.util = util;
|
37 | grunt.util.task = require('./util/task');
|
38 |
|
39 | var Log = require('grunt-legacy-log').Log;
|
40 | var log = new Log({grunt: grunt});
|
41 | grunt.log = log;
|
42 |
|
43 | gRequire('template');
|
44 | gRequire('event');
|
45 | var fail = gRequire('fail');
|
46 | gRequire('file');
|
47 | var option = gRequire('option');
|
48 | var config = gRequire('config');
|
49 | var task = gRequire('task');
|
50 | var help = gRequire('help');
|
51 | gRequire('cli');
|
52 | var verbose = grunt.verbose = log.verbose;
|
53 |
|
54 |
|
55 | grunt.package = require('../package.json');
|
56 | grunt.version = grunt.package.version;
|
57 |
|
58 |
|
59 | function gExpose(obj, methodName, newMethodName) {
|
60 | grunt[newMethodName || methodName] = obj[methodName].bind(obj);
|
61 | }
|
62 | gExpose(task, 'registerTask');
|
63 | gExpose(task, 'registerMultiTask');
|
64 | gExpose(task, 'registerInitTask');
|
65 | gExpose(task, 'renameTask');
|
66 | gExpose(task, 'loadTasks');
|
67 | gExpose(task, 'loadNpmTasks');
|
68 | gExpose(config, 'init', 'initConfig');
|
69 | gExpose(fail, 'warn');
|
70 | gExpose(fail, 'fatal');
|
71 |
|
72 |
|
73 |
|
74 | grunt.tasks = function(tasks, options, done) {
|
75 |
|
76 | option.init(options);
|
77 |
|
78 |
|
79 | var _tasks, _options;
|
80 | if (option('version')) {
|
81 |
|
82 | log.writeln('grunt v' + grunt.version);
|
83 |
|
84 | if (option('verbose')) {
|
85 |
|
86 | verbose.writeln('Install path: ' + path.resolve(__dirname, '..'));
|
87 |
|
88 |
|
89 | grunt.log.muted = true;
|
90 |
|
91 | grunt.task.init([], {help: true});
|
92 |
|
93 | grunt.log.muted = false;
|
94 |
|
95 |
|
96 | _tasks = Object.keys(grunt.task._tasks).sort();
|
97 | verbose.writeln('Available tasks: ' + _tasks.join(' '));
|
98 |
|
99 |
|
100 | _options = [];
|
101 | Object.keys(grunt.cli.optlist).forEach(function(long) {
|
102 | var o = grunt.cli.optlist[long];
|
103 | _options.push('--' + (o.negate ? 'no-' : '') + long);
|
104 | if (o.short) { _options.push('-' + o.short); }
|
105 | });
|
106 | verbose.writeln('Available options: ' + _options.join(' '));
|
107 | }
|
108 |
|
109 | return;
|
110 | }
|
111 |
|
112 |
|
113 | log.initColors();
|
114 |
|
115 |
|
116 | if (option('help')) {
|
117 | help.display();
|
118 | return;
|
119 | }
|
120 |
|
121 |
|
122 | verbose.header('Initializing').writeflags(option.flags(), 'Command-line options');
|
123 |
|
124 |
|
125 | var tasksSpecified = tasks && tasks.length > 0;
|
126 | tasks = task.parseArgs([tasksSpecified ? tasks : 'default']);
|
127 |
|
128 |
|
129 | task.init(tasks, options);
|
130 |
|
131 | verbose.writeln();
|
132 | if (!tasksSpecified) {
|
133 | verbose.writeln('No tasks specified, running default tasks.');
|
134 | }
|
135 | verbose.writeflags(tasks, 'Running tasks');
|
136 |
|
137 |
|
138 | var uncaughtHandler = function(e) {
|
139 | fail.fatal(e, fail.code.TASK_FAILURE);
|
140 | };
|
141 | process.on('uncaughtException', uncaughtHandler);
|
142 |
|
143 |
|
144 | task.options({
|
145 | error: function(e) {
|
146 | fail.warn(e, fail.code.TASK_FAILURE);
|
147 | },
|
148 | done: function() {
|
149 |
|
150 |
|
151 |
|
152 |
|
153 | process.removeListener('uncaughtException', uncaughtHandler);
|
154 |
|
155 |
|
156 | fail.report();
|
157 |
|
158 | if (done) {
|
159 |
|
160 | done();
|
161 | } else {
|
162 |
|
163 | util.exit(0);
|
164 | }
|
165 | }
|
166 | });
|
167 |
|
168 |
|
169 |
|
170 | tasks.forEach(function(name) { task.run(name); });
|
171 |
|
172 |
|
173 | task.start({asyncDone: true});
|
174 | };
|