-
Notifications
You must be signed in to change notification settings - Fork 0
/
TaskHandler.js
62 lines (49 loc) · 1.21 KB
/
TaskHandler.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
import EventEmitter from 'events'
import load from 'gulpy-boiler-load-plugins'
import merge from 'merge-deep'
import cli from './cli'
export default class TaskHandler extends EventEmitter {
constructor(name, plugins = {}, config = {}) {
super()
this.name = name
this.plugins = plugins
this.config = config
}
cli(opts = {}) {
const data = cli(opts)
const {flags} = data
const cliData = Object.keys(flags).reduce((acc, key) => {
const aliasVal = opts.alias && opts.alias[key]
if (aliasVal) {
Object.assign(acc.flags, {
[aliasVal]: flags[key]
})
}
return acc
}, data)
this.configure({
cli: cliData
})
return cliData
}
/**
* Merge config/plugins from base tasks with
* - config/plugins external task
* - onto context of TaskHandler parent instance
*/
configure(config = {}) {
this.config = merge({}, this.config, config)
return this.config
}
loadPlugins(opts = {}) {
Object.assign(this.plugins, load(opts))
return this.plugins
}
on(event, cb) {
super.on(event, cb)
return this
}
run(gulp, ...args) {
return this.task(gulp, this.plugins, this.config, ...args)
}
}