UNPKG

@stryke/prisma-trpc-generator

Version:

A fork of the prisma-trpc-generator code to work in ESM with Prisma v6.

87 lines (85 loc) 5.39 kB
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs'); const require_title_case = require('../../string-format/src/title-case.cjs'); let _stryke_path_join_paths = require("@stryke/path/join-paths"); let node_path = require("node:path"); node_path = require_runtime.__toESM(node_path, 1); let node_os = require("node:os"); node_os = require_runtime.__toESM(node_os, 1); //#region ../env/src/get-env-paths.ts const homedir = node_os.default.homedir(); const tmpdir = node_os.default.tmpdir(); const macos = (orgId) => { const library = (0, _stryke_path_join_paths.joinPaths)(homedir, "Library"); return { data: (0, _stryke_path_join_paths.joinPaths)(library, "Application Support", orgId), config: (0, _stryke_path_join_paths.joinPaths)(library, "Preferences", orgId), cache: (0, _stryke_path_join_paths.joinPaths)(library, "Caches", orgId), log: (0, _stryke_path_join_paths.joinPaths)(library, "Logs", orgId), temp: (0, _stryke_path_join_paths.joinPaths)(tmpdir, orgId) }; }; const windows = (orgId) => { const appData = process.env.APPDATA || (0, _stryke_path_join_paths.joinPaths)(homedir, "AppData", "Roaming"); const localAppData = process.env.LOCALAPPDATA || (0, _stryke_path_join_paths.joinPaths)(homedir, "AppData", "Local"); const windowsFormattedOrgId = require_title_case.titleCase(orgId).trim().replace(/\s+/g, ""); return { data: (0, _stryke_path_join_paths.joinPaths)(localAppData, windowsFormattedOrgId, "Data"), config: (0, _stryke_path_join_paths.joinPaths)(appData, windowsFormattedOrgId, "Config"), cache: (0, _stryke_path_join_paths.joinPaths)(localAppData, "Cache", orgId), log: (0, _stryke_path_join_paths.joinPaths)(localAppData, windowsFormattedOrgId, "Log"), temp: (0, _stryke_path_join_paths.joinPaths)(tmpdir, orgId) }; }; const linux = (orgId) => { const username = node_path.default.basename(homedir); return { data: (0, _stryke_path_join_paths.joinPaths)(process.env.XDG_DATA_HOME || (0, _stryke_path_join_paths.joinPaths)(homedir, ".local", "share"), orgId), config: (0, _stryke_path_join_paths.joinPaths)(process.env.XDG_CONFIG_HOME || (0, _stryke_path_join_paths.joinPaths)(homedir, ".config"), orgId), cache: (0, _stryke_path_join_paths.joinPaths)(process.env.XDG_CACHE_HOME || (0, _stryke_path_join_paths.joinPaths)(homedir, ".cache"), orgId), log: (0, _stryke_path_join_paths.joinPaths)(process.env.XDG_STATE_HOME || (0, _stryke_path_join_paths.joinPaths)(homedir, ".local", "state"), orgId), temp: process.env.DEVENV_RUNTIME || process.env.XDG_RUNTIME_DIR ? (0, _stryke_path_join_paths.joinPaths)(process.env.DEVENV_RUNTIME || process.env.XDG_RUNTIME_DIR, orgId) : (0, _stryke_path_join_paths.joinPaths)(tmpdir, username, orgId) }; }; /** * Get paths for storing things like data, config, logs, and cache in the current runtime environment. * * @remarks * On macOS, directories are generally created in `~/Library/Application Support/<name>`. * On Windows, directories are generally created in `%AppData%/<name>`. * On Linux, directories are generally created in `~/.config/<name>` - this is determined via the [XDG Base Directory spec](https://specifications.freedesktop.org/basedir-spec/latest/). * * If the `STORM_DATA_DIR`, `STORM_CONFIG_DIR`, `STORM_CACHE_DIR`, `STORM_LOG_DIR`, or `STORM_TEMP_DIR` environment variables are set, they will be used instead of the default paths. * * @param options - Parameters used to determine the specific paths for the current project/runtime environment * @returns An object containing the various paths for the runtime environment */ function getEnvPaths(options = {}) { let orgId = options.orgId || "storm-software"; if (!orgId) throw new Error("You need to provide an orgId to the `getEnvPaths` function"); if (options.suffix) orgId += `-${typeof options.suffix === "string" ? options.suffix : "nodejs"}`; let result = {}; if (process.platform === "darwin") result = macos(orgId); else if (process.platform === "win32") result = windows(orgId); else result = linux(orgId); if (process.env.STORM_DATA_DIR) result.data = process.env.STORM_DATA_DIR; else if (process.env.STORM_CONFIG_DIR) result.config = process.env.STORM_CONFIG_DIR; else if (process.env.STORM_CACHE_DIR) result.cache = process.env.STORM_CACHE_DIR; else if (process.env.STORM_LOG_DIR) result.log = process.env.STORM_LOG_DIR; else if (process.env.STORM_TEMP_DIR) result.temp = process.env.STORM_TEMP_DIR; if (options.workspaceRoot) { result.cache ??= (0, _stryke_path_join_paths.joinPaths)(options.workspaceRoot, "node_modules", ".cache", orgId); result.temp ??= (0, _stryke_path_join_paths.joinPaths)(options.workspaceRoot, "tmp", orgId); result.log ??= (0, _stryke_path_join_paths.joinPaths)(result.temp, "logs"); result.config ??= (0, _stryke_path_join_paths.joinPaths)(options.workspaceRoot, ".config", orgId); } return Object.keys(result).reduce((ret, key) => { if (result[key]) { const filePath = result[key]; ret[key] = options.appId && options.appId !== options.orgId && options.appId !== options.nestedDir ? (0, _stryke_path_join_paths.joinPaths)(filePath, options.appId) : filePath; if (options.nestedDir && options.nestedDir !== options.orgId && options.nestedDir !== options.appId) ret[key] = (0, _stryke_path_join_paths.joinPaths)(ret[key], options.nestedDir); } return ret; }, {}); } //#endregion exports.getEnvPaths = getEnvPaths;