Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions apps/studio/electron/main/code/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { generateCode } from './diff/helpers';
import { formatContent, readFile, writeFile } from './files';
import { parseJsxCodeBlock } from './helpers';
import { IDE } from '/common/ide';
import fs from 'fs';
import path from 'path';

export async function readCodeBlock(
templateNode: TemplateNode,
Expand Down Expand Up @@ -99,3 +101,15 @@ export function pickDirectory() {
properties: ['openDirectory', 'createDirectory'],
});
}

export async function moveFolder(source: string, destination: string) {
try {
await fs.mkdir(destination, { recursive: true }, err => { throw err });
await fs.cp(source, destination, { recursive: true }, err => { throw err });

return { success: true, message: 'Folder moved successfully' };
} catch (error: any) {
console.error('Move failed:', error);
return { success: false, message: error.message };
}
}
9 changes: 7 additions & 2 deletions apps/studio/electron/main/events/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { CodeDiff, CodeDiffRequest } from '@onlook/models/code';
import { MainChannels } from '@onlook/models/constants';
import type { TemplateNode } from '@onlook/models/element';
import { ipcMain } from 'electron';
import { openFileInIde, openInIde, pickDirectory, readCodeBlock, writeCode } from '../code/';
import { moveFolder, openFileInIde, openInIde, pickDirectory, readCodeBlock, writeCode } from '../code/';
import { getTemplateNodeClass } from '../code/classes';
import { extractComponentsFromDirectory } from '../code/components';
import { getCodeDiffs } from '../code/diff';
Expand Down Expand Up @@ -99,10 +99,15 @@ export function listenForCodeMessages() {
if (result.canceled) {
return null;
}

return result.filePaths.at(0) ?? null;
});

ipcMain.handle(MainChannels.MOVE_PROJECT_FOLDER, async (e: Electron.IpcMainInvokeEvent, args) => {
console.log("This is the path values from the frontend : ", args);
const { currentPath, newPath } = args;
return moveFolder(currentPath, newPath)
})

ipcMain.handle(MainChannels.GET_COMPONENTS, async (_, args) => {
if (typeof args !== 'string') {
throw new Error('`args` must be a string');
Expand Down
Loading