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