feat: select all files or one folder for project restoration

This commit is contained in:
muena
2026-10-20 11:27:11 +02:00
parent 731c449c33
commit 41b935a145
3 changed files with 101 additions and 6 deletions

View File

@@ -0,0 +1,26 @@
import { dirname } from "node:path";
import type { ProjectFile } from "./velum-project";
export type RestorableFolder = { path: string; fileCount: number; textCount: number; documentCount: number };
export function listRestorableFolders(files: ProjectFile[]): RestorableFolder[] {
const folders = new Map<string, RestorableFolder>();
for (const file of files) {
let path = dirname(file.relPath);
while (path !== ".") {
const folder = folders.get(path) ?? { path, fileCount: 0, textCount: 0, documentCount: 0 };
folder.fileCount++;
if (file.kind === "text") folder.textCount++;
else folder.documentCount++;
folders.set(path, folder);
path = dirname(path);
}
}
return [...folders.values()].sort((a, b) => a.path.localeCompare(b.path, "de"));
}
export function selectRestorableFolder(files: ProjectFile[], folder: string, includeDocuments = false): Set<string> {
const prefix = `${folder}/`;
return new Set(files.filter((file) => file.relPath.startsWith(prefix)
&& (includeDocuments || file.kind === "text")).map((file) => file.relPath));
}