32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { existsSync, readFileSync } from 'fs';
|
|
import { join } from 'path';
|
|
import yaml from 'js-yaml';
|
|
import { logger } from '../observability/logger.js';
|
|
|
|
export interface WorkspacePreset {
|
|
env?: Record<string, string | number | boolean | null | undefined>;
|
|
routing?: Record<string, unknown>;
|
|
}
|
|
|
|
export async function loadWorkspacePreset(path = process.env['WORKSPACE_PRESET_PATH'] ?? join(process.cwd(), 'workspace.yaml')): Promise<WorkspacePreset | null> {
|
|
if (!existsSync(path)) return null;
|
|
try {
|
|
return yaml.load(readFileSync(path, 'utf-8')) as WorkspacePreset;
|
|
} catch (err) {
|
|
logger.warn({ err, path }, 'workspace preset parse failed');
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function applyWorkspaceDefaults(preset: WorkspacePreset): void {
|
|
for (const [key, value] of Object.entries(preset.env ?? {})) {
|
|
if (process.env[key] === undefined && value !== null && value !== undefined) {
|
|
process.env[key] = String(value);
|
|
}
|
|
}
|
|
}
|
|
|
|
export function getRoutingOverride(_taskType?: string): Record<string, unknown> | null {
|
|
return null;
|
|
}
|