bruno/packages/bruno-lang/v2/src/jsonToEnv.js

46 lines
876 B
JavaScript
Raw Normal View History

2023-02-05 14:36:48 +01:00
const _ = require('lodash');
const envToJson = (json) => {
const variables = _.get(json, 'variables', []);
const vars = variables
.filter((variable) => !variable.secret)
.map((variable) => {
const { name, value, enabled } = variable;
const prefix = enabled ? '' : '~';
return ` ${prefix}${name}: ${value}`;
});
2023-02-05 14:36:48 +01:00
const secretVars = variables
.filter((variable) => variable.secret)
.map((variable) => {
const { name, enabled } = variable;
const prefix = enabled ? '' : '~';
return ` ${prefix}${name}`;
});
if (!variables || !variables.length) {
2023-02-05 14:36:48 +01:00
return `vars {
}
`;
}
let output = '';
if (vars.length) {
output += `vars {
2023-02-05 14:36:48 +01:00
${vars.join('\n')}
}
`;
}
if (secretVars.length) {
output += `vars:secret [
${secretVars.join(',\n')}
]
`;
}
2023-02-05 14:36:48 +01:00
return output;
};
module.exports = envToJson;