UNPKG

@magidoc/plugin-starter-variables

Version:

A shared library that contains common Magidoc starter environment variables keys.

45 lines (42 loc) 1.52 kB
import magidoc from '../variables/magidoc.js'; function toVariablesFile(options, supportedVariables) { return asVariablesString(buildEnv(options, supportedVariables)); } function asVariablesString(env) { return JSON.stringify(env); } function buildEnv(options, supportedVariables) { let newRecord = {}; const unsupportedVariables = []; Object.entries(options).forEach(([key, value]) => { const variable = supportedVariables.find((option) => option.name === key); if (!variable) { unsupportedVariables.push(key); return; } newRecord = { ...newRecord, ...variable.asEnv(value), }; }); if (unsupportedVariables.length > 0) { throw new UnsupportedVariablesError(`Options [${unsupportedVariables.toString()}] are not supported... Supported option names are [${supportedVariables .map((value) => value.name) .join(', ')}]`, unsupportedVariables); } insertDefaultVariables(newRecord); return newRecord; } function insertDefaultVariables(newRecord) { newRecord[magidoc.MAGIDOC_GENERATE.key] = 'true'; } class UnsupportedVariablesError extends Error { unsupportedVariables; constructor(message, unsupportedVariables) { super(message); this.unsupportedVariables = unsupportedVariables; this.name = 'UnsupportedVariableError'; } } export { UnsupportedVariablesError, toVariablesFile }; //# sourceMappingURL=envFileContent.js.map