-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
95 lines (74 loc) · 1.93 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* load-project-config
* https://github.com/cedaro/load-project-config
*
* @copyright Copyright (c) 2015 Cedaro, LLC
* @license MIT
*/
'use strict';
var _ = require('lodash');
var path = require('path');
function Project(grunt, config) {
if (!(this instanceof Project)) {
return new Project(grunt, config);
}
var loader = {};
var settings = {};
var taskMap = {};
this.loader = function(options) {
options && _.merge(loader, options);
return loader || {};
};
this.settings = function(options) {
options && _.merge(settings, options);
return settings || {};
};
this.taskMap = function(map) {
map && _.merge(taskMap, map);
return taskMap || {};
};
this.grunt = grunt;
config = _.isFunction(config) ? config() : config;
config.loader && this.loader(config.loader);
delete config.loader;
config.taskMap && this.taskMap(config.taskMap);
delete config.taskMap;
this.settings(config);
}
Project.prototype.getConfigPaths = function() {
var settings = this.settings();
var paths = [];
// Global config path.
if (settings.paths.global.config) {
paths.push(settings.paths.global.grunt);
}
// Local config path.
if (settings.paths.config) {
paths.push(path.join(process.cwd(), settings.paths.grunt));
}
return paths;
};
Project.prototype.init = function(options) {
var settings;
if (options && options.loader) {
this.loader(options.loader);
delete options.loader;
}
if (options && options.taskMap) {
this.taskMap(options.taskMap);
delete options.taskMap;
}
settings = this.settings(options);
require('time-grunt')(this.grunt);
var loader = _.merge({
configPath: this.getConfigPaths(),
data: settings,
jitGrunt: {
customTasksDir: settings.paths.grunt + '/tasks',
staticMappings: this.taskMap()
}
}, this.loader());
require('load-grunt-config')(this.grunt, loader);
return this;
};
module.exports = Project;