Files
bruno/packages/bruno-lang/v2/src/jsonToEnv.js
Sid 652f3cc3fe feat: basic annotation syntax support for lang (#7609)
* 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
2026-04-01 16:04:34 +05:30

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;