mirror of
https://github.com/smogon/sprites.git
synced 2026-12-05 07:00:37 -06:00
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>
32 lines
862 B
TypeScript
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);
|
|
}
|