From 6ca86aa667b0c260027f901c69c94c838e8c3f5e Mon Sep 17 00:00:00 2001 From: Derek Henscheid Date: Thu, 26 Apr 2018 15:56:44 -0500 Subject: [PATCH] feat(inspect): add a -v/--verbose flag to inspect command to output full functions (#1175) close #1157 --- .../@vue/cli-service/lib/commands/inspect.js | 19 +++++++++++-------- packages/@vue/cli/bin/vue.js | 3 ++- packages/@vue/cli/lib/inspect.js | 5 +++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/@vue/cli-service/lib/commands/inspect.js b/packages/@vue/cli-service/lib/commands/inspect.js index 6165f86cc8..8d6e8d1dd7 100644 --- a/packages/@vue/cli-service/lib/commands/inspect.js +++ b/packages/@vue/cli-service/lib/commands/inspect.js @@ -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') @@ -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) diff --git a/packages/@vue/cli/bin/vue.js b/packages/@vue/cli/bin/vue.js index 1937d6fa78..91948320bc 100755 --- a/packages/@vue/cli/bin/vue.js +++ b/packages/@vue/cli/bin/vue.js @@ -67,9 +67,10 @@ program program .command('inspect [paths...]') .option('--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 diff --git a/packages/@vue/cli/lib/inspect.js b/packages/@vue/cli/lib/inspect.js index f2e98c419a..02edb4ff74 100644 --- a/packages/@vue/cli/lib/inspect.js +++ b/packages/@vue/cli/lib/inspect.js @@ -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 { @@ -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' }) }