Skip to content

Commit f86597b

Browse files
author
Guillaume Chau
committed
fix(ui): deduplicate task arguments, closes #1561
1 parent 657e425 commit f86597b

File tree

1 file changed

+28
-11
lines changed
  • packages/@vue/cli-ui/src/graphql-api/connectors

1 file changed

+28
-11
lines changed

packages/@vue/cli-ui/src/graphql-api/connectors/tasks.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const execa = require('execa')
22
const terminate = require('terminate')
3+
const chalk = require('chalk')
34
// Subs
45
const channels = require('../channels')
56
// Connectors
@@ -10,7 +11,6 @@ const plugins = require('./plugins')
1011
const prompts = require('./prompts')
1112
const views = require('./views')
1213
// Utils
13-
const { getCommand } = require('../utils/command')
1414
const { log } = require('../utils/logger')
1515
const { notify } = require('../utils/notification')
1616

@@ -62,7 +62,7 @@ function list (context) {
6262
index: list.findIndex(t => t.id === id),
6363
prompts: [],
6464
views: [],
65-
fullCommand: true,
65+
uiOnly: true,
6666
...task
6767
}
6868
}
@@ -220,8 +220,8 @@ async function run (id, context) {
220220

221221
// Answers
222222
const answers = prompts.getAnswers()
223-
let args = task.fullCommand ? [] : ['run', task.name]
224-
let command = task.fullCommand ? task.command : getCommand()
223+
let args = []
224+
let command = task.command
225225

226226
// Process command containing args
227227
if (command.indexOf(' ')) {
@@ -248,6 +248,25 @@ async function run (id, context) {
248248
})
249249
}
250250

251+
// Deduplicate arguments
252+
const dedupedArgs = []
253+
for (let i = args.length - 1; i >= 0; i--) {
254+
const arg = args[i]
255+
if (arg.indexOf('--') === 0) {
256+
if (dedupedArgs.indexOf(arg) === -1) {
257+
dedupedArgs.push(arg)
258+
} else {
259+
const value = args[i + 1]
260+
if (value && value.indexOf('--') !== 0) {
261+
dedupedArgs.pop()
262+
}
263+
}
264+
} else {
265+
dedupedArgs.push(arg)
266+
}
267+
}
268+
args = dedupedArgs.reverse()
269+
251270
if (command === 'npm') {
252271
args.splice(0, 0, '--')
253272
}
@@ -263,13 +282,11 @@ async function run (id, context) {
263282
type: 'info'
264283
}, context)
265284

266-
if (task.fullCommand) {
267-
addLog({
268-
taskId: task.id,
269-
type: 'stdout',
270-
text: `$ ${command} ${args.join(' ')}`
271-
}, context)
272-
}
285+
addLog({
286+
taskId: task.id,
287+
type: 'stdout',
288+
text: chalk.grey(`$ ${command} ${args.join(' ')}`)
289+
}, context)
273290

274291
process.env.VUE_CLI_CONTEXT = cwd.get()
275292

0 commit comments

Comments
 (0)