@zohodesk/client_build_tool
Version:
A CLI tool to build web applications and client libraries
34 lines (25 loc) • 975 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.applyValuesToSchema = applyValuesToSchema;
var _isObject = require("./isObject");
var _isValid = require("./isValid");
function applyValuesToSchema(schemas, customOptions, processEnv) {
const output = {};
function decideValue(schema, key, customOptions) {
const specificSchema = schema[key];
const correspondingValue = customOptions && customOptions[key];
if ((0, _isObject.isObject)(specificSchema)) {
if (typeof specificSchema.cli === 'string') {
return processEnv[specificSchema.cli] ?? (0, _isValid.isValid)(correspondingValue, specificSchema.value);
}
return applyValuesToSchema(specificSchema, correspondingValue, processEnv);
}
return (0, _isValid.isValid)(correspondingValue, specificSchema);
}
Object.keys(schemas).forEach(key => {
output[key] = decideValue(schemas, key, customOptions);
});
return output;
}