mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Rename project
This commit is contained in:
3 files changed
+258
-5
No files matched your search
@@ -264,6 +264,50 @@ export class ProjectsManager {
|
||||
await this.deleteDirectory(projectPath);
|
||||
}
|
||||
|
||||
async renameProject(oldId: string, newId: string): Promise<Project> {
|
||||
// Validate that the old project exists
|
||||
const oldProject = await this.getProject(oldId);
|
||||
if (!oldProject) {
|
||||
throw new Error(`Project with ID "${oldId}" does not exist`);
|
||||
}
|
||||
|
||||
// Validate that the new ID doesn't already exist
|
||||
if (await this.projectExists(newId)) {
|
||||
throw new Error(`Project with ID "${newId}" already exists`);
|
||||
}
|
||||
|
||||
// Validate the new ID format (same rules as generateUniqueProjectId)
|
||||
const validatedNewId = newId
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/^-+|-+$/g, '');
|
||||
|
||||
if (validatedNewId !== newId) {
|
||||
throw new Error(`Project name must contain only lowercase letters, numbers, and hyphens`);
|
||||
}
|
||||
|
||||
if (!validatedNewId) {
|
||||
throw new Error(`Project name cannot be empty`);
|
||||
}
|
||||
|
||||
const oldPath = `${this.dir}/${oldId}`;
|
||||
const newPath = `${this.dir}/${newId}`;
|
||||
|
||||
// Rename the directory
|
||||
await this.fs.rename(oldPath, newPath);
|
||||
|
||||
// Return the updated project object
|
||||
const stats = await this.fs.stat(newPath);
|
||||
const timestamp = stats.mtimeMs ? new Date(stats.mtimeMs) : new Date();
|
||||
|
||||
return {
|
||||
id: newId,
|
||||
name: this.formatProjectName(newId),
|
||||
path: newPath,
|
||||
lastModified: timestamp,
|
||||
};
|
||||
}
|
||||
|
||||
private async deleteDirectory(dirPath: string): Promise<void> {
|
||||
const files = await this.fs.readdir(dirPath);
|
||||
|
||||
|
||||
Reference in new issue
Block a user