in src/core/utils/cli-config.ts [50:114]
export async function getConfigFileOptions(configName: string | undefined, configFilePath: string): Promise<SWACLIConfig> {
logger.silly(`Getting config file options from "${configFilePath}"...`);
let configFilePathResolved = path.resolve(configFilePath);
if (!swaCliConfigFileExists(configFilePathResolved)) {
logger.silly(`Config file does not exist at "${configFilePath}"`);
// Handle the case when the user runs the command outside the project path
if (!configName || !swaCliConfigFileExists(path.resolve(configName, swaCliConfigFilename))) {
return {};
}
logger.warn(
`WARNING: Config file does not exist at "${configFilePath}", but can be detected at "${path.join(
configName,
swaCliConfigFilename
)}". Do you mean "swa --config ${path.join(configName, swaCliConfigFilename)} <command> ${configName} [options]"?`
);
configFilePathResolved = path.resolve(configName, swaCliConfigFilename);
}
const cliConfig = await tryParseSwaCliConfig(configFilePathResolved);
if (!cliConfig.configurations) {
logger.warn(`${swaCliConfigFilename} is missing the "configurations" property. No options will be loaded.`);
return {};
}
// Use configuration root path as the outputLocation
const configDir = path.dirname(configFilePathResolved);
process.chdir(configDir);
logger.silly(`Changed directory to ${configDir}`);
if (!configName) {
const hasMultipleConfig = Object.entries(cliConfig.configurations).length > 1;
if (hasMultipleConfig) {
// Show as a log not warning because the user may want to use the default config
logger.log(`Multiple configurations found in "${swaCliConfigFilename}", but none was specified.`);
logger.log(`Specify which configuration to use with "swa <command> --config-name <configName>"\n`);
}
const [configName, config] = Object.entries(cliConfig.configurations)[0];
printConfigMsg(configName, configFilePathResolved);
currentSwaCliConfigFromFile = {
name: configName,
filePath: configFilePathResolved,
config,
};
return { ...config };
}
const config = cliConfig.configurations?.[configName];
if (config) {
logger.silly(`Found configuration "${configName}" in "${swaCliConfigFilename}"`);
printConfigMsg(configName, configFilePath);
currentSwaCliConfigFromFile = {
name: configName,
filePath: configFilePath,
config,
};
return { ...config };
}
return {};
}