* Initialize a new CodeGraph project * * Creates the .CodeGraph directory, database, and configuration. * * @param projectRoot - Path to the project root directory * @param options - Initialization options * @returns A new CodeGraph instance
(projectRoot: string, options: InitOptions = {})
| 414 | * @returns A new CodeGraph instance |
| 415 | */ |
| 416 | static async init(projectRoot: string, options: InitOptions = {}): Promise<CodeGraph> { |
| 417 | await initGrammars(); |
| 418 | const resolvedRoot = path.resolve(projectRoot); |
| 419 | |
| 420 | // Check if already initialized |
| 421 | if (isInitialized(resolvedRoot)) { |
| 422 | throw new Error(`CodeGraph already initialized in ${resolvedRoot}`); |
| 423 | } |
| 424 | |
| 425 | // Create directory structure |
| 426 | createDirectory(resolvedRoot); |
| 427 | |
| 428 | // Initialize database |
| 429 | const dbPath = getDatabasePath(resolvedRoot); |
| 430 | const db = DatabaseConnection.initialize(dbPath); |
| 431 | const queries = new QueryBuilder(db.getDb()); |
| 432 | |
| 433 | const instance = new CodeGraph(db, queries, resolvedRoot); |
| 434 | |
| 435 | // Run initial indexing if requested |
| 436 | if (options.index) { |
| 437 | await instance.indexAll({ onProgress: options.onProgress }); |
| 438 | } |
| 439 | |
| 440 | return instance; |
| 441 | } |
| 442 | |
| 443 | /** |
| 444 | * Initialize synchronously (without indexing) |
no test coverage detected