forked from r.muellner/velum-raycast
feat: allow project files to be excluded before analysis
This commit is contained in:
@@ -91,6 +91,46 @@ export function entityTypesPath(projectPath: string, support = environment.suppo
|
||||
return join(projectDataRoot(projectPath, support), "entity-types.json");
|
||||
}
|
||||
|
||||
export function fileExclusionsPath(projectPath: string, support = environment.supportPath): string {
|
||||
return join(projectDataRoot(projectPath, support), "excluded-files.json");
|
||||
}
|
||||
|
||||
function checkedFileExclusions(value: unknown): string[] {
|
||||
if (!Array.isArray(value) || value.some((path) => typeof path !== "string")) {
|
||||
throw new Error("Ungültige Dateiauswahl für dieses Projekt.");
|
||||
}
|
||||
try { return [...new Set(value.map((path: string) => safeRelativePath(path)))]; }
|
||||
catch { throw new Error("Ungültiger Dateipfad in der Projektauswahl."); }
|
||||
}
|
||||
|
||||
export async function loadProjectFileExclusions(projectPath: string, support?: string): Promise<string[]> {
|
||||
try {
|
||||
return checkedFileExclusions(JSON.parse(await fs.readFile(fileExclusionsPath(projectPath, support), "utf8")));
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code === "ENOENT") return [];
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function saveProjectFileExclusions(projectPath: string, paths: string[], support?: string): Promise<void> {
|
||||
const unique = checkedFileExclusions(paths);
|
||||
const path = fileExclusionsPath(projectPath, support);
|
||||
await fs.mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
||||
const temp = `${path}.${randomUUID()}.tmp`;
|
||||
try {
|
||||
await fs.writeFile(temp, JSON.stringify(unique), { encoding: "utf8", mode: 0o600 });
|
||||
await fs.rename(temp, path);
|
||||
} catch (error) {
|
||||
await fs.rm(temp, { force: true });
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export function withoutExcludedProjectFiles(files: ProjectFile[], excluded: readonly string[]): ProjectFile[] {
|
||||
const paths = new Set(excluded);
|
||||
return files.filter((file) => !paths.has(file.relPath));
|
||||
}
|
||||
|
||||
export async function loadProjectEntityTypes(projectPath: string, support?: string): Promise<EntityType[] | null> {
|
||||
try {
|
||||
const value = JSON.parse(await fs.readFile(entityTypesPath(projectPath, support), "utf8")) as unknown;
|
||||
|
||||
Reference in New Issue
Block a user