-
Notifications
You must be signed in to change notification settings - Fork 6
/
util.js
72 lines (62 loc) · 1.98 KB
/
util.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
import _gulp from "gulp";
export const { src, dest, parallel, task, series, watch } = _gulp;
export const gulp = _gulp;
// Streamline Gulp Tasks
export const stream = (_src, _opt = {}) => {
return new Promise((resolve) => {
let _end = _opt.end;
let host =
typeof _src !== "string" && !Array.isArray(_src)
? _src
: src(_src, _opt.opts),
_pipes = _opt.pipes || [],
_dest = _opt.dest === undefined ? "." : _opt.dest,
_log = _opt.log || (() => { });
_pipes.forEach((val) => {
if (val !== undefined && val !== null) {
host = host.pipe(val);
}
});
if (_dest !== null) host = host.pipe(dest(_dest));
host.on("data", _log);
host = host.on("end", (...args) => {
if (typeof _end === "function") _end(...args);
resolve(host);
}); // Output
if (Array.isArray(_end)) {
_end.forEach((val) => {
if (val !== undefined && val !== null) {
host = host.pipe(val);
}
});
}
return host;
});
};
// A list of streams
export const streamList = (...args) => {
return Promise.all(
(Array.isArray(args[0]) ? args[0] : args).map((_stream) => {
return Array.isArray(_stream) ? stream(..._stream) : _stream;
})
);
};
// A list of gulp tasks
export const tasks = (list) => {
let entries = Object.entries(list);
for (let [name, fn] of entries) {
task(name, (...args) => fn(...args));
}
};
export const parallelFn = (...args) => {
let tasks = args.filter((x) => x !== undefined && x !== null);
return function parallelrun(done) {
return parallel(...tasks)(done);
};
};
export const seriesFn = (...args) => {
let tasks = args.filter((x) => x !== undefined && x !== null);
return function seriesrun(done) {
return series(...tasks)(done);
};
};