mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-01 16:44:16 +00:00
* chore: basic annotation support * chore: string and escape cases * feat: add basic multiline support * fix: simplify dedentation logic in annotation multiline text block * chore: fix asserts * feat: add annotation support to env and collection * feat: enhance annotation parsing with support for quoted arguments and nested parentheses * refactor: feedback, remove inline annotations * feat: move serializeAnnotations function to utils and update imports
55 lines
1.1 KiB
JavaScript
55 lines
1.1 KiB
JavaScript
const _ = require('lodash');
|
|
const { getValueString, indentString, serializeAnnotations } = require('./utils');
|
|
|
|
const envToJson = (json) => {
|
|
const variables = _.get(json, 'variables', []);
|
|
const color = _.get(json, 'color', null);
|
|
|
|
const vars = variables
|
|
.filter((variable) => !variable.secret)
|
|
.map((variable) => {
|
|
const { name, value, enabled, annotations } = variable;
|
|
const prefix = enabled ? '' : '~';
|
|
|
|
return indentString(`${serializeAnnotations(annotations)}${prefix}${name}: ${getValueString(value)}`);
|
|
});
|
|
|
|
const secretVars = variables
|
|
.filter((variable) => variable.secret)
|
|
.map((variable) => {
|
|
const { name, enabled } = variable;
|
|
const prefix = enabled ? '' : '~';
|
|
return indentString(`${prefix}${name}`);
|
|
});
|
|
|
|
let output = '';
|
|
|
|
if (!variables || !variables.length) {
|
|
output += `vars {
|
|
}
|
|
`;
|
|
}
|
|
|
|
if (vars.length) {
|
|
output += `vars {
|
|
${vars.join('\n')}
|
|
}
|
|
`;
|
|
}
|
|
|
|
if (secretVars.length) {
|
|
output += `vars:secret [
|
|
${secretVars.join(',\n')}
|
|
]
|
|
`;
|
|
}
|
|
if (color) {
|
|
output += `color: ${color}
|
|
`;
|
|
}
|
|
|
|
return output;
|
|
};
|
|
|
|
module.exports = envToJson;
|