rcPath.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const fs = require('fs-extra')
  2. const os = require('os')
  3. const path = require('path')
  4. const xdgConfigPath = file => {
  5. const xdgConfigHome = process.env.XDG_CONFIG_HOME
  6. if (xdgConfigHome) {
  7. const rcDir = path.join(xdgConfigHome, 'vue')
  8. if (!fs.existsSync(rcDir)) {
  9. fs.ensureDirSync(rcDir, 0o700)
  10. }
  11. return path.join(rcDir, file)
  12. }
  13. }
  14. // migration for 3.0.0-rc.7
  15. // we introduced a change storing .vuerc in AppData, but the benefit isn't
  16. // really obvious so we are reverting it to keep consistency across OSes
  17. const migrateWindowsConfigPath = file => {
  18. if (process.platform !== 'win32') {
  19. return
  20. }
  21. const appData = process.env.APPDATA
  22. if (appData) {
  23. const rcDir = path.join(appData, 'vue')
  24. const rcFile = path.join(rcDir, file)
  25. const properRcFile = path.join(os.homedir(), file)
  26. if (fs.existsSync(rcFile)) {
  27. try {
  28. if (fs.existsSync(properRcFile)) {
  29. fs.removeSync(rcFile)
  30. } else {
  31. fs.moveSync(rcFile, properRcFile)
  32. }
  33. } catch (e) {}
  34. }
  35. }
  36. }
  37. exports.getRcPath = file => {
  38. migrateWindowsConfigPath(file)
  39. return (
  40. process.env.VUE_CLI_CONFIG_PATH ||
  41. xdgConfigPath(file) ||
  42. path.join(os.homedir(), file)
  43. )
  44. }