Tizen 2.0 Release
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.2.0 / node_modules / grunt / lib / grunt.js
1 /*
2  * grunt
3  * http://gruntjs.com/
4  *
5  * Copyright (c) 2012 "Cowboy" Ben Alman
6  * Licensed under the MIT license.
7  * https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
8  */
9
10 // Nodejs libs.
11 var path = require('path');
12
13 // The module to be exported.
14 var grunt = module.exports = {};
15
16 // Expose internal grunt libs.
17 function gRequire(name) {
18   return grunt[name] = require('./grunt/' + name);
19 }
20 var utils = gRequire('utils');
21 var template = gRequire('template');
22 var fail = gRequire('fail');
23 var file = gRequire('file');
24 var option = gRequire('option');
25 var config = gRequire('config');
26 var task = gRequire('task');
27 var log = gRequire('log');
28 var cli = gRequire('cli');
29 var verbose = grunt.verbose = log.verbose;
30
31 grunt.version = file.readJSON(path.join(__dirname, '../package.json')).version;
32
33 // Expose specific grunt lib methods on grunt.
34 function gExpose(obj, methodName, newMethodName) {
35   grunt[newMethodName || methodName] = obj[methodName].bind(obj);
36 }
37 gExpose(task, 'registerTask');
38 gExpose(task, 'registerMultiTask');
39 gExpose(task, 'registerInitTask');
40 gExpose(task, 'renameTask');
41 gExpose(task, 'registerHelper');
42 gExpose(task, 'renameHelper');
43 gExpose(task, 'helper');
44 gExpose(task, 'loadTasks');
45 gExpose(task, 'registerTask');
46 gExpose(task, 'loadNpmTasks');
47 gExpose(config, 'init', 'initConfig');
48 gExpose(fail, 'warn');
49 gExpose(fail, 'fatal');
50
51 // Handle exceptions.
52 // process.on('uncaughtException', function (e) {
53 //   fail.warn(e, 3);
54 // });
55
56 // Disable colors if --no-colors was passed.
57 function initColors() {
58   var methods = Object.keys(String.prototype);
59   // Requiring this here will modify String prototype everywhere.
60   require('colors');
61
62   // Disable colors.
63   if (option('no-color')) {
64     // Override "colors".
65     Object.keys(String.prototype).filter(function(method) {
66       // Filter out methods that existed before "colors" was required.
67       return methods.indexOf(method) === -1;
68     }).forEach(function(method) {
69       // Replace each new method with a function that just returns `this`.
70       String.prototype.__defineGetter__(method, function() { return this; });
71     });
72
73     // Override console.log (nodeunit, maybe others).
74     console._log = console.log;
75     console.log = function() {
76       var args = utils.toArray(arguments).map(function(value) {
77         if (typeof value === 'string') {
78           return value.replace(/\033\[[\d;]+m/g, '');
79         }
80         return value;
81       });
82       console._log.apply(console, args);
83     };
84   }
85 }
86
87 // Expose the task interface. I've never called this manually, and have no idea
88 // how it will work. But it might.
89 grunt.tasks = function(tasks, options, done) {
90   // Update options with passed-in options.
91   option.init(options);
92
93   // Init colors.
94   initColors();
95
96   if (option('help')) {
97     // Load and display help if the user did --help.
98     require('./grunt/help');
99   } else if (option('version')) {
100     // Display the current grunt version if the user did --version.
101     log.writeln('grunt v' + grunt.version);
102     return;
103   }
104
105   // A little header stuff.
106   verbose.header('Initializing').writeflags(option.flags(), 'Command-line options');
107
108   // Determine and output which tasks will be run.
109   var tasksSpecified = tasks && tasks.length > 0;
110   tasks = task.parseArgs([tasksSpecified ? tasks : 'default']);
111
112   // Initialize tasks.
113   task.init(tasks);
114
115   verbose.writeln();
116   if (!tasksSpecified) {
117     verbose.writeln('No tasks specified, running default tasks.');
118   }
119   verbose.writeflags(tasks, 'Running tasks');
120
121   // Report, etc when all tasks have completed.
122   task.options({
123     error: function(e) {
124       fail.warn(e, 3);
125     },
126     done: function() {
127       // Output a final fail / success report.
128       fail.report();
129
130       if (done) {
131         // Execute "done" function when done (only if passed, of course).
132         done();
133       } else {
134         // Otherwise, explicitly exit.
135         process.exit(0);
136       }
137     }
138   });
139
140   // Execute all tasks, in order. Passing each task individually in a forEach
141   // allows the error callback to execute multiple times.
142   tasks.forEach(function(name) { task.run(name); });
143   task.start();
144 };
145
146 // Register one or more Npm-installed grunt plugins inside that plugin's bin.
147 grunt._npmTasks = [];
148 grunt.npmTasks = function(tasks) {
149   grunt._npmTasks = Array.isArray(tasks) ? tasks : [tasks];
150   return grunt;
151 };