@mpxjs/mpx-cli-service 2.0.6 → 2.1.0
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-cli-service.js +70 -30
- package/lib/Service.js +4 -0
- package/package.json +2 -1
package/bin/mpx-cli-service.js
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
2
|
const { semver, error } = require('@vue/cli-shared-utils')
|
|
4
3
|
const requiredVersion = require('../package.json').engines.node
|
|
5
4
|
const filterPluginsByPlatform = require('../utils/filterPlugins')
|
|
5
|
+
const { LogUpdate } = require('@mpxjs/vue-cli-plugin-mpx/utils/reporter')
|
|
6
|
+
const Service = require('../lib/Service')
|
|
7
|
+
const {
|
|
8
|
+
getTargets,
|
|
9
|
+
setTargetProcessEnv,
|
|
10
|
+
runServiceCommand,
|
|
11
|
+
removeArgv,
|
|
12
|
+
rawTarget
|
|
13
|
+
} = require('@mpxjs/cli-shared-utils')
|
|
6
14
|
|
|
7
|
-
if (
|
|
15
|
+
if (
|
|
16
|
+
!semver.satisfies(process.version, requiredVersion, {
|
|
17
|
+
includePrerelease: true
|
|
18
|
+
})
|
|
19
|
+
) {
|
|
8
20
|
error(
|
|
9
21
|
`You are using Node ${process.version}, but mpx-cli-service ` +
|
|
10
|
-
|
|
22
|
+
`requires Node ${requiredVersion}.\nPlease upgrade your Node version.`
|
|
11
23
|
)
|
|
12
24
|
process.exit(1)
|
|
13
25
|
}
|
|
14
26
|
|
|
15
|
-
const Service = require('../lib/Service')
|
|
16
|
-
const { parseTarget } = require('@mpxjs/vue-cli-plugin-mpx/utils')
|
|
17
27
|
const service = new Service(process.env.VUE_CLI_CONTEXT || process.cwd())
|
|
18
28
|
const rawArgv = process.argv.slice(2)
|
|
19
29
|
const args = require('minimist')(rawArgv, {
|
|
@@ -32,31 +42,61 @@ const args = require('minimist')(rawArgv, {
|
|
|
32
42
|
'verbose'
|
|
33
43
|
]
|
|
34
44
|
})
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
const setPluginsToSkip = service.setPluginsToSkip.bind(service)
|
|
41
|
-
service.setPluginsToSkip = function (args) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
const targets = getTargets(args)
|
|
46
|
+
if (targets.length === 1) {
|
|
47
|
+
const command = args._[0]
|
|
48
|
+
const target = targets[0]
|
|
49
|
+
setTargetProcessEnv(target)
|
|
50
|
+
const setPluginsToSkip = service.setPluginsToSkip.bind(service)
|
|
51
|
+
service.setPluginsToSkip = function (args) {
|
|
52
|
+
setPluginsToSkip(args, rawArgv)
|
|
53
|
+
let plugins = filterPluginsByPlatform(process.env.MPX_CLI_MODE)
|
|
54
|
+
// 小程序模式下,将 @vue/cli-service 内置的 base 及 app 配置过滤掉
|
|
55
|
+
if (process.env.MPX_CLI_MODE !== 'web') {
|
|
56
|
+
plugins = plugins.concat([
|
|
57
|
+
'built-in:config/base',
|
|
58
|
+
'built-in:config/app',
|
|
59
|
+
'built-in:config/css'
|
|
60
|
+
])
|
|
61
|
+
}
|
|
62
|
+
plugins.forEach((plugin) => {
|
|
63
|
+
this.pluginsToSkip.add(plugin)
|
|
64
|
+
})
|
|
51
65
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
66
|
+
if (target.env) args.mode = target.env
|
|
67
|
+
service.run(command, args, rawArgv).catch((err) => {
|
|
68
|
+
error(err)
|
|
69
|
+
process.exit(1)
|
|
70
|
+
})
|
|
71
|
+
} else {
|
|
72
|
+
const chunks = []
|
|
73
|
+
let doneNum = 0
|
|
74
|
+
const num = 0
|
|
75
|
+
const logUpdate = new LogUpdate()
|
|
76
|
+
targets.forEach((target, index) => {
|
|
77
|
+
const ls = runServiceCommand(
|
|
78
|
+
[...removeArgv(rawArgv, 'targets'), '--targets', rawTarget(target)],
|
|
79
|
+
{
|
|
80
|
+
env: {
|
|
81
|
+
...process.env,
|
|
82
|
+
FORCE_COLOR: true,
|
|
83
|
+
NODE_ENV: undefined
|
|
84
|
+
},
|
|
85
|
+
stdio: 'inherit'
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
// 子进程输出内容
|
|
89
|
+
ls.on('message', (data) => {
|
|
90
|
+
if (data.status === 'done') {
|
|
91
|
+
doneNum++
|
|
92
|
+
if (doneNum === num) {
|
|
93
|
+
doneNum = 0
|
|
94
|
+
logUpdate.done()
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
chunks[index] = data.message
|
|
98
|
+
logUpdate.render(chunks.join('\n\n'))
|
|
99
|
+
}
|
|
100
|
+
})
|
|
55
101
|
})
|
|
56
102
|
}
|
|
57
|
-
|
|
58
|
-
// 优先wx:production 然后是 --mode=production
|
|
59
|
-
service.run(command, { ...args, mode: env || args.mode }, rawArgv).catch((err) => {
|
|
60
|
-
error(err)
|
|
61
|
-
process.exit(1)
|
|
62
|
-
})
|
package/lib/Service.js
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/mpx-cli-service",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "local service for mpx-cli project",
|
|
5
5
|
"main": "lib/Service.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"mpx-cli-service": "bin/mpx-cli-service.js"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
+
"@mpxjs/cli-shared-utils": "^2.0.7",
|
|
10
11
|
"@vue/cli-service": "^5.0.0",
|
|
11
12
|
"@vue/cli-shared-utils": "^5.0.4",
|
|
12
13
|
"minimist": "^1.2.5"
|