sourcebot/packages/backend/src/zoekt.ts

37 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-11-01 17:51:14 +00:00
import { exec } from "child_process";
import { AppContext, GitRepository, LocalRepository } from "./types.js";
const ALWAYS_EXCLUDED_DIRS = ['.git', '.hg', '.svn'];
export const indexGitRepository = async (repo: GitRepository, ctx: AppContext) => {
return new Promise<{ stdout: string, stderr: string }>((resolve, reject) => {
exec(`zoekt-git-index -index ${ctx.indexPath} ${repo.path}`, (error, stdout, stderr) => {
if (error) {
reject(error);
return;
}
resolve({
stdout,
stderr
});
})
});
}
export const indexLocalRepository = async (repo: LocalRepository, ctx: AppContext, signal?: AbortSignal) => {
const excludedDirs = [...ALWAYS_EXCLUDED_DIRS, repo.excludedPaths];
const command = `zoekt-index -index ${ctx.indexPath} -ignore_dirs ${excludedDirs.join(',')} ${repo.path}`;
return new Promise<{ stdout: string, stderr: string }>((resolve, reject) => {
exec(command, { signal }, (error, stdout, stderr) => {
if (error) {
reject(error);
return;
}
resolve({
stdout,
stderr
});
})
});
}