-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgruntfile.js
101 lines (88 loc) · 2.72 KB
/
gruntfile.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
module.exports = function(grunt) {
"use strict";
// Adding the folder node_modules under the process folder to the require paths
var path = process.cwd()+"/node_modules";
if (module.paths.indexOf(path) === -1) {
module.paths.push(path);
}
require("time-grunt")(grunt); // Display the elapsed execution time of grunt tasks
// Project configuration.
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var config = {};
if (grunt.file.exists("grunt-config.json")) {
config = grunt.file.readJSON("grunt-config.json");
}
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
config: config
});
// Custom Subroutines
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
* Adding the possibility to suppress the log headers
* via grunt config
*/
grunt.log.header = (function(log) {
return function (message) {
var printHeader = grunt.config.get("log.printHeader");
if (printHeader !== false) {
log(message);
} else {
// console.log("suppressing header: " + message);
}
};
})(grunt.log.header);
/**
*
* @param taskName
* @param moduleName
* @returns {*}
*/
grunt.task.customLoadNpmTasks = function(taskName, moduleName) {
moduleName = moduleName || taskName;
if (! grunt.file.exists("node_modules/"+moduleName)) {
return grunt.fail.fatal("The npm module " + taskName + " is not installed");
}
grunt.task.loadNpmTasks(taskName);
};
/**
*
*/
grunt.task.customRun = function() {
var args = Array.prototype.slice.call(arguments),
taskName = this.name,
defaultTarget = this.defaultTarget,
targetMandatory = this.targetMandatory,
target = args[0],
originalPrintHeader = grunt.config.get("log.printHeader");
if (! taskName) {
return grunt.fail.fatal("Missing taskName");
}
/**
*
* @private
*/
function _resetLogHeader() {
grunt.config.set("log.printHeader", originalPrintHeader);
}
if (target) {
grunt.task.customLoadNpmTasks("grunt-then");
args = args.join(":");
// Suppressing the double header resulting in the task calling itself again
grunt.config.set("log.printHeader", false);
grunt.task.run(taskName+":"+args).then(_resetLogHeader);
} else {
if (defaultTarget) {
grunt.task.run(taskName + ":"+defaultTarget);
} else if (targetMandatory === true) {
grunt.fail.fatal("A target is mandatory for this task");
} else {
grunt.task.customLoadNpmTasks("grunt-then");
// Suppressing the double header resulting in the task calling itself again
grunt.config.set("log.printHeader", false);
grunt.task.run(taskName).then(_resetLogHeader);
}
}
};
grunt.loadTasks("grunt-tasks"); // Loading the project specific grunt tasks
};