UNPKG

1.15 kBJavaScriptView Raw
1const fs = require('fs')
2const path = require('path')
3const resolve = require('resolve')
4const { execa } = require('@vue/cli-shared-utils')
5
6module.exports = function inspect (paths, args) {
7 const cwd = process.cwd()
8 let servicePath
9 try {
10 servicePath = resolve.sync('@vue/cli-service', { basedir: cwd })
11 } catch (e) {
12 const { error } = require('@vue/cli-shared-utils')
13 error(
14 `Failed to locate @vue/cli-service.\n` +
15 `Note that \`vue inspect\` is an alias of \`vue-cli-service inspect\`\n` +
16 `and can only be used in a project where @vue/cli-service is locally installed.`
17 )
18 process.exit(1)
19 }
20 const binPath = path.resolve(servicePath, '../../bin/vue-cli-service.js')
21 if (fs.existsSync(binPath)) {
22 execa('node', [
23 binPath,
24 'inspect',
25 ...(args.mode ? ['--mode', args.mode] : []),
26 ...(args.rule ? ['--rule', args.rule] : []),
27 ...(args.plugin ? ['--plugin', args.plugin] : []),
28 ...(args.rules ? ['--rules'] : []),
29 ...(args.plugins ? ['--plugins'] : []),
30 ...(args.verbose ? ['--verbose'] : []),
31 ...paths
32 ], { cwd, stdio: 'inherit' })
33 }
34}