mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-22 08:38:08 +02:00
Initial open-source release
This commit is contained in:
commit
1a42152e6f
1199 changed files with 257054 additions and 0 deletions
36
packages/context/src/core/config-reference.ts
Normal file
36
packages/context/src/core/config-reference.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { readFileSync } from 'node:fs';
|
||||
import { homedir } from 'node:os';
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
export function resolveKloHomePath(path: string): string {
|
||||
if (path === '~') {
|
||||
return homedir();
|
||||
}
|
||||
|
||||
if (path.startsWith('~/')) {
|
||||
return resolve(homedir(), path.slice(2));
|
||||
}
|
||||
|
||||
return resolve(path);
|
||||
}
|
||||
|
||||
export function resolveKloConfigReference(value: string | undefined, env: NodeJS.ProcessEnv): string | undefined {
|
||||
if (!value) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (value.startsWith('env:')) {
|
||||
const envName = value.slice('env:'.length).trim();
|
||||
const envValue = env[envName];
|
||||
return envValue && envValue.trim().length > 0 ? envValue.trim() : undefined;
|
||||
}
|
||||
|
||||
if (value.startsWith('file:')) {
|
||||
const filePath = resolveKloHomePath(value.slice('file:'.length).trim());
|
||||
const fileValue = readFileSync(filePath, 'utf8').trim();
|
||||
return fileValue.length > 0 ? fileValue : undefined;
|
||||
}
|
||||
|
||||
const trimmed = value.trim();
|
||||
return trimmed.length > 0 ? trimmed : undefined;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue