deth
Version:
Ethereum node focused on Developer Experience
21 lines (20 loc) • 677 B
JavaScript
import { getDirName } from '../fs/Path';
import { getConfigWithDefaults } from './config';
/**
* Loads config from a directory
* TODO:
* - support autofinding file based only on dir path
* - support at least JSON/JS/TS
* - typecheck config with iots
* - load BN values as strings in JSON
*/
export function loadConfig(fs, path) {
const exists = fs.fileExists(path);
if (!exists) {
throw new Error(`Couldn't load config at ${path}`);
}
// @todo parse / typecheck config. We can utilize io-ts for that
const config = fs.requireFile(path);
config.cwd = getDirName(path); // set cwd to config path
return getConfigWithDefaults(config);
}