forked from vecnatechnologies/quick-sip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
97 lines (89 loc) · 2.8 KB
/
options.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
var _ = require('lodash'),
$ = require('gulp-load-plugins')({});
// Function creates a new options object each time
// This options object should be generated once for each execution of quick-sip
// and passed into all task registrations that require this object
module.exports = function() {
var baseDefaults = {
taskPrefix: '',
src: 'app',
dist: 'dist',
clean: {},
browserify: {},
styles: {},
copy: {}
},
options;
// Generate bundle defaults from an options parameter
function generateBundleDefaults(opts) {
return {
clean: {
skip: false,
dist: opts.dist
},
browserify: {
skip: false,
root: './' + opts.src + '/app',
transforms: [],
out: 'app.js',
failOnError: false,
debug: $.util.env.type !== 'production',
dist: opts.dist
},
styles: {
skip: false,
root: opts.src + '/app.scss',
src: opts.src,
includes: [],
dist: opts.dist
},
jshint: {
src: './' + opts.src + '/**/*.js',
skip: false,
stopOnFail: true,
config: {}
},
copy: {
skip: false,
src: opts.src,
excludes: 'scss',
dist: opts.dist,
/**
* Constructs the [source, exclusion] pair used when copying resources.
* Takes in an optional source location, defaults to the copy.src setting if not provided.
*/
_buildSrcExclusionPair: function(optionalSrc) {
var sourceLoc = optionalSrc || this.src;
return [
sourceLoc + '/**/*.*',
'!' + sourceLoc + '/**/*.+(' + this.excludes + ')'
]
},
/**
* Builds a flat map of all the [source, exclusion] pairs.
* Each item in the copy.src array will construct a new pair. If copy.src is just a single item, return the single pair.
*/
buildFullSrcArray: function() {
var copyOptions = this;
if (Array.isArray(this.src)) {
return this.src.map(function(entry) {
return copyOptions._buildSrcExclusionPair(entry);
}).reduce(function(copy, exclude) {
return copy.concat(exclude);
});
} else {
return this._buildSrcExclusionPair();
}
}
}
};
}
options = _.merge({}, baseDefaults, generateBundleDefaults(baseDefaults));
// Update options
// For certain options, if a key isn't defined at the task level, it will default to the value specified at the top level
options.update = function(newOptions) {
var bundleDefaults = generateBundleDefaults(_.merge({}, baseDefaults, newOptions));
return _.merge(options, bundleDefaults, newOptions);
};
return options;
};