-
Notifications
You must be signed in to change notification settings - Fork 4
/
Gruntfile.js
74 lines (57 loc) · 1.79 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
if (typeof String.prototype.endsWith != 'function') {
String.prototype.endsWith = function (str) {
return this.slice(-str.length) == str;
};
}
if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function (str) {
return this.slice(0, str.length) == str;
};
}
module.exports = function (grunt) {
'use strict';
grunt.util.linefeed = '\r\n';
grunt.file.defaultEncoding = 'utf8';
var config = {
pkg: grunt.file.readJSON('package.json')
};
merge(config, require('./themes.js'));
merge(config, loadConfig('./tasks/options/', '.js'));
grunt.file.expand('./tasks/themes/*').forEach(function (dir) {
merge(config, loadConfig(dir + '/', '.js'));
});
merge(config, loadConfig('./custom/', '-grunt.js', '-grunt'));
//console.log(config);
grunt.initConfig(config);
require('load-grunt-tasks')(grunt);
grunt.loadTasks('./tasks/');
grunt.loadTasks('./tasks/themes/');
};
function loadConfig(path, extension, marker) {
var glob = require('glob'),
object = {},
key;
glob.sync('**/*' + extension, { cwd: path }).forEach(function (option) {
if (marker) {
key = option.replace(marker, '').split('.').slice(-2, -1);
} else {
key = option.split('.').slice(-2, -1);
}
if (key in object) {
object[key] = merge(object[key], require(path + option));
} else {
object[key] = require(path + option);
}
});
return object;
}
function merge(to, from) {
for (var n in from) {
if (typeof to[n] != 'object') {
to[n] = from[n];
} else if (typeof from[n] == 'object') {
to[n] = merge(to[n], from[n]);
}
}
return to;
};