files.js 674 B

12345678910111213141516171819202122232425262728293031
  1. const { launch } = require('@vue/cli-shared-utils')
  2. const path = require('path')
  3. // Connectors
  4. const cwd = require('./cwd')
  5. const git = require('./git')
  6. const logs = require('./logs')
  7. async function openInEditor (input, context) {
  8. let query
  9. if (input.gitPath) {
  10. query = await git.resolveFile(input.file, context)
  11. } else {
  12. query = path.resolve(cwd.get(), input.file)
  13. }
  14. if (input.line) {
  15. query += `:${input.line}`
  16. if (input.column) {
  17. query += `:${input.column}`
  18. }
  19. }
  20. logs.add({
  21. message: `Opening file '${query}' in code editor...`,
  22. type: 'info'
  23. }, context)
  24. launch(query)
  25. return true
  26. }
  27. module.exports = {
  28. openInEditor
  29. }