Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* Converts the passed config to normalized shape.
*
* @example
*
* normalizeConfig(["app", { name: "app2" }]) // [{ name: "app" }, { name: "app2" }]
*
* normalizeConfig({ templateFilename: 'index.ejs', apps: ["app"]})
* // [{ name: "app", templateFilename: 'index.ejs', }]
*
* @see tests
*/
const normalizeConfig = R.cond([
[R_.isArray, fromArrayConfig_],
[R_.isObject, fromObjectConfig_],
[R.T, R_.noop],
]);
const getAppPattern_ = R.path(['workspaces', 'appPattern']);
const setAppsIfMissing_ = config => {
const uniRepoDirs = () => utilsFs.readDirs(DEFAULT_UNI_REPO_APP_DIR);
const appsPattern = getAppPattern_(config) || getAppPattern_(DEFAULT_UNION_CONFIG);
const appDirs = isMonoRepo ? utilsFs.readAllAppsFromWorkspaces(appsPattern) : uniRepoDirs();
return R.cond([
[nilOrEmpty_, R.always(appDirs)],
[R_.isArray, R.identity],
[c => !c.apps, c => R.mergeDeepRight(c, { apps: appDirs })],
[R.T, R.identity],
])(config);
};
const getUnionConfig = () =>
R.pipe(
R.ifElse(fs.existsSync, x => require(x), R_.noop),
whenIsFunction_(R.applyTo(cli)),
setAppsIfMissing_,
normalizeConfig,
R.tap(validateConfig_),
extendConfigs
)(UNION_CONFIG_PATH);