mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-28 18:19:02 -06:00
feat(tasks): override args switch, closes #3236
This commit is contained in:
@@ -14,6 +14,7 @@ const projects = require('./projects')
|
||||
const { log } = require('../util/logger')
|
||||
const { notify } = require('../util/notification')
|
||||
const { terminate } = require('../util/terminate')
|
||||
const { parseArgs } = require('../util/parse-args')
|
||||
|
||||
const MAX_LOGS = 2000
|
||||
const VIEW_ID = 'vue-project-tasks'
|
||||
@@ -237,15 +238,7 @@ async function run (id, context) {
|
||||
|
||||
// Answers
|
||||
const answers = prompts.getAnswers()
|
||||
let args = []
|
||||
let command = task.command
|
||||
|
||||
// Process command containing args
|
||||
if (command.indexOf(' ')) {
|
||||
const parts = command.split(/\s+/)
|
||||
command = parts.shift()
|
||||
args = parts
|
||||
}
|
||||
let [command, ...args] = parseArgs(task.command)
|
||||
|
||||
// Output colors
|
||||
// See: https://www.npmjs.com/package/supports-color
|
||||
@@ -253,6 +246,13 @@ async function run (id, context) {
|
||||
|
||||
// Plugin API
|
||||
if (task.onBeforeRun) {
|
||||
if (!answers.$_overrideArgs) {
|
||||
const origPush = args.push.bind(args)
|
||||
args.push = (...items) => {
|
||||
if (items.length && args.indexOf(items[0]) !== -1) return items.length
|
||||
return origPush(...items)
|
||||
}
|
||||
}
|
||||
await task.onBeforeRun({
|
||||
answers,
|
||||
args
|
||||
@@ -581,6 +581,15 @@ async function restoreParameters ({ id }, context) {
|
||||
const task = findOne(id, context)
|
||||
if (task) {
|
||||
await prompts.reset()
|
||||
if (task.prompts.length) {
|
||||
prompts.add({
|
||||
name: '$_overrideArgs',
|
||||
type: 'confirm',
|
||||
default: false,
|
||||
message: 'org.vue.views.project-task-details.override-args.message',
|
||||
description: 'org.vue.views.project-task-details.override-args.description'
|
||||
})
|
||||
}
|
||||
task.prompts.forEach(prompts.add)
|
||||
const data = getSavedData(id, context)
|
||||
if (data) {
|
||||
|
||||
27
packages/@vue/cli-ui/apollo-server/util/parse-args.js
Normal file
27
packages/@vue/cli-ui/apollo-server/util/parse-args.js
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @param {string} args
|
||||
*/
|
||||
exports.parseArgs = function (args) {
|
||||
const parts = args.split(/\s+|=/)
|
||||
const result = []
|
||||
let arg
|
||||
let index = 0
|
||||
for (const part of parts) {
|
||||
const l = part.length
|
||||
if (!arg && part.charAt(0) === '"') {
|
||||
arg = part.substr(1)
|
||||
} else if (part.charAt(l - 1) === '"' && (
|
||||
l === 1 || part.charAt(l - 2) !== '\\'
|
||||
)) {
|
||||
arg += args.charAt(index - 1) + part.substr(0, l - 1)
|
||||
result.push(arg)
|
||||
arg = null
|
||||
} else if (arg) {
|
||||
arg += args.charAt(index - 1) + part
|
||||
} else {
|
||||
result.push(part)
|
||||
}
|
||||
index += part.length + 1
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -448,7 +448,11 @@
|
||||
"command": "Script command",
|
||||
"parameters": "Parameters",
|
||||
"more-info": "More Info",
|
||||
"output": "Output"
|
||||
"output": "Output",
|
||||
"override-args": {
|
||||
"message": "Override hard-coded arguments",
|
||||
"description": "If enabled, hard-coded arguments in the package.json file will be replaced with the value defined below"
|
||||
}
|
||||
},
|
||||
"project-dependencies": {
|
||||
"title": "Project dependencies",
|
||||
|
||||
Reference in New Issue
Block a user