Skip to content

Commit

Permalink
feat(inspect): add a -v/--verbose flag to inspect command to output f…
Browse files Browse the repository at this point in the history
…ull functions (#1175)

close #1157
  • Loading branch information
dhensche authored and yyx990803 committed Apr 26, 2018
1 parent abb82ab commit 6ca86aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
19 changes: 11 additions & 8 deletions packages/@vue/cli-service/lib/commands/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module.exports = (api, options) => {
description: 'inspect internal webpack config',
usage: 'vue-cli-service inspect [options] [...paths]',
options: {
'--mode': 'specify env mode (default: development)'
'--mode': 'specify env mode (default: development)',
'--verbose': 'show full function definitions in output'
}
}, args => {
api.setMode(args.mode || 'development')
Expand All @@ -27,13 +28,15 @@ module.exports = (api, options) => {

const pluginRE = /(?:function|class) (\w+Plugin)/
console.log(stringify(res, (value, indent, stringify) => {
if (typeof value === 'function' && value.toString().length > 100) {
return `function () { /* omitted long function */ }`
}
if (value && typeof value.constructor === 'function') {
const match = value.constructor.toString().match(pluginRE)
if (match) {
return `/* ${match[1]} */ ` + stringify(value)
if (!args.verbose) {
if (typeof value === 'function' && value.toString().length > 100) {
return `function () { /* omitted long function */ }`
}
if (value && typeof value.constructor === 'function') {
const match = value.constructor.toString().match(pluginRE)
if (match) {
return `/* ${match[1]} */ ` + stringify(value)
}
}
}
return stringify(value)
Expand Down
3 changes: 2 additions & 1 deletion packages/@vue/cli/bin/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ program
program
.command('inspect [paths...]')
.option('--mode <mode>')
.option('-v --verbose', 'Show full function definitions in output')
.description('inspect the webpack config in a project with vue-cli-service')
.action((paths, cmd) => {
require('../lib/inspect')(paths, cmd.mode)
require('../lib/inspect')(paths, cleanArgs(cmd))
})

program
Expand Down
5 changes: 3 additions & 2 deletions packages/@vue/cli/lib/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path')
const execa = require('execa')
const resolve = require('resolve')

module.exports = function inspect (paths, mode) {
module.exports = function inspect (paths, args) {
const cwd = process.cwd()
let servicePath
try {
Expand All @@ -18,7 +18,8 @@ module.exports = function inspect (paths, mode) {
execa('node', [
binPath,
'inspect',
...(mode ? ['--mode', mode] : []),
...(args.mode ? ['--mode', args.mode] : []),
...(args.verbose ? ['--verbose'] : []),
...paths
], { cwd, stdio: 'inherit' })
}
Expand Down

0 comments on commit 6ca86aa

Please sign in to comment.