@mpxjs/cli 3.0.0-beta.1 → 3.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/mpx.js +94 -30
- package/lib/plugins.js +1 -1
- package/lib/preset.js +4 -4
- package/package.json +8 -3
package/bin/mpx.js
CHANGED
|
@@ -8,48 +8,112 @@ const builtInPreset = require('../lib/preset')
|
|
|
8
8
|
const inquirer = require('inquirer')
|
|
9
9
|
const prompts = require('../lib/prompts')
|
|
10
10
|
const plugins = require('../lib/plugins')
|
|
11
|
+
const loadRemotePreset = require('@vue/cli/lib/util/loadRemotePreset')
|
|
12
|
+
const loadLocalPreset = require('@vue/cli/lib/util/loadLocalPreset')
|
|
13
|
+
const {
|
|
14
|
+
chalk,
|
|
15
|
+
exit,
|
|
16
|
+
error,
|
|
17
|
+
log
|
|
18
|
+
} = require('@vue/cli-shared-utils')
|
|
19
|
+
const merge = require('lodash.merge')
|
|
11
20
|
|
|
12
21
|
const args = process.argv.slice(2)
|
|
13
|
-
const
|
|
22
|
+
const parsedArgs = minimist(args)
|
|
14
23
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
+
async function resolvePreset(args = {}) {
|
|
25
|
+
const { p, preset, i, inlinePreset, c, clone } = args
|
|
26
|
+
let res = {}
|
|
27
|
+
let cliPreset = {}
|
|
28
|
+
if (p || preset) {
|
|
29
|
+
// mpx create foo --preset bar
|
|
30
|
+
cliPreset = p || preset
|
|
31
|
+
if (cliPreset.endsWith('.json') || /^\./.test(cliPreset) || path.isAbsolute(cliPreset)) {
|
|
32
|
+
res = await loadLocalPreset(path.resolve(cliPreset))
|
|
33
|
+
} else if (cliPreset.includes('/')) {
|
|
34
|
+
try {
|
|
35
|
+
log(`Fetching remote preset ${chalk.cyan(cliPreset)}...`)
|
|
36
|
+
res = await loadRemotePreset(cliPreset, c || clone)
|
|
37
|
+
} catch (e) {
|
|
38
|
+
error(`Failed fetching remote preset ${chalk.cyan(cliPreset)}:`)
|
|
39
|
+
throw e
|
|
40
|
+
}
|
|
24
41
|
}
|
|
25
|
-
|
|
26
|
-
|
|
42
|
+
} else if (i || inlinePreset) {
|
|
43
|
+
// mpx create foo --inlinePreset {...}
|
|
44
|
+
cliPreset = i || inlinePreset
|
|
45
|
+
try {
|
|
46
|
+
res = JSON.parse(cliPreset)
|
|
47
|
+
} catch (e) {
|
|
48
|
+
error(`CLI inline preset is not valid JSON: ${cliPreset}`);
|
|
49
|
+
exit(1)
|
|
27
50
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
51
|
+
}
|
|
52
|
+
return res
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function resolvePrompts(name, builtInPreset) {
|
|
56
|
+
return new Promise(function(resolve) {
|
|
57
|
+
inquirer.prompt(prompts).then(answers => {
|
|
58
|
+
if (answers.needTs) {
|
|
59
|
+
Object.assign(builtInPreset.plugins, plugins.tsSupport)
|
|
60
|
+
}
|
|
61
|
+
if (answers.cloudFunc) {
|
|
62
|
+
Object.assign(builtInPreset.plugins, plugins.cloudFunc)
|
|
63
|
+
}
|
|
64
|
+
if (answers.isPlugin) {
|
|
65
|
+
Object.assign(builtInPreset.plugins, plugins.isPlugin)
|
|
66
|
+
}
|
|
67
|
+
if (answers.transWeb) {
|
|
68
|
+
Object.assign(builtInPreset.plugins, plugins.transWeb)
|
|
69
|
+
}
|
|
70
|
+
// TODO: 添加其他 prompt 插件配置
|
|
71
|
+
|
|
72
|
+
// 各插件共享 answers 配置
|
|
73
|
+
Object.keys(builtInPreset.plugins).forEach(function(key) {
|
|
74
|
+
let plugin = builtInPreset.plugins[key]
|
|
75
|
+
plugin = Object.assign(plugin, {
|
|
76
|
+
...answers,
|
|
77
|
+
name
|
|
78
|
+
})
|
|
39
79
|
})
|
|
80
|
+
|
|
81
|
+
resolve(builtInPreset)
|
|
40
82
|
})
|
|
83
|
+
})
|
|
84
|
+
}
|
|
41
85
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
86
|
+
function regenCmd() {
|
|
87
|
+
const cmd = [...parsedArgs._, '--skipGetStarted']
|
|
88
|
+
const ignoreKey = ['_', 'p', 'preset', 'i', 'inlinePreset']
|
|
89
|
+
Object.keys(parsedArgs).map((key = '') => {
|
|
90
|
+
if (key && !ignoreKey.includes(key)) {
|
|
91
|
+
cmd.push(key.length > 1 ? `--${key}` : `-${key}`)
|
|
92
|
+
cmd.push(parsedArgs[key])
|
|
93
|
+
}
|
|
47
94
|
})
|
|
95
|
+
return cmd
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function hookForCreateCli() {
|
|
99
|
+
const name = args[1]
|
|
100
|
+
let cmd = regenCmd()
|
|
101
|
+
const mpxBuiltInPreset = await resolvePrompts(name, builtInPreset)
|
|
102
|
+
const cliPreset = await resolvePreset(parsedArgs)
|
|
103
|
+
const mergedPreset = merge(mpxBuiltInPreset, cliPreset)
|
|
104
|
+
|
|
105
|
+
cmd.push('-i', JSON.stringify(mergedPreset))
|
|
106
|
+
doVueCli(cmd)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// hook for create cli
|
|
110
|
+
if (args[0] === 'create') {
|
|
111
|
+
hookForCreateCli()
|
|
48
112
|
} else {
|
|
49
|
-
doVueCli()
|
|
113
|
+
doVueCli(args)
|
|
50
114
|
}
|
|
51
115
|
|
|
52
|
-
function doVueCli() {
|
|
116
|
+
function doVueCli(args) {
|
|
53
117
|
execa(
|
|
54
118
|
'node',
|
|
55
119
|
[
|
package/lib/plugins.js
CHANGED
package/lib/preset.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
cssPreprocessor: 'stylus',
|
|
3
3
|
plugins: {
|
|
4
|
-
'mpx-cli-service': {},
|
|
5
|
-
'vue-cli-plugin-mpx': {},
|
|
6
|
-
'vue-cli-plugin-mpx-mp': {},
|
|
7
|
-
'vue-cli-plugin-mpx-eslint': {}
|
|
4
|
+
'@mpxjs/mpx-cli-service': {},
|
|
5
|
+
'@mpxjs/vue-cli-plugin-mpx': {},
|
|
6
|
+
'@mpxjs/vue-cli-plugin-mpx-mp': {},
|
|
7
|
+
'@mpxjs/vue-cli-plugin-mpx-eslint': {}
|
|
8
8
|
}
|
|
9
9
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0-beta.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -8,13 +8,18 @@
|
|
|
8
8
|
},
|
|
9
9
|
"keywords": [],
|
|
10
10
|
"author": "",
|
|
11
|
-
"license": "
|
|
11
|
+
"license": "Apache",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@vue/cli": "^
|
|
13
|
+
"@vue/cli": "^5.0.0-rc.2",
|
|
14
14
|
"execa": "^4.1.0",
|
|
15
|
+
"lodash.merge": "^4.6.2",
|
|
15
16
|
"shelljs": "^0.8.4"
|
|
16
17
|
},
|
|
17
18
|
"engines": {
|
|
18
19
|
"node": ">=8.9"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"registry": "https://registry.npmjs.org",
|
|
23
|
+
"access": "public"
|
|
19
24
|
}
|
|
20
25
|
}
|