@akiojin/claude-worktree
Version:
Interactive Git worktree manager for Claude Code with graphical branch selection
48 lines ⢠1.48 kB
JavaScript
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { readFile } from 'fs/promises';
export function getCurrentDirname() {
return path.dirname(fileURLToPath(import.meta.url));
}
export class AppError extends Error {
cause;
constructor(message, cause) {
super(message);
this.cause = cause;
this.name = 'AppError';
}
}
export function setupExitHandlers() {
// Handle Ctrl+C gracefully
process.on('SIGINT', () => {
console.log('\n\nš Goodbye!');
process.exit(0);
});
// Handle other termination signals
process.on('SIGTERM', () => {
console.log('\n\nš Goodbye!');
process.exit(0);
});
}
export function handleUserCancel(error) {
if (error && typeof error === 'object' && 'name' in error) {
if (error.name === 'ExitPromptError' || error.name === 'AbortPromptError') {
console.log('\n\nš Operation cancelled. Goodbye!');
process.exit(0);
}
}
throw error;
}
export async function getPackageVersion() {
try {
const currentDir = getCurrentDirname();
const packageJsonPath = path.resolve(currentDir, '..', 'package.json');
const packageJsonContent = await readFile(packageJsonPath, 'utf-8');
const packageJson = JSON.parse(packageJsonContent);
return packageJson.version || null;
}
catch {
return null;
}
}
//# sourceMappingURL=utils.js.map