Adhere to XDG base directory spec for dataDir and logDir (#156)

This commit is contained in:
Forest Hoffman
2019-03-09 11:11:30 -06:00
committed by Kyle Carberry
parent e22e2c8b67
commit 30d14eeab4
2 changed files with 13 additions and 3 deletions

View File

@@ -1,5 +1,11 @@
import * as path from "path";
import * as os from "os";
export const isCli = typeof process.env.CLI !== "undefined" && process.env.CLI !== "false";
export const serveStatic = typeof process.env.SERVE_STATIC !== "undefined" && process.env.SERVE_STATIC !== "false";
export const buildDir = process.env.BUILD_DIR ? path.resolve(process.env.BUILD_DIR) : "";
const xdgResolve = (primary: string | undefined, fallback: string): string => {
return primary ? path.resolve(primary) : path.resolve(process.env.HOME || os.homedir(), fallback);
};
export const dataHome = xdgResolve(process.env.XDG_DATA_HOME, ".local/share");
export const cacheHome = xdgResolve(process.env.XDG_CACHE_HOME, ".cache");