@elsikora/setup-wizard
Version:
Setup Wizard - CLI scaffolding utility
50 lines (48 loc) • 1.77 kB
JavaScript
/**
* Mapper for configuration processing.
* Provides utility functions for transforming between configuration formats.
*/
const ConfigMapper = {
/**
* Converts a configuration object to initialization command properties.
* Extracts the enabled status from complex configuration objects.
* @param config - The configuration object
* @returns Command properties for initialization
*/
fromConfigToInitCommandProperties(config) {
const properties = {};
for (const key in config) {
if (Object.prototype.hasOwnProperty.call(config, key)) {
const value = config[key];
if (typeof value === "boolean") {
properties[key] = value;
}
else if (value && typeof value === "object" && "isEnabled" in value) {
properties[key] = value.isEnabled;
}
else {
properties[key] = !!value;
}
}
}
return properties;
},
/**
* Converts setup results to a configuration object.
* Combines wasInstalled flag with custom properties into a configuration.
* @param setupResults - Partial record of module setup results
* @returns Configuration object
*/
fromSetupResultsToConfig(setupResults) {
const config = {};
for (const key in setupResults) {
if (Object.prototype.hasOwnProperty.call(setupResults, key)) {
config[key] = { isEnabled: setupResults[key]?.wasInstalled, ...setupResults[key]?.customProperties };
}
}
return config;
},
};
export { ConfigMapper };
//# sourceMappingURL=config.mapper.js.map