mirror of
https://github.com/usebruno/bruno.git
synced 2025-06-21 04:08:01 +02: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(
|
ipcMain.handle(
|
||||||
'renderer:create-collection',
|
'renderer:create-collection',
|
||||||
async (event, collectionName, collectionFolderName, collectionLocation) => {
|
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 {
|
try {
|
||||||
const dirPath = path.join(collectionLocation, collectionFolderName);
|
const dirPath = path.join(collectionLocation, collectionFolderName);
|
||||||
if (fs.existsSync(dirPath)) {
|
if (fs.existsSync(dirPath)) {
|
||||||
@ -80,42 +52,70 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
|||||||
throw new Error(`collection: invalid pathname - ${dir}`);
|
throw new Error(`collection: invalid pathname - ${dir}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create dir
|
|
||||||
await createDirectory(dirPath);
|
await createDirectory(dirPath);
|
||||||
|
|
||||||
const uid = generateUidBasedOnHash(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
|
mainWindow.webContents.send('main:collection-opened', dirPath, uid, brunoConfig);
|
||||||
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);
|
ipcMain.emit('main:collection-opened', mainWindow, dirPath, uid);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return Promise.reject(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
|
// rename collection
|
||||||
ipcMain.handle('renderer:rename-collection', async (event, newName, collectionPathname) => {
|
ipcMain.handle('renderer:rename-collection', async (event, newName, collectionPathname) => {
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user