| 45 | }; |
| 46 | |
| 47 | async function createTempMapProject(options: TempProjectOptions = {}): Promise<string> { |
| 48 | const tempParent = await fs.mkdtemp(path.join(os.tmpdir(), 'codebase-map-project-')); |
| 49 | const projectName = options.projectName ?? 'temp-map-project'; |
| 50 | const rootPath = path.join(tempParent, projectName); |
| 51 | const ctxDir = path.join(rootPath, CODEBASE_CONTEXT_DIRNAME); |
| 52 | |
| 53 | await fs.mkdir(ctxDir, { recursive: true }); |
| 54 | await fs.writeFile( |
| 55 | path.join(ctxDir, INTELLIGENCE_FILENAME), |
| 56 | JSON.stringify( |
| 57 | { |
| 58 | patterns: options.patterns ?? {}, |
| 59 | goldenFiles: options.goldenFiles ?? [] |
| 60 | }, |
| 61 | null, |
| 62 | 2 |
| 63 | ), |
| 64 | 'utf-8' |
| 65 | ); |
| 66 | await fs.writeFile( |
| 67 | path.join(ctxDir, KEYWORD_INDEX_FILENAME), |
| 68 | JSON.stringify({ chunks: options.chunks ?? [] }, null, 2), |
| 69 | 'utf-8' |
| 70 | ); |
| 71 | await fs.writeFile( |
| 72 | path.join(ctxDir, RELATIONSHIPS_FILENAME), |
| 73 | JSON.stringify({ graph: options.graph ?? {} }, null, 2), |
| 74 | 'utf-8' |
| 75 | ); |
| 76 | |
| 77 | return rootPath; |
| 78 | } |
| 79 | |
| 80 | async function removeTempMapProject(rootPath: string): Promise<void> { |
| 81 | await fs.rm(path.dirname(rootPath), { recursive: true, force: true }); |