refactor: duplicate project

This commit is contained in:
Carlos Valente
2024-06-26 22:30:15 +02:00
committed by Carlos Valente
parent ad0e821cc0
commit c9ef8d55c1
3 changed files with 48 additions and 29 deletions
@@ -66,9 +66,17 @@ export async function getProjectList(): Promise<ProjectFileListResponse> {
/**
* Duplicates an existing project file
*/
export async function duplicateProjectFile(existingProjectFile: string, newProjectFile: string) {
const projectFilePath = getPathToProject(existingProjectFile);
const duplicateProjectFilePath = getPathToProject(newProjectFile);
export async function duplicateProjectFile(originalFile: string, newFileName: string) {
if (!doesProjectExist(originalFile)) {
throw new Error('Project file not found');
}
if (doesProjectExist(newFileName)) {
throw new Error(`Project file with name ${newFileName} already exists`);
}
const projectFilePath = getPathToProject(originalFile);
const duplicateProjectFilePath = getPathToProject(newFileName);
return copyFile(projectFilePath, duplicateProjectFilePath);
}