jatg
Version:
Just Another Template Generator
24 lines • 819 B
JavaScript
import { readFile } from 'node:fs/promises';
import { resolve } from 'node:path';
import { JatgError } from '../models/jatg-error.js';
export async function loadConfig(basePath, path) {
try {
const rawConfig = await readFile(resolve(basePath, path), 'utf8');
const config = JSON.parse(rawConfig);
return {
templates: [],
...config,
};
}
catch (error) {
if (error instanceof SyntaxError) {
throw new JatgError(`The config file ${path} has invalid JSON: ${error.message}`);
}
const code = error.code;
if (code === 'ENOENT') {
throw new JatgError(`The config file ${path} does not exist. Create one with "jatg --init"`);
}
throw error;
}
}
//# sourceMappingURL=loadConfig.js.map