Spaces:
Paused
Paused
Download cli/src/config/data-dir.ts from testfirela/paperclip-app: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/spaces/testfirela/paperclip-app/resolve/main/cli/src/config/data-dir.ts
- Command line
-
hf download hf://spaces/testfirela/paperclip-app/cli/src/config/data-dir.ts
-
curl -L -o data-dir.ts https://huggingface.co/spaces/testfirela/paperclip-app/resolve/main/cli/src/config/data-dir.ts
1.39 kB
| import path from "node:path"; | |
| import { | |
| expandHomePrefix, | |
| resolveDefaultConfigPath, | |
| resolveDefaultContextPath, | |
| resolvePaperclipInstanceId, | |
| } from "./home.js"; | |
| export interface DataDirOptionLike { | |
| dataDir?: string; | |
| config?: string; | |
| context?: string; | |
| instance?: string; | |
| } | |
| export interface DataDirCommandSupport { | |
| hasConfigOption?: boolean; | |
| hasContextOption?: boolean; | |
| } | |
| export function applyDataDirOverride( | |
| options: DataDirOptionLike, | |
| support: DataDirCommandSupport = {}, | |
| ): string | null { | |
| const rawDataDir = options.dataDir?.trim(); | |
| if (!rawDataDir) return null; | |
| const resolvedDataDir = path.resolve(expandHomePrefix(rawDataDir)); | |
| process.env.PAPERCLIP_HOME = resolvedDataDir; | |
| if (support.hasConfigOption) { | |
| const hasConfigOverride = Boolean(options.config?.trim()) || Boolean(process.env.PAPERCLIP_CONFIG?.trim()); | |
| if (!hasConfigOverride) { | |
| const instanceId = resolvePaperclipInstanceId(options.instance); | |
| process.env.PAPERCLIP_INSTANCE_ID = instanceId; | |
| process.env.PAPERCLIP_CONFIG = resolveDefaultConfigPath(instanceId); | |
| } | |
| } | |
| if (support.hasContextOption) { | |
| const hasContextOverride = Boolean(options.context?.trim()) || Boolean(process.env.PAPERCLIP_CONTEXT?.trim()); | |
| if (!hasContextOverride) { | |
| process.env.PAPERCLIP_CONTEXT = resolveDefaultContextPath(); | |
| } | |
| } | |
| return resolvedDataDir; | |
| } | |