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