This repository has been archived by the owner on Jan 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
124 lines (109 loc) · 4.66 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Copyright 2014 Workiva, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
module.exports = function(gulp, userConfig){
var _ = require('lodash');
var cwd = process.cwd();
var glob = require('glob');
var path = require('path');
var getDeps = require('./src/depTreeParser');
// Load default options from gulpconfig.json
var defaultOptions = require('./src/gulpconfig.json');
// Use user defined languages if provided, otherwise use defaults
var languages = 'languages' in userConfig ? userConfig.languages : defaultOptions.languages;
// Apply changes to options based on languages selected
defaultOptions = require('./src/applyLanguageOptions')(defaultOptions, languages);
// Merge user defined config with wGulp's default options
var options = require('./src/mergeOptions')(userConfig, defaultOptions);
// Is this a `dist` run? Check the sequence for 'dist'
gulp.on('start', function(e){
options.isDist = _.contains(e.message.split(','), 'dist');
});
// Echo a system bell on all errors to alert the user
gulp.on('err', function(e){
console.log("\u0007");
});
// Check for circular dependencies (cycles) in resulting taskTree
function detectCycle(task, key, val){
if(_.contains(val, task)){
if(_.contains(getDeps(options, task), key)){
console.log("Circular task dependency detected! \t" + task + " --> " + key);
}
}
}
_.forOwn(options.taskTree, function(val, key){
val = getDeps(options, key);
_.forOwn(options.taskTree, function(innerVal, innerKey){
if(innerKey != key){
detectCycle(innerKey, key, val);
}
});
});
// Put our custom describe method onto gulp
gulp.desc = require('./src/desc');
// Register task functions for exporting
var sPath = './src/subtasks/';
var subtasks = {
analyze: require(sPath + 'analyze')(gulp, options),
applyLicense: require(sPath + 'applyLicense')(gulp, options),
clean: require(sPath + 'clean')(gulp, options),
coffee: require(sPath + 'coffee')(gulp, options),
compass: require(sPath + 'compass')(gulp, options),
concat: require(sPath + 'concat')(gulp, options),
connect: require(sPath + 'connect')(gulp, options),
copy: require(sPath + 'copy')(gulp, options),
jasmine: require(sPath + 'jasmine')(gulp, options),
jsdoc: require(sPath + 'jsdoc')(gulp, options),
jshint: require(sPath + 'jshint')(gulp, options),
jsx: require(sPath + 'jsx')(gulp, options),
livescript: require(sPath + 'livescript')(gulp, options),
minify_css: require(sPath + 'minifyCss')(gulp, options),
minify_js: require(sPath + 'minifyJs')(gulp, options),
sass: require(sPath + 'sass')(gulp, options),
tsc: require(sPath + 'tsc')(gulp, options),
tslint: require(sPath + 'tslint')(gulp, options)
};
// Create tasks for each task function with default options
_.forOwn(subtasks, function(val, key){
key = key.replace('_', ':');
var taskDeps = getDeps(options, key);
gulp.task(key, taskDeps, val());
});
// Add runSequence function (not really a task/subtask)
subtasks.runSequence = require(sPath + 'runSequence')(gulp, options);
// Generate bundle tasks
require('./src/bundling/buildBundleTasks')(gulp, options);
// Create tasks in task folders
function addTasks(folder) {
var files = glob('*.js', {
cwd: folder,
sync: true
});
_.forEach(files, function(file){
var taskName = file.replace(/\.js$/i, '');
var taskPath = path.resolve(folder, taskName);
require(taskPath)(gulp, options, subtasks);
});
};
var globalTaskFolder = path.resolve(__dirname, 'src/tasks/');
var projectTaskFolder = path.resolve(cwd, 'tasks/');
addTasks(globalTaskFolder);
addTasks(projectTaskFolder);
// Add config to exports
subtasks.config = options;
// Expose getDeps in case consumers want to use it
subtasks.getDeps = _.curry(getDeps)(options);
return subtasks;
};