Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/lib/commands/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = (api, options) => {
'--verbose': 'show full function definitions in output'
}
}, args => {
const get = require('get-value')
const { get } = require('@vue/cli-shared-utils')
const { toString } = require('webpack-chain')
const config = api.resolveWebpackConfig()
const { _: paths, verbose } = args
Expand Down
1 change: 0 additions & 1 deletion packages/@vue/cli-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"file-loader": "^1.1.11",
"friendly-errors-webpack-plugin": "^1.7.0",
"fs-extra": "^6.0.1",
"get-value": "^3.0.1",
"globby": "^8.0.1",
"hash-sum": "^1.0.2",
"html-webpack-plugin": "^3.2.0",
Expand Down
1 change: 1 addition & 0 deletions packages/@vue/cli-shared-utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'exit',
'ipc',
'logger',
'object',
'openBrowser',
'pluginResolution',
'request',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ exports.get = function (target, path) {
return obj[fields[l - 1]]
}

exports.remove = function (target, path) {
exports.unset = function (target, path) {
const fields = path.split('.')
let obj = target
const l = fields.length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const plugins = require('./plugins')
const folders = require('./folders')
const prompts = require('./prompts')
// Utils
const { get, set, remove } = require('../../src/util/object')
const { get, set, unset } = require('@vue/cli-shared-utils')
const { log } = require('../util/logger')
const { loadModule } = require('@vue/cli/lib/util/module')
const extendJSConfig = require('@vue/cli/lib/util/extendJSConfig')
Expand Down Expand Up @@ -232,7 +232,7 @@ async function save (id, context) {

const value = newData[key]
if (typeof value === 'undefined') {
remove(data[fileId], key)
unset(data[fileId], key)
} else {
set(data[fileId], key, value)
}
Expand Down
8 changes: 4 additions & 4 deletions packages/@vue/cli-ui/apollo-server/connectors/prompts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Utils
const ObjectUtil = require('../../src/util/object')
const { get, set, unset } = require('@vue/cli-shared-utils')
const { log } = require('../util/logger')

let answers = {}
Expand Down Expand Up @@ -85,11 +85,11 @@ async function getChoices (prompt) {
}

function setAnswer (id, value) {
ObjectUtil.set(answers, id, value)
set(answers, id, value)
}

function removeAnswer (id) {
ObjectUtil.remove(answers, id)
unset(answers, id)
}

function generatePrompt (data) {
Expand Down Expand Up @@ -159,7 +159,7 @@ function getAnswers () {
}

function getAnswer (id) {
return ObjectUtil.get(answers, id)
return get(answers, id)
}

async function reset () {
Expand Down
12 changes: 12 additions & 0 deletions packages/@vue/cli/bin/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ program
loadCommand('init', '@vue/cli-init')
})

program
.command('config [value]')
.description('inspect and modify the config')
.option('-g, --get <path>', 'get value from option')
.option('-s, --set <path> <value>', 'set option value')
.option('-d, --delete <path>', 'delete option from config')
.option('-e, --edit', 'open config with default editor')
.option('--json', 'outputs JSON result only')
.action((value, cmd) => {
require('../lib/config')(value, cleanArgs(cmd))
})

// output help information on unknown commands
program
.arguments('<command>')
Expand Down
86 changes: 86 additions & 0 deletions packages/@vue/cli/lib/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const fs = require('fs-extra')
const path = require('path')
const homedir = require('os').homedir()
const { get, set, unset, error } = require('@vue/cli-shared-utils')
const launch = require('launch-editor')

async function config (value, options) {
const file = path.resolve(homedir, '.vuerc')
const config = await fs.readJson(file)

if (!options.delete && !options.get && !options.edit && !options.set) {
if (options.json) {
console.log(JSON.stringify({
resolvedPath: file,
content: config
}))
} else {
console.log('Resolved path: ' + file + '\n', JSON.stringify(config, null, 2))
}
}

if (options.get) {
const value = get(config, options.get)
if (options.json) {
console.log(JSON.stringify({
value
}))
} else {
console.log(value)
}
}

if (options.delete) {
unset(config, options.delete)
await fs.writeFile(file, JSON.stringify(config, null, 2), 'utf-8')
if (options.json) {
console.log(JSON.stringify({
deleted: options.delete
}))
} else {
console.log(`You have removed the option: ${options.delete}`)
}
}

if (options.edit) {
launch(file)
}

if (options.set && !value) {
throw new Error(`Make sure you define a value for the option ${options.set}`)
}

if (options.set && value) {
set(config, options.set, value)

if (value.match('[0-9]')) {
set(config, options.set, parseInt(value))
}

if (value === 'true') {
set(config, options.set, true)
}

if (value === 'false') {
set(config, options.set, false)
}

await fs.writeFile(file, JSON.stringify(config, null, 2), 'utf-8')
if (options.json) {
console.log(JSON.stringify({
updated: options.set
}))
} else {
console.log(`You have updated the option: ${options.set} to ${value}`)
}
}
}

module.exports = (...args) => {
return config(...args).catch(err => {
error(err)
if (!process.env.VUE_CLI_TEST) {
process.exit(1)
}
})
}
1 change: 1 addition & 0 deletions packages/@vue/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"javascript-stringify": "^1.6.0",
"js-yaml": "^3.12.0",
"klaw-sync": "^4.0.0",
"launch-editor": "^2.2.1",
"lodash.clonedeep": "^4.5.0",
"minimist": "^1.2.0",
"recast": "^0.15.2",
Expand Down
6 changes: 0 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5476,12 +5476,6 @@ get-value@^2.0.3, get-value@^2.0.6:
version "2.0.6"
resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28"

get-value@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/get-value/-/get-value-3.0.1.tgz#5efd2a157f1d6a516d7524e124ac52d0a39ef5a8"
dependencies:
isobject "^3.0.1"

getos@2.8.4:
version "2.8.4"
resolved "https://registry.yarnpkg.com/getos/-/getos-2.8.4.tgz#7b8603d3619c28e38cb0fe7a4f63c3acb80d5163"
Expand Down