UNPKG

generator-begcode

Version:

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

64 lines (63 loc) 2.09 kB
import { isEqual } from 'lodash-es'; import { applicationOptions, deploymentOptions } from '../built-in-options/index.js'; import { merge } from '../utils/object-utils.js'; import { join } from '../utils/set-utils.js'; const { Options } = deploymentOptions; const arrayTypes = ['appsFolders', 'clusteredDbApps']; export default class JDLDeployment { deploymentType; appsFolders; directoryPath; gatewayType; kubernetesServiceType; istio; ingressDomain; ingressType; storageType; monitoring; clusteredDbApps; constructor(args) { if (!args?.deploymentType) { throw new Error('The deploymentType is mandatory to create a deployment.'); } const merged = merge(defaults(args.deploymentType), args); Object.entries(merged).forEach(([key, option]) => { if (Array.isArray(option) && arrayTypes.includes(key)) { this[key] = new Set(option); } else if (key === applicationOptions.OptionNames.SERVICE_DISCOVERY_TYPE && option === Options.serviceDiscoveryType.no) { this[key] = 'no'; } else { this[key] = option; } }); } toString() { return stringifyConfig(this); } } function stringifyConfig(applicationConfig) { let config = 'deployment {'; Object.entries(applicationConfig).forEach(([option, value]) => { if (!isEqual(defaults(applicationConfig.deploymentType)[option], value) || option === 'deploymentType') { config = `${config}\n ${option}${stringifyOptionValue(option, value)}`; } }); return `${config}\n }`; } function stringifyOptionValue(name, value) { if (arrayTypes.includes(name)) { if (value.size === 0) { return ' []'; } return ` [${join(value, ', ')}]`; } if (value === null || value === undefined) { return ''; } return ` ${value}`; } function defaults(deploymentType) { return deploymentOptions.Options.defaults(deploymentType); }