mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-25 17:33:28 +01:00
removed try catch from clone collection
This commit is contained in:
parent
93661bd0d2
commit
cada4f201a
@ -42,34 +42,6 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
||||
ipcMain.handle(
|
||||
'renderer:create-collection',
|
||||
async (event, collectionName, collectionFolderName, collectionLocation) => {
|
||||
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}`);
|
||||
}
|
||||
|
||||
await createDirectory(dirPath);
|
||||
|
||||
const uid = generateUidBasedOnHash(dirPath);
|
||||
const brunoConfig = {
|
||||
version: '1',
|
||||
name: collectionName,
|
||||
type: 'collection'
|
||||
};
|
||||
const content = await stringifyJson(brunoConfig);
|
||||
await writeFile(path.join(dirPath, 'bruno.json'), content);
|
||||
|
||||
mainWindow.webContents.send('main:collection-opened', dirPath, uid, brunoConfig);
|
||||
ipcMain.emit('main:collection-opened', mainWindow, dirPath, uid);
|
||||
}
|
||||
);
|
||||
// clone collection
|
||||
ipcMain.handle(
|
||||
'renderer:clone-collection',
|
||||
async (event, collectionName, collectionFolderName, collectionLocation, previousPath) => {
|
||||
try {
|
||||
const dirPath = path.join(collectionLocation, collectionFolderName);
|
||||
if (fs.existsSync(dirPath)) {
|
||||
@ -80,42 +52,70 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
||||
throw new Error(`collection: invalid pathname - ${dir}`);
|
||||
}
|
||||
|
||||
// create dir
|
||||
await createDirectory(dirPath);
|
||||
|
||||
const uid = generateUidBasedOnHash(dirPath);
|
||||
const brunoConfig = {
|
||||
version: '1',
|
||||
name: collectionName,
|
||||
type: 'collection'
|
||||
};
|
||||
const content = await stringifyJson(brunoConfig);
|
||||
await writeFile(path.join(dirPath, 'bruno.json'), content);
|
||||
|
||||
// open the bruno.json of previousPath
|
||||
const brunoJsonFilePath = path.join(previousPath, 'bruno.json');
|
||||
const content = fs.readFileSync(brunoJsonFilePath, 'utf8');
|
||||
|
||||
//Chnage 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);
|
||||
mainWindow.webContents.send('main:collection-opened', dirPath, uid, brunoConfig);
|
||||
ipcMain.emit('main:collection-opened', mainWindow, dirPath, uid);
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
}
|
||||
);
|
||||
// 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');
|
||||
|
||||
//Chnage 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user