-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathgulpfile.js
86 lines (77 loc) · 2.6 KB
/
gulpfile.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
const config = require('./gulp-config.json');
const runSequence = require('run-sequence');
const gulp = require('gulp');
const del = require('del');
const browserSync = require('browser-sync');
const watch = require('gulp-watch');
const util = require('gulp-util');
var fs = require('fs');
var cleanFolderList = [];
var buildTaskList = [];
var watchTaskList = [];
util.env.boilerplate = {
config
};
for(var taskName in config.tasks) {
if (config.tasks.hasOwnProperty(taskName)) {
var task = config.tasks[taskName];
var relatedTask = task.hasOwnProperty('task') ? task.task : taskName;
if(fs.existsSync('./gulp-tasks/' + relatedTask + '.js')) {
gulp.task(taskName, require('./gulp-tasks/' + relatedTask));
} else {
gulp.task(taskName, function(taskName, relatedTask) {
var taskExport = require('./node_modules/adfab-gulp-boilerplate/tasks/' + relatedTask);
return function() {
taskExport(taskName);
}
}(taskName, relatedTask));
}
if(!task.hasOwnProperty('build') || task.build) {
buildTaskList.push(taskName);
}
if(task.hasOwnProperty('destination') && (!task.hasOwnProperty('clean') || task.clean)) {
cleanFolderList.push(config.tasks[taskName].destination);
}
if(task.hasOwnProperty('watch')) {
watchTaskList.push({'task': taskName, 'fileList': task.watch });
} else if(task.hasOwnProperty('source')) {
// 'scripts' task is bundled with babel, watch is managed in 'scripts' task
if(taskName !== 'scripts') {
watchTaskList.push({'task': taskName, 'fileList': task.source });
}
}
}
}
/**
* Clean build directory
*/
gulp.task('clean', function() {
return del(cleanFolderList, { cwd: config.destinationRoot });
});
/**
* Build app from sources
*/
gulp.task('build', ['clean'], function() {
return runSequence(buildTaskList);
});
//BrowserSync
gulp.task('browser-sync', function() {
browserSync.init({
proxy: config.vhost
});
});
/**
* Watch task for development
*/
gulp.task('watch', ['build'], function() {
for(var index in watchTaskList) {
var watchTask = watchTaskList[index];
watch(watchTask.fileList, { cwd: config.sourceRoot }, function(task) {
return function() {
return runSequence([task]);
};
}(watchTask.task));
}
});
gulp.task('serve', ['watch', 'browser-sync']);
gulp.task('default', ['build'], function () { });