* 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 = {})
| 234 | * @returns A new CodeGraph instance |
| 235 | */ |
| 236 | static async init(projectRoot: string, options: InitOptions = {}): Promise<CodeGraph> { |
| 237 | await initGrammars(); |
| 238 | const resolvedRoot = path.resolve(projectRoot); |
| 239 | |
| 240 | // Check if already initialized |
| 241 | if (isInitialized(resolvedRoot)) { |
| 242 | throw new Error(`CodeGraph already initialized in ${resolvedRoot}`); |
| 243 | } |
| 244 | |
| 245 | // Create directory structure |
| 246 | createDirectory(resolvedRoot); |
| 247 | |
| 248 | // Initialize database |
| 249 | const dbPath = getDatabasePath(resolvedRoot); |
| 250 | const db = DatabaseConnection.initialize(dbPath); |
| 251 | const queries = new QueryBuilder(db.getDb()); |
| 252 | |
| 253 | const instance = new CodeGraph(db, queries, resolvedRoot); |
| 254 | |
| 255 | // Run initial indexing if requested |
| 256 | if (options.index) { |
| 257 | await instance.indexAll({ onProgress: options.onProgress }); |
| 258 | } |
| 259 | |
| 260 | return instance; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Initialize synchronously (without indexing) |