inspect.js 1.1 KB

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