* 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 = {})
| 313 | * @returns A new CodeGraph instance |
| 314 | */ |
| 315 | static async init(projectRoot: string, options: InitOptions = {}): Promise<CodeGraph> { |
| 316 | await initGrammars(); |
| 317 | const resolvedRoot = path.resolve(projectRoot); |
| 318 | |
| 319 | // Check if already initialized |
| 320 | if (isInitialized(resolvedRoot)) { |
| 321 | throw new Error(`CodeGraph already initialized in ${resolvedRoot}`); |
| 322 | } |
| 323 | |
| 324 | // Create directory structure |
| 325 | createDirectory(resolvedRoot); |
| 326 | |
| 327 | // Initialize database |
| 328 | const dbPath = getDatabasePath(resolvedRoot); |
| 329 | const db = DatabaseConnection.initialize(dbPath); |
| 330 | const queries = new QueryBuilder(db.getDb()); |
| 331 | |
| 332 | const instance = new CodeGraph(db, queries, resolvedRoot); |
| 333 | |
| 334 | // Run initial indexing if requested |
| 335 | if (options.index) { |
| 336 | await instance.indexAll({ onProgress: options.onProgress }); |
| 337 | } |
| 338 | |
| 339 | return instance; |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * Initialize synchronously (without indexing) |
no test coverage detected