From 379697a02da86cfe1a90fc725e9e2ee774d8f08a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Dathueyt?= Date: Wed, 22 Nov 2023 21:12:26 +0100 Subject: [PATCH] Remove missing argument & moving parseCollectionItems --- .../ReduxStore/slices/collections/actions.js | 2 +- packages/bruno-electron/src/ipc/collection.js | 38 +++++++++++++++++++ .../bruno-electron/src/utils/filesystem.js | 22 +---------- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js index bebabbb3c..dd9ff9455 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js @@ -329,7 +329,7 @@ export const cloneItem = (newName, itemUid, collectionUid) => (dispatch, getStat } const collectionPath = `${collection.pathname}${PATH_SEPARATOR}${newName}`; - ipcRenderer.invoke('renderer:clone-folder', newName, item, collectionPath).then(resolve).catch(reject); + ipcRenderer.invoke('renderer:clone-folder', item, collectionPath).then(resolve).catch(reject); return; } diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js index f3eb78457..529626387 100644 --- a/packages/bruno-electron/src/ipc/collection.js +++ b/packages/bruno-electron/src/ipc/collection.js @@ -336,6 +336,25 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection throw new Error(`collection: ${collectionPath} already exists`); } + // Recursive function to parse the collection items and create files/folders + const parseCollectionItems = (items = [], currentPath) => { + items.forEach((item) => { + if (['http-request', 'graphql-request'].includes(item.type)) { + const content = jsonToBru(item); + const filePath = path.join(currentPath, `${item.name}.bru`); + fs.writeFileSync(filePath, content); + } + if (item.type === 'folder') { + const folderPath = path.join(currentPath, item.name); + fs.mkdirSync(folderPath); + + if (item.items && item.items.length) { + parseCollectionItems(item.items, folderPath); + } + } + }); + }; + const parseEnvironments = (environments = [], collectionPath) => { const envDirPath = path.join(collectionPath, 'environments'); if (!fs.existsSync(envDirPath)) { @@ -379,6 +398,25 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection throw new Error(`folder: ${collectionPath} already exists`); } + // Recursive function to parse the folder and create files/folders + const parseCollectionItems = (items = [], currentPath) => { + items.forEach((item) => { + if (['http-request', 'graphql-request'].includes(item.type)) { + const content = jsonToBru(item); + const filePath = path.join(currentPath, `${item.name}.bru`); + fs.writeFileSync(filePath, content); + } + if (item.type === 'folder') { + const folderPath = path.join(currentPath, item.name); + fs.mkdirSync(folderPath); + + if (item.items && item.items.length) { + parseCollectionItems(item.items, folderPath); + } + } + }); + }; + await createDirectory(collectionPath); // create folder and files based on another folder diff --git a/packages/bruno-electron/src/utils/filesystem.js b/packages/bruno-electron/src/utils/filesystem.js index ab3a8d88d..4f3ea980b 100644 --- a/packages/bruno-electron/src/utils/filesystem.js +++ b/packages/bruno-electron/src/utils/filesystem.js @@ -134,25 +134,6 @@ const sanitizeDirectoryName = (name) => { return name.replace(/[<>:"/\\|?*\x00-\x1F]+/g, '-'); }; -// Recursive function to parse the folder and create files/folders -const parseCollectionItems = (items = [], currentPath) => { - items.forEach((item) => { - if (['http-request', 'graphql-request'].includes(item.type)) { - const content = jsonToBru(item); - const filePath = path.join(currentPath, `${item.name}.bru`); - fs.writeFileSync(filePath, content); - } - if (item.type === 'folder') { - const folderPath = path.join(currentPath, item.name); - fs.mkdirSync(folderPath); - - if (item.items && item.items.length) { - parseCollectionItems(item.items, folderPath); - } - } - }); -}; - module.exports = { isValidPathname, exists, @@ -169,6 +150,5 @@ module.exports = { chooseFileToSave, searchForFiles, searchForBruFiles, - sanitizeDirectoryName, - parseCollectionItems + sanitizeDirectoryName };