@sa-labs/fate-core
Version:
fate-core contains the base assumptions of the fate ecosystem as well as utilities for operating with fate.
37 lines (34 loc) • 1.26 kB
JavaScript
import rc from 'rc';
import merge from 'lodash/object/merge';
import isFunction from 'lodash/lang/isFunction';
import path from 'path';
import fs from 'fs';
import { camelize } from 'humps';
export function autoconfigure(conf, cb) {
const config = rc('fate', conf || {});
return fs.readdirSync(path.resolve(__dirname, '../'))
.filter((val) => {
// select all fate packages
return val.startsWith('fate-');
})
.map((pkg) => {
// configure constants, using any user-supplied values
const pkgConstants = require(`${pkg}/constants`);
if(!isFunction(pkgConstants)) {
throw new Error(`${pkg} has no constants function.
This is likely an error in ${pkg}, not in this project.`);
}
const camel = camelize(pkg);
return pkgConstants(config[camel] || {})
})
.reduce((acc, val) => {
// merge all separate constants objects
// there should be no conflicts between keys
return merge({}, acc, val);
})
}
export function manual(conf) {
const config = path.resolve(process.cwd(), '.faterc');
console.log('config', config);
return config;
}