vibehub-cli
Version:
VibeHub CLI - Command line interface for VibeHub
113 lines ⢠4.5 kB
JavaScript
import { Command } from 'commander';
import chalk from 'chalk';
import inquirer from 'inquirer';
import path from 'path';
import { fileURLToPath } from 'url';
import { VibeHubManager } from '../lib/vibehub-manager.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export const initCommand = new Command('init')
.description('Initialize a new VibeHub repository')
.option('-f, --force', 'Force initialization even if .vibehub already exists')
.option('-q, --quiet', 'Suppress output')
.action(async (options) => {
const cwd = process.cwd();
const vibehubManager = new VibeHubManager(cwd);
try {
// Check if already initialized
if (await vibehubManager.isInitialized() && !options.force) {
if (!options.quiet) {
console.log(chalk.yellow('VibeHub repository already exists in this directory.'));
console.log(chalk.yellow('Use --force to reinitialize.'));
}
return;
}
// Interactive setup
if (!options.quiet) {
console.log(chalk.blue('š Initializing VibeHub repository...\n'));
}
let answers;
if (options.quiet) {
// Use default values for non-interactive mode
answers = {
projectName: path.basename(cwd),
description: '',
author: process.env.USER_EMAIL || 'user@example.com',
enableAutoSync: true,
createGitignore: true
};
}
else {
answers = await inquirer.prompt([
{
type: 'input',
name: 'projectName',
message: 'Project name:',
default: path.basename(cwd),
validate: (input) => {
if (!input.trim()) {
return 'Project name cannot be empty';
}
return true;
}
},
{
type: 'input',
name: 'description',
message: 'Project description (optional):',
default: ''
},
{
type: 'input',
name: 'author',
message: 'Author email:',
default: process.env.USER_EMAIL || '',
validate: (input) => {
if (!input.trim()) {
return 'Author email is required';
}
if (!input.includes('@')) {
return 'Please enter a valid email address';
}
return true;
}
},
{
type: 'confirm',
name: 'enableAutoSync',
message: 'Enable automatic sync with VibeHub cloud?',
default: true
},
{
type: 'confirm',
name: 'createGitignore',
message: 'Add .vibehub to .gitignore?',
default: true
}
]);
}
// Initialize the repository
await vibehubManager.init({
projectName: answers.projectName,
description: answers.description,
author: answers.author,
enableAutoSync: answers.enableAutoSync
});
// Update .gitignore if requested
if (answers.createGitignore) {
await vibehubManager.updateGitignore();
}
if (!options.quiet) {
console.log(chalk.green('\nā
VibeHub repository initialized successfully!'));
console.log(chalk.blue('\nNext steps:'));
console.log(chalk.white(' ⢠Run ') + chalk.cyan('vibe status') + chalk.white(' to see repository status'));
console.log(chalk.white(' ⢠Run ') + chalk.cyan('vibe commit') + chalk.white(' to create your first commit'));
console.log(chalk.white(' ⢠Visit ') + chalk.cyan('https://vibehub.dev') + chalk.white(' to view your project'));
}
}
catch (error) {
console.error(chalk.red('Failed to initialize VibeHub repository:'), error);
process.exit(1);
}
});
//# sourceMappingURL=init.js.map