index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 linePath = path.split(':')[1]
  14. const filePath = path.split(':')[0]
  15. const platform = os()
  16. if (platform === 'win32') {
  17. child_process.exec(
  18. `webstorm64.exe --line ${linePath} ${filePath}`
  19. )
  20. } else {
  21. child_process.exec(
  22. `webstorm --line ${linePath} ${filePath}`
  23. )
  24. }
  25. } else {
  26. child_process.exec('code -r -g ' + path)
  27. }
  28. }
  29. }
  30. next()
  31. })
  32. },
  33. }
  34. }
  35. function os() {
  36. 'use strict'
  37. const os = require('os')
  38. const platform = os.platform()
  39. return platform
  40. }