forked from sendicecream/DeFi-Haulers
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
77 lines (64 loc) · 1.78 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
const { src, dest, series, watch } = require('gulp');
const del = require('del');
const { config, tasks } = require('../package.json');
const { makeTask } = require('./util.js');
/* Make sure each task has its key inserted. */
Object.keys(tasks).forEach((key) => {
tasks[key].key = key;
});
/*
* Tasks loaded from package.json and converted into runnable task functions */
const taskFns = Object.keys(tasks).reduce((obj, key) => {
obj[key] = makeTask(tasks[key]);
return obj;
}, {});
/*
* Array of tasks sorted by their `order` property for running in series.
*/
const orderedTasks =
// Get all of the processors as an array
Object.values(tasks)
// Sort by the order value
.sort((a, b) => (a.order < b.order ? -1 : 1))
// Turn into processor tasks
.map(makeTask)
// Flatten into a single array
.reduce((arr, task) => arr.concat(task), []);
/*
* Remove all files from the dist dir.
*/
function clean(done) {
del.sync([config.distDir]);
return done();
}
/*
* Copy src files to the dist dir for processing. The tasks will cleanup unneeded files.
*/
function copyToDist() {
return src([config.srcDir + '**/*.*', '!**/_*.*']).pipe(dest(config.distDir));
}
/*
* $ npm run build
* The default build task, running these tasks in series.
*/
const build = series(clean, copyToDist, ...orderedTasks);
module.exports = {
default: build,
build,
/*
* $ npm run serve
* A watch task to run a local server with auto-refreshing when files are changed
*/
serve: series(build, () => {
const browserSync = require('browser-sync').create();
function refresh(done) {
browserSync.reload();
done();
}
browserSync.init({
server: config.distDir
});
watch([config.srcDir + '**/*.*'], series(build, refresh));
}),
...taskFns
};