/**
 * Theme descriptor loader — reads a JSON theme file and validates its structure.
 *
 * A theme descriptor carries the theme's name, source path, and raw JSON data.
 * Validation ensures the file parses as JSON and contains a non-empty "name" field.
 */
import { readFileSync } from 'node:fs';
/** Parse a JSON theme file and return a validated ThemeDescriptor. Throws on invalid JSON or missing name. */
export function loadThemeDescriptorFromPath(themePath) {
    const content = readFileSync(themePath, 'utf-8');
    let parsed;
    try {
        parsed = JSON.parse(content);
    }
    catch (error) {
        throw new Error(`Failed to parse theme ${themePath}: ${error}`);
    }
    if (typeof parsed !== 'object' ||
        parsed === null ||
        !('name' in parsed) ||
        typeof parsed.name !== 'string' ||
        parsed.name.trim().length === 0) {
        throw new Error(`Theme ${themePath} is missing a valid "name" field`);
    }
    return {
        name: parsed.name,
        sourcePath: themePath,
        data: parsed
    };
}
//# sourceMappingURL=theme-descriptor.js.map