{
>
New Folder
+
{
+ menuDropdownTippyRef.current.hide();
+ setShowCloneCollectionModalOpen(true);
+ }}
+ >
+ Clone
+
{
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 c7bb98378..9c799c234 100644
--- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
+++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
@@ -939,7 +939,17 @@ export const createCollection = (collectionName, collectionFolderName, collectio
.catch(reject);
});
};
+export const cloneCollection = (collectionName, collectionFolderName, collectionLocation, perviousPath) => () => {
+ const { ipcRenderer } = window;
+ return ipcRenderer.invoke(
+ 'renderer:clone-collection',
+ collectionName,
+ collectionFolderName,
+ collectionLocation,
+ perviousPath
+ );
+};
export const openCollection = () => () => {
return new Promise((resolve, reject) => {
const { ipcRenderer } = window;
diff --git a/packages/bruno-electron/src/ipc/collection.js b/packages/bruno-electron/src/ipc/collection.js
index ba19cfaf2..76bb661d8 100644
--- a/packages/bruno-electron/src/ipc/collection.js
+++ b/packages/bruno-electron/src/ipc/collection.js
@@ -70,7 +70,52 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
}
}
);
+ // clone collection
+ ipcMain.handle(
+ 'renderer:clone-collection',
+ async (event, collectionName, collectionFolderName, collectionLocation, previousPath) => {
+ const dirPath = path.join(collectionLocation, collectionFolderName);
+ if (fs.existsSync(dirPath)) {
+ throw new Error(`collection: ${dirPath} already exists`);
+ }
+ if (!isValidPathname(dirPath)) {
+ throw new Error(`collection: invalid pathname - ${dir}`);
+ }
+
+ // create dir
+ await createDirectory(dirPath);
+ const uid = generateUidBasedOnHash(dirPath);
+
+ // open the bruno.json of previousPath
+ const brunoJsonFilePath = path.join(previousPath, 'bruno.json');
+ const content = fs.readFileSync(brunoJsonFilePath, 'utf8');
+
+ //Change new name of collection
+ let json = JSON.parse(content);
+ json.name = collectionName;
+ const cont = await stringifyJson(json);
+
+ // write the bruno.json to new dir
+ await writeFile(path.join(dirPath, 'bruno.json'), cont);
+
+ // Now copy all the files with extension name .bru along with there dir
+ const files = searchForBruFiles(previousPath);
+
+ for (const sourceFilePath of files) {
+ const relativePath = path.relative(previousPath, sourceFilePath);
+ const newFilePath = path.join(dirPath, relativePath);
+
+ // handle dir of files
+ fs.mkdirSync(path.dirname(newFilePath), { recursive: true });
+ // copy each files
+ fs.copyFileSync(sourceFilePath, newFilePath);
+ }
+
+ mainWindow.webContents.send('main:collection-opened', dirPath, uid, json);
+ ipcMain.emit('main:collection-opened', mainWindow, dirPath, uid);
+ }
+ );
// rename collection
ipcMain.handle('renderer:rename-collection', async (event, newName, collectionPathname) => {
try {