import fs from "fs-extra"; import os from "os"; import path from "path"; const xdgConfigPath = function(file: string): string | undefined { const xdgConfigHome = process.env.XDG_CONFIG_HOME; if (xdgConfigHome) { const rcDir = path.join(xdgConfigHome, "luban"); if (!fs.existsSync(rcDir)) { fs.ensureDirSync(rcDir, 0o700); } return path.join(rcDir, file); } }; const migrateWindowsConfigPath = function(file: string): void { if (process.platform !== "win32") { return; } const appData = process.env.APPDATA; if (appData) { const rcDir = path.join(appData, "luban"); const rcFile = path.join(rcDir, file); const properRcFile = path.join(os.homedir(), file); if (fs.existsSync(rcFile)) { try { if (fs.existsSync(properRcFile)) { fs.removeSync(rcFile); } else { fs.moveSync(rcFile, properRcFile); } } catch (e) {} } } }; export const getRcPath = function(file: string): string { migrateWindowsConfigPath(file); return xdgConfigPath(file) || path.join(os.homedir(), file); };