mirror of
https://github.com/usebruno/bruno.git
synced 2025-02-16 09:50:17 +01:00
add collection and folder data to exported bruno collection json (#2560)
* add collection and folder data to exported bruno collection json * folder root data order
This commit is contained in:
parent
71353b0404
commit
2aa7d26a89
@ -380,6 +380,25 @@ export const transformCollectionToSaveToExportAsFile = (collection, options = {}
|
||||
}
|
||||
}
|
||||
|
||||
if (si?.root) {
|
||||
di.root = {
|
||||
request: {
|
||||
headers: si?.root?.request?.headers,
|
||||
script: si?.root?.request?.script,
|
||||
vars: si?.root?.request?.vars,
|
||||
tests: si?.root?.request?.tests
|
||||
},
|
||||
docs: si?.root?.request?.docs,
|
||||
meta: {
|
||||
name: si?.root?.meta?.name
|
||||
}
|
||||
};
|
||||
|
||||
di.root.request.auth = {
|
||||
mode: get(si.root.request, 'auth.mode', 'none')
|
||||
};
|
||||
}
|
||||
|
||||
if (si.type === 'js') {
|
||||
di.fileContent = si.raw;
|
||||
}
|
||||
@ -402,6 +421,7 @@ export const transformCollectionToSaveToExportAsFile = (collection, options = {}
|
||||
collectionToSave.items = [];
|
||||
collectionToSave.activeEnvironmentUid = collection.activeEnvironmentUid;
|
||||
collectionToSave.environments = collection.environments || [];
|
||||
collectionToSave.root = collection.root || {};
|
||||
|
||||
collectionToSave.brunoConfig = cloneDeep(collection?.brunoConfig);
|
||||
|
||||
|
@ -13,7 +13,6 @@ const collectionBruToJson = (bru) => {
|
||||
|
||||
const transformedJson = {
|
||||
request: {
|
||||
params: _.get(json, 'params', []),
|
||||
headers: _.get(json, 'headers', []),
|
||||
auth: _.get(json, 'auth', {}),
|
||||
script: _.get(json, 'script', {}),
|
||||
|
@ -14,7 +14,6 @@ const collectionBruToJson = (bru) => {
|
||||
|
||||
const transformedJson = {
|
||||
request: {
|
||||
params: _.get(json, 'params', []),
|
||||
headers: _.get(json, 'headers', []),
|
||||
auth: _.get(json, 'auth', {}),
|
||||
script: _.get(json, 'script', {}),
|
||||
@ -29,8 +28,7 @@ const collectionBruToJson = (bru) => {
|
||||
// in the future, all of this will be replaced by standard bru lang
|
||||
if (json.meta) {
|
||||
transformedJson.meta = {
|
||||
name: json.meta.name,
|
||||
seq: json.meta.seq
|
||||
name: json.meta.name
|
||||
};
|
||||
}
|
||||
|
||||
@ -43,7 +41,6 @@ const collectionBruToJson = (bru) => {
|
||||
const jsonToCollectionBru = (json) => {
|
||||
try {
|
||||
const collectionBruJson = {
|
||||
params: _.get(json, 'request.params', []),
|
||||
headers: _.get(json, 'request.headers', []),
|
||||
auth: _.get(json, 'request.auth', {}),
|
||||
script: {
|
||||
@ -61,10 +58,9 @@ const jsonToCollectionBru = (json) => {
|
||||
// add meta if it exists
|
||||
// this is only for folder bru file
|
||||
// in the future, all of this will be replaced by standard bru lang
|
||||
if (json.meta) {
|
||||
if (json?.meta) {
|
||||
collectionBruJson.meta = {
|
||||
name: json.meta.name,
|
||||
seq: json.meta.seq
|
||||
name: json.meta.name
|
||||
};
|
||||
}
|
||||
|
||||
@ -123,7 +119,6 @@ const bruToJson = (bru) => {
|
||||
}
|
||||
|
||||
const sequence = _.get(json, 'meta.seq');
|
||||
|
||||
const transformedJson = {
|
||||
type: requestType,
|
||||
name: _.get(json, 'meta.name'),
|
||||
@ -170,11 +165,12 @@ const jsonToBru = (json) => {
|
||||
type = 'http';
|
||||
}
|
||||
|
||||
const sequence = _.get(json, 'meta.seq');
|
||||
const bruJson = {
|
||||
meta: {
|
||||
name: _.get(json, 'name'),
|
||||
type: type,
|
||||
seq: _.get(json, 'seq')
|
||||
seq: !isNaN(sequence) ? Number(sequence) : 1
|
||||
},
|
||||
http: {
|
||||
method: _.lowerCase(_.get(json, 'request.method')),
|
||||
|
@ -439,6 +439,11 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
||||
const folderPath = path.join(currentPath, item.name);
|
||||
fs.mkdirSync(folderPath);
|
||||
|
||||
const folderBruFilePath = path.join(folderPath, 'folder.bru');
|
||||
const folderContent = jsonToCollectionBru(item.root);
|
||||
console.log('folder COntent', item.root, folderContent);
|
||||
fs.writeFileSync(folderBruFilePath, folderContent);
|
||||
|
||||
if (item.items && item.items.length) {
|
||||
parseCollectionItems(item.items, folderPath);
|
||||
}
|
||||
@ -488,6 +493,9 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
||||
// Write the Bruno configuration to a file
|
||||
await writeFile(path.join(collectionPath, 'bruno.json'), stringifiedBrunoConfig);
|
||||
|
||||
const collectionContent = jsonToCollectionBru(collection.root);
|
||||
await writeFile(path.join(collectionPath, 'collection.bru'), collectionContent);
|
||||
|
||||
mainWindow.webContents.send('main:collection-opened', collectionPath, uid, brunoConfig);
|
||||
ipcMain.emit('main:collection-opened', mainWindow, collectionPath, uid, brunoConfig);
|
||||
|
||||
|
@ -231,6 +231,39 @@ const requestSchema = Yup.object({
|
||||
.noUnknown(true)
|
||||
.strict();
|
||||
|
||||
const folderRootSchema = Yup.object({
|
||||
request: Yup.object({
|
||||
headers: Yup.array().of(keyValueSchema).required('headers are required'),
|
||||
auth: authSchema,
|
||||
script: Yup.object({
|
||||
req: Yup.string().nullable(),
|
||||
res: Yup.string().nullable()
|
||||
})
|
||||
.noUnknown(true)
|
||||
.strict(),
|
||||
vars: Yup.object({
|
||||
req: Yup.array().of(varsSchema).nullable(),
|
||||
res: Yup.array().of(varsSchema).nullable()
|
||||
})
|
||||
.noUnknown(true)
|
||||
.strict()
|
||||
.nullable(),
|
||||
tests: Yup.string().nullable()
|
||||
})
|
||||
.noUnknown(true)
|
||||
.strict()
|
||||
.nullable(),
|
||||
docs: Yup.string().nullable(),
|
||||
meta: Yup.object({
|
||||
name: Yup.string().nullable()
|
||||
})
|
||||
.noUnknown(true)
|
||||
.strict()
|
||||
.nullable()
|
||||
})
|
||||
.noUnknown(true)
|
||||
.nullable();
|
||||
|
||||
const itemSchema = Yup.object({
|
||||
uid: uidSchema,
|
||||
type: Yup.string().oneOf(['http-request', 'graphql-request', 'folder', 'js']).required('type is required'),
|
||||
@ -248,6 +281,11 @@ const itemSchema = Yup.object({
|
||||
// For all other types, the fileContent field is not required and can be null.
|
||||
otherwise: Yup.string().nullable()
|
||||
}),
|
||||
root: Yup.mixed().when('type', {
|
||||
is: 'folder',
|
||||
then: folderRootSchema,
|
||||
otherwise: Yup.mixed().nullable().notRequired()
|
||||
}),
|
||||
items: Yup.lazy(() => Yup.array().of(itemSchema)),
|
||||
filename: Yup.string().nullable(),
|
||||
pathname: Yup.string().nullable()
|
||||
@ -270,7 +308,8 @@ const collectionSchema = Yup.object({
|
||||
items: Yup.array()
|
||||
}),
|
||||
collectionVariables: Yup.object(),
|
||||
brunoConfig: Yup.object()
|
||||
brunoConfig: Yup.object(),
|
||||
root: folderRootSchema
|
||||
})
|
||||
.noUnknown(true)
|
||||
.strict();
|
||||
|
Loading…
Reference in New Issue
Block a user