geenee-spell
Version:
regenerates project code based upon settings and a template
38 lines (37 loc) • 1.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSpecElement = void 0;
const types_1 = require("../types");
const simpleValueEdit_1 = require("../editSpecs/simpleValueEdit");
const askQuestion_1 = require("./askQuestion");
async function createSpecElement(specsForTypeContents, session = {}) {
if (!specsForTypeContents)
return {};
const subTypes = Object.keys(specsForTypeContents);
let answers = {};
let i;
for (i = 0; i < subTypes.length; i++) {
const subType = subTypes[i];
const subTypeInfo = specsForTypeContents[subType];
const { type } = subTypeInfo;
if (type !== types_1.types.SET && type !== types_1.types.LIST) {
// eslint-disable-next-line require-atomic-updates
answers = await askQuestion_1.askQuestion(subTypeInfo, subType, answers, session);
}
}
Object.keys(answers).forEach(key => {
if (answers[key] === '')
delete answers[key];
});
subTypes.map((subType) => {
const subTypeInfo = specsForTypeContents[subType];
const type = subTypeInfo.type;
if (answers[subType] === '' || answers[subType] === undefined) {
delete answers[subType];
return;
}
answers[subType] = simpleValueEdit_1.simpleValueEdit(type, answers[subType]);
});
return answers;
}
exports.createSpecElement = createSpecElement;