* 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 = {})
| 277 | * @returns A new CodeGraph instance |
| 278 | */ |
| 279 | static async init(projectRoot: string, options: InitOptions = {}): Promise<CodeGraph> { |
| 280 | await initGrammars(); |
| 281 | const resolvedRoot = path.resolve(projectRoot); |
| 282 | |
| 283 | // Check if already initialized |
| 284 | if (isInitialized(resolvedRoot)) { |
| 285 | throw new Error(`CodeGraph already initialized in ${resolvedRoot}`); |
| 286 | } |
| 287 | |
| 288 | // Create directory structure |
| 289 | createDirectory(resolvedRoot); |
| 290 | |
| 291 | // Initialize database |
| 292 | const dbPath = getDatabasePath(resolvedRoot); |
| 293 | const db = DatabaseConnection.initialize(dbPath); |
| 294 | const queries = new QueryBuilder(db.getDb()); |
| 295 | |
| 296 | const instance = new CodeGraph(db, queries, resolvedRoot); |
| 297 | |
| 298 | // Run initial indexing if requested |
| 299 | if (options.index) { |
| 300 | await instance.indexAll({ onProgress: options.onProgress }); |
| 301 | } |
| 302 | |
| 303 | return instance; |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Initialize synchronously (without indexing) |
no test coverage detected