1 |
|
2 | import Emittery from 'emittery'
|
3 | import path from 'path'
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | class Plugin extends Emittery {
|
11 | constructor (mid, options) {
|
12 | super()
|
13 |
|
14 | this.mid = mid
|
15 |
|
16 | if (!options.name) throw new Error('The plugin have no name')
|
17 |
|
18 | |
19 |
|
20 |
|
21 |
|
22 | this.name = options.name
|
23 |
|
24 | if (!options.path) throw new Error('The plugin as no path')
|
25 |
|
26 | |
27 |
|
28 |
|
29 |
|
30 | this.path = options.path
|
31 |
|
32 | |
33 |
|
34 |
|
35 |
|
36 | this.config = options.config || {}
|
37 |
|
38 | |
39 |
|
40 |
|
41 |
|
42 | this.dirs = this.config.dirs || {}
|
43 |
|
44 | |
45 |
|
46 |
|
47 |
|
48 | this.pm = mid.pm
|
49 |
|
50 | |
51 |
|
52 |
|
53 |
|
54 | this.package = options.package
|
55 | }
|
56 |
|
57 | |
58 |
|
59 |
|
60 | async init () {}
|
61 |
|
62 | |
63 |
|
64 |
|
65 |
|
66 |
|
67 | getDir (name) {
|
68 | if (!this.pm.pluginDirs[name] && !this.dirs[name]) {
|
69 | this.mid.warn('Unknow plugin dir ' + name)
|
70 | return null
|
71 | }
|
72 |
|
73 | return this.dirs[name] ? this.dirs[name] : this.pm.pluginDirs[name]
|
74 | }
|
75 |
|
76 | getDirPath (name) {
|
77 | const dir = this.getDir(name)
|
78 | return dir ? path.join(this.path, dir) : null
|
79 | }
|
80 | }
|
81 |
|
82 | export default Plugin
|