Files
sprites/tools/build/config.ts
Christopher Monsanto 40bd3052f5 Make the deploy layer and tool I/O async
DeployCtx read/list/hash return promises (copy and write stay sync:
they only queue ops), the stamped copy helpers and buildfile deploy
blocks await them, ActionQueue materialization and packing use
fs/promises, and the CLI, config loaders, spritesheet writer, and
trim tool follow. Declaration-time globbing and the module-init data
reads stay sync: rules exist by the end of the import.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-21 01:13:15 -04:00

32 lines
862 B
TypeScript

import * as fs from 'node:fs/promises';
export function parseConfig(text: string): Map<string, string> {
let result = new Map<string, string>();
for (let line of text.split('\n')) {
line = line.trim();
if (line === '' || line.startsWith('#')) {
continue;
}
let eq = line.indexOf('=');
if (eq === -1) {
throw new Error(`Invalid config line: ${line}`);
}
result.set(line.slice(0, eq).trim(), line.slice(eq + 1).trim());
}
return result;
}
export async function loadConfig(path: string): Promise<Map<string, string>> {
let text;
try {
text = await fs.readFile(path, 'utf8');
} catch (err) {
if ((err as {code?: string}).code === 'ENOENT') {
return new Map();
}
throw err;
}
return parseConfig(text);
}