UNPKG

generator-begcode

Version:

Spring Boot + Angular/React/Vue in one handy generator

92 lines (91 loc) 3.19 kB
import createApplicationConfigurationFromObject, { createApplicationNamespaceConfigurationFromObject, } from './jdl-application-configuration-factory.js'; import JDLApplicationEntities from './jdl-application-entities.js'; import JDLOptions from './jdl-options.js'; export default class JDLApplication { config; namespaceConfigs; entityNames; options; constructor({ config = {}, entityNames = [], namespaceConfigs = {} } = {}) { this.config = createApplicationConfigurationFromObject(config); this.namespaceConfigs = createApplicationNamespaceConfigurationFromObject(namespaceConfigs); this.entityNames = new JDLApplicationEntities(entityNames); this.options = new JDLOptions(); } setConfigurationOption(option) { if (!option) { throw new Error('An option has to be passed to set an option.'); } this.config.setOption(option); } hasConfigurationOption(optionName) { return this.config.hasOption(optionName); } getConfigurationOptionValue(optionName) { if (!optionName) { throw new Error('An option name has to be passed to get a value.'); } if (!this.config.hasOption(optionName)) { return undefined; } const option = this.config.getOption(optionName); return option.getValue(); } forEachConfigurationOption(passedFunction) { this.config.forEachOption(passedFunction); } forEachNamespaceConfiguration(passedFunction) { for (const namespaceConfig of this.namespaceConfigs) { passedFunction(namespaceConfig); } } addEntityName(entityName) { if (!entityName) { throw new Error('An entity name has to be passed so as to be added to the application.'); } this.entityNames.add(entityName); } addEntityNames(entityNames = []) { this.entityNames.addEntityNames(entityNames); } getEntityNames() { return this.entityNames.toArray(); } hasEntityName(entityName) { if (!entityName) { return false; } return this.entityNames.has(entityName); } forEachEntityName(passedFunction) { this.entityNames.forEach(passedFunction); } addOption(jdlOption) { if (!jdlOption) { throw new Error("Can't add a nil option."); } this.options.addOption(jdlOption); } forEachOption(passedFunction) { if (!passedFunction) { return; } this.options.forEach(passedFunction); } getOptionQuantity() { return this.options.size(); } toString() { let stringifiedApplication = `application { ${this.config.toString(2)} ${this.namespaceConfigs.map(config => `${config.toString(2)}\n`).join()}`; if (this.entityNames.size() !== 0) { stringifiedApplication += `\n${this.entityNames.toString(2)}\n`; } if (this.options.size() !== 0) { stringifiedApplication += `\n${this.options.toString(2)}\n`; } stringifiedApplication += '}'; return stringifiedApplication; } }