1 | 'use strict'
|
2 |
|
3 | const logger = require('./logger')
|
4 | const isObject = require('./is').Object
|
5 | const isArray = require('./is').Array
|
6 | const exec = require('./exec')
|
7 | const pluginExists = require('./check').pluginExists
|
8 |
|
9 |
|
10 | const importExtend = (extend, xdc, options) => {
|
11 | require(`xdc-${extend}`)(xdc, options)
|
12 | logger.success(`插件加载成功: ${extend}`)
|
13 | }
|
14 |
|
15 |
|
16 | const installExtend = name => {
|
17 | logger.warn(`插件不存在,自动下载插件: ${name}`)
|
18 | exec('xdc', ['import', name], {
|
19 | stdio: 'inherit'
|
20 | })
|
21 | }
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | module.exports = (_extends, xdc) => {
|
30 | const isObj = isObject(_extends)
|
31 |
|
32 | Object.keys(_extends || {}).reverse().forEach(key => {
|
33 | let extend = isObj ? key : _extends[key]
|
34 | let options = isObj ? _extends[key] : {}
|
35 |
|
36 | if (isArray(extend)) {
|
37 | options = extend[1]
|
38 | extend = extend[0]
|
39 | }
|
40 |
|
41 | const extendName = extend.split('@')[0]
|
42 |
|
43 | if (!pluginExists(`xdc-${extendName}`)) {
|
44 | installExtend(extend)
|
45 | }
|
46 |
|
47 | importExtend(extendName, xdc, options)
|
48 | })
|
49 | console.log()
|
50 | }
|