index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const child_process = require('child_process')
  2. export default function GvaPositionServer() {
  3. return {
  4. name: 'gva-position-server',
  5. apply: 'serve',
  6. configureServer(server) {
  7. server.middlewares.use((req, _, next) => {
  8. if (req._parsedUrl.pathname === '/gvaPositionCode') {
  9. const path =
  10. req._parsedUrl.query && req._parsedUrl.query.split('=')[1]
  11. if (path && path !== 'null') {
  12. if (process.env.VITE_EDITOR === 'webstorm') {
  13. const lastColonIndex = path.lastIndexOf(':')
  14. const linePath = path.substring(lastColonIndex + 1)
  15. const filePath = path.substring(0, lastColonIndex)
  16. const platform = os()
  17. if (platform === 'win32') {
  18. child_process.exec(
  19. `webstorm64.exe --line ${linePath} ${filePath}`
  20. )
  21. } else {
  22. child_process.exec(
  23. `webstorm --line ${linePath} ${filePath}`
  24. )
  25. }
  26. } else {
  27. child_process.exec('code -r -g ' + path)
  28. }
  29. }
  30. }
  31. next()
  32. })
  33. },
  34. }
  35. }
  36. function os() {
  37. 'use strict'
  38. const os = require('os')
  39. const platform = os.platform()
  40. return platform
  41. }