MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / buildProject

Function buildProject

__tests__/explore-relevance-scoring.test.ts:36–49  ·  view source on GitHub ↗

Build + index a throwaway project from a `{ relPath: source }` map.

(
  prefix: string,
  files: Record<string, string>,
)

Source from the content-addressed store, hash-verified

34
35/** Build + index a throwaway project from a `{ relPath: source }` map. */
36async function buildProject(
37 prefix: string,
38 files: Record<string, string>,
39): Promise<{ dir: string; cg: CodeGraph; handler: ToolHandler }> {
40 const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
41 for (const [rel, body] of Object.entries(files)) {
42 const abs = path.join(dir, rel);
43 fs.mkdirSync(path.dirname(abs), { recursive: true });
44 fs.writeFileSync(abs, body.trimStart());
45 }
46 const cg = CodeGraph.initSync(dir);
47 await cg.indexAll();
48 return { dir, cg, handler: new ToolHandler(cg) };
49}
50
51const cleanup = (dir: string, cg?: CodeGraph) => {
52 if (cg) cg.destroy();

Calls 3

initSyncMethod · 0.80
joinMethod · 0.45
indexAllMethod · 0.45

Tested by

no test coverage detected