initialize
codebolt.hook.initialize(projectPath: string): Promise<HookInitializeResponse>
Initializes the hook manager for a project directory, setting up the infrastructure for managing hooks.
Parameters
projectPath(string): The absolute path to the project directory where hooks will be managed.
Returns
Promise<[HookInitializeResponse](/docs/reference/type-reference/codeboltjs/interfaces/HookInitializeResponse)>: A promise that resolves when the hook manager is initialized.
Response Structure
interface HookInitializeResponse {
success: boolean;
message?: string;
projectPath: string;
initializedAt: string;
}
Examples
Example 1: Initialize Hook Manager
import codebolt from '@codebolt/codeboltjs';
await codebolt.waitForReady();
const result = await codebolt.hook.initialize('/Users/developer/my-project');
if (result.success) {
console.log('Hook manager initialized');
console.log('Project:', result.projectPath);
console.log('Initialized at:', result.initializedAt);
}
Example 2: Initialize with Error Handling
async function initializeHooks(projectPath: string) {
try {
const result = await codebolt.hook.initialize(projectPath);
if (result.success) {
console.log('Hook system ready for project');
return true;
} else {
console.error('Initialization failed');
return false;
}
} catch (error) {
console.error('Failed to initialize hooks:', error.message);
return false;
}
}
// Usage
const success = await initializeHooks('/path/to/project');
Common Use Cases
- Project Setup: Initialize hooks when starting a new project
- CI/CD Setup: Prepare hook system for automated workflows
- Development Environment: Set up local development automation
Notes
- Must be called before creating or managing hooks
- Creates necessary directory structure and configuration
- Should be called once per project
- Project path must be absolute