-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
62 lines (53 loc) · 1.3 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
module.exports = {
run (gulp, contains, excluded, cb) {
const tasklist = gulp._registry._tasks
const tasks = []
const keys = []
forEach(tasklist, contains, excluded, function (key) {
tasks.push(function (pTasks, pos) {
keys.push(key)
if (run(pTasks, pos, keys)) {
const finishName = `finish_${contains}`
gulp.task(finishName, (done) => {
done()
cb()
})
keys.push(finishName)
gulp.series(keys)()
}
})
})
if (tasks.length > 0) {
tasks[tasks.length - 1].call(null, tasks, tasks.length - 1)
}
}
}
function forEach (obj, contains, excluded, fn) {
const arrExcluded = excluded.split(',')
const regExContains = new RegExp(contains)
let key
for (key in obj) {
if (
exec(fn, key.replace(/"/g, ''), regExContains, arrExcluded) === false
) {
break
}
}
return forEach
}
function exec (fn, key, regExContains, arrExcluded) {
const exMatch = arrExcluded.find((e) => {
const bol = new RegExp(e).test(key)
return bol
})
if (regExContains.test(key) && exMatch === undefined) { return fn(key) }
return true
}
function run (tasks, pos) {
pos--
if (pos >= 0) {
tasks[pos].call(null, tasks, pos)
return true
}
return false
}