vibehub-cli
Version:
VibeHub CLI - Command line interface for VibeHub
182 lines โข 7.57 kB
JavaScript
import { Command } from 'commander';
import chalk from 'chalk';
import fs from 'fs-extra';
import path from 'path';
import { execSync } from 'child_process';
export const installCommand = new Command('install')
.description('Install VibeHub CLI globally')
.option('-f, --force', 'Force reinstallation even if already installed')
.option('--skip-build', 'Skip building the CLI (use existing build)')
.action(async (options) => {
let tempDir = null;
try {
console.log(chalk.blue('๐ Installing VibeHub CLI...\n'));
// Check if Node.js is installed
try {
execSync('node --version', { stdio: 'pipe' });
}
catch {
console.error(chalk.red('โ Node.js is not installed. Please install Node.js first.'));
process.exit(1);
}
// Check if npm is installed
try {
execSync('npm --version', { stdio: 'pipe' });
}
catch {
console.error(chalk.red('โ npm is not installed. Please install npm first.'));
process.exit(1);
}
// Check if git is installed
try {
execSync('git --version', { stdio: 'pipe' });
}
catch {
console.error(chalk.red('โ git is not installed. Please install git first.'));
process.exit(1);
}
// Check if already installed
try {
execSync('vibe --version', { stdio: 'pipe' });
if (!options.force) {
console.log(chalk.yellow('โ ๏ธ VibeHub CLI is already installed.'));
console.log(chalk.blue('Use --force to reinstall.'));
return;
}
console.log(chalk.blue('๐ Reinstalling VibeHub CLI...'));
}
catch {
// Not installed, continue with installation
}
// For global installation, we need to clone the repository to a temporary location
console.log(chalk.blue('๐ฅ Downloading VibeHub CLI...'));
const vibehubRepoUrl = 'https://github.com/Anandakumar-D/vibehub.git';
// Create temporary directory in a safe location
tempDir = path.join(process.env.TMPDIR || '/tmp', `vibe-install-${Date.now()}`);
await fs.ensureDir(tempDir);
// Clone the repository to temporary directory
console.log(chalk.blue('๐ฆ Cloning repository to temporary location...'));
execSync(`git clone ${vibehubRepoUrl} .`, {
stdio: 'inherit',
cwd: tempDir
});
const projectRoot = tempDir;
const packageJsonPath = path.join(projectRoot, 'package.json');
if (!await fs.pathExists(packageJsonPath)) {
throw new Error('Failed to clone repository');
}
// Install dependencies
console.log(chalk.blue('๐ฆ Installing dependencies...'));
execSync('npm install', {
stdio: 'inherit',
cwd: projectRoot
});
// Build the CLI if not skipped
if (!options.skipBuild) {
console.log(chalk.blue('๐ฆ Building VibeHub CLI...'));
try {
execSync('npm run build:cli', {
stdio: 'inherit',
cwd: projectRoot
});
}
catch (error) {
console.error(chalk.red('โ Failed to build CLI'));
process.exit(1);
}
}
// Check if dist/cli/index.js exists
const cliPath = path.join(projectRoot, 'dist', 'cli', 'index.js');
if (!await fs.pathExists(cliPath)) {
console.error(chalk.red('โ CLI build not found.'));
console.log(chalk.blue('Please run "npm run build:cli" first.'));
process.exit(1);
}
// Make the CLI executable
console.log(chalk.blue('๐ง Making CLI executable...'));
try {
await fs.chmod(cliPath, 0o755);
}
catch (error) {
console.error(chalk.red('โ Failed to make CLI executable:'), error);
process.exit(1);
}
// Install globally using npm link
console.log(chalk.blue('๐ Installing VibeHub CLI globally...'));
try {
execSync('npm link', {
stdio: 'inherit',
cwd: projectRoot
});
}
catch (error) {
console.error(chalk.red('โ Failed to install CLI globally'));
console.log(chalk.blue('Try running with sudo if you encounter permission issues:'));
console.log(chalk.gray(' sudo vibe install'));
process.exit(1);
}
// Test the installation
console.log(chalk.blue('๐งช Testing CLI installation...'));
try {
const version = execSync('vibe --version', {
stdio: 'pipe',
encoding: 'utf8'
}).trim();
console.log(chalk.green('โ
VibeHub CLI installed successfully!'));
console.log(chalk.cyan(`๐ฆ Version: ${version}`));
console.log(chalk.blue('\n๐ Available commands:'));
console.log(chalk.gray(' vibe init - Initialize a new VibeHub repository'));
console.log(chalk.gray(' vibe status - Show repository status'));
console.log(chalk.gray(' vibe add - Add files to staging'));
console.log(chalk.gray(' vibe commit - Create a commit'));
console.log(chalk.gray(' vibe push - Push to VibeHub cloud'));
console.log(chalk.gray(' vibe pull - Pull from VibeHub cloud'));
console.log(chalk.gray(' vibe set - Connect to existing project'));
console.log(chalk.gray(' vibe --help - Show all commands'));
console.log(chalk.green('\n๐ You can now use "vibe" commands in any directory!'));
// Show installation path
try {
const whichOutput = execSync('which vibe', {
stdio: 'pipe',
encoding: 'utf8'
}).trim();
console.log(chalk.gray(`๐ Installed at: ${whichOutput}`));
}
catch {
// Ignore if which command fails
}
}
catch (error) {
console.error(chalk.red('โ CLI installation test failed'));
console.log(chalk.blue('The CLI was installed but may not be in your PATH.'));
console.log(chalk.blue('Try restarting your terminal or adding the npm global bin to your PATH.'));
process.exit(1);
}
// Clean up temporary directory
console.log(chalk.blue('๐งน Cleaning up temporary files...'));
if (tempDir) {
try {
await fs.remove(tempDir);
}
catch (error) {
console.log(chalk.yellow('โ ๏ธ Could not clean up temporary directory:'), tempDir);
}
}
}
catch (error) {
// Clean up on error
if (tempDir) {
try {
await fs.remove(tempDir);
}
catch {
// Ignore cleanup errors
}
}
console.error(chalk.red('โ Installation failed:'), error);
console.log(chalk.blue('Try running with sudo if you encounter permission issues:'));
console.log(chalk.gray(' sudo vibe install'));
process.exit(1);
}
});
//# sourceMappingURL=install.js.map