feat: opencollection presets

This commit is contained in:
Anoop M D
2025-12-18 22:33:35 +05:30
parent c5827dfa72
commit aadbf8c33f
3 changed files with 31 additions and 1 deletions

1
.gitignore vendored
View File

@@ -53,6 +53,7 @@ bruno.iml
/blob-report/
# Development plan files
CLAUDE.md
*.plan.md
# packages dist

View File

@@ -26,6 +26,17 @@ const parseCollection = (ymlString: string): ParsedCollection => {
brunoConfig.ignore = oc.extensions.ignore;
}
// presets
if (oc.extensions?.presets) {
const presets = oc.extensions.presets as any;
if (presets.request) {
brunoConfig.presets = {
requestType: presets.request.type || [],
requestUrl: presets.request.url || []
};
}
}
// protobuf
if (oc.config?.protobuf) {
brunoConfig.protobuf = {

View File

@@ -46,14 +46,20 @@ const hasRequestScripts = (collectionRoot: any): boolean => {
|| (collectionRoot.request?.tests);
};
const hasPresets = (brunoConfig: any): boolean => {
return brunoConfig?.presets?.requestType?.length
|| brunoConfig?.presets?.requestUrl?.length;
};
const stringifyCollection = (collectionRoot: any, brunoConfig: any): string => {
console.log('brunoConfig', brunoConfig);
try {
const oc: OpenCollection = {};
oc.opencollection = '1.0.0';
oc.info = {
name: brunoConfig.name || 'Untitled Collection'
};
oc.opencollection = '1.0.0';
// collection config
if (hasCollectionConfig(brunoConfig)) {
@@ -179,6 +185,18 @@ const stringifyCollection = (collectionRoot: any, brunoConfig: any): string => {
});
oc.extensions.ignore = ignoreList;
}
if (hasPresets(brunoConfig)) {
const presetsRequest: any = {};
if (brunoConfig.presets.requestType?.length) {
presetsRequest.type = brunoConfig.presets.requestType;
}
if (brunoConfig.presets.requestUrl?.length) {
presetsRequest.url = brunoConfig.presets.requestUrl;
}
oc.extensions.presets = {
request: presetsRequest
} as any;
}
return stringifyYml(oc);
} catch (error) {