forked from maxov/gulp-grunt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
73 lines (60 loc) · 1.94 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var grunt = require('grunt');
var spawn = require('child_process').spawn;
var makeOptions = function (options) {
var baseOptions = {
base: null,
prefix: 'grunt-',
verbose: false
};
if (options) {
for (var key in options) {
if (options.hasOwnProperty(key)) {
baseOptions[key] = options[key];
}
}
}
grunt.option('verbose', baseOptions.verbose);
return baseOptions;
};
module.exports = function (gulp, options) {
var tasks = getTasks(options);
for (var name in tasks) {
if (tasks.hasOwnProperty(name)) {
var fn = tasks[name];
gulp.task(name, fn);
}
}
};
var getTasks = module.exports.tasks = function (options) {
var opt = makeOptions(options);
if (opt.base) {
grunt.file.setBase(opt.base);
}
grunt.task.init([]);
var gruntTasks = grunt.task._tasks,
finalTasks = {};
for (var name in gruntTasks) {
if (gruntTasks.hasOwnProperty(name)) {
(function (name) {
finalTasks[opt.prefix + name] = function (cb) {
if (opt.verbose) {
console.log('[grunt-gulp] Running Grunt "' + name + '" task...');
}
var child = spawn(
'grunt',
[name, '--force', '--verbose=' + opt.verbose]
);
child.stdout.on('data', function(d) { grunt.log.write(d); });
child.stderr.on('data', function(d) { grunt.log.error(d); });
child.on('close', function(code) {
if (opt.verbose) {
grunt.log.ok('[grunt-gulp] Done running Grunt "' + name + '" task.');
}
cb();
});
};
})(name);
}
}
return finalTasks;
};