git-bolt
Version:
Git utilities for faster development
131 lines (111 loc) • 3.8 kB
JavaScript
import chalk from 'chalk';
import { program } from 'commander';
import fs from 'fs';
import path, { dirname } from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Import commands
import { addCommand } from '../lib/commands/add.js';
import { branchCommand } from '../lib/commands/branch.js';
import { commitCommand } from '../lib/commands/commit.js';
import { configCommand } from '../lib/commands/config.js';
import { fetchCommand } from '../lib/commands/fetch.js';
import { initCommand } from '../lib/commands/init.js';
import { logCommand } from '../lib/commands/log.js';
import { pullCommand } from '../lib/commands/pull.js';
import { pushCommand } from '../lib/commands/push.js';
import { statusCommand } from '../lib/commands/status.js';
import { syncCommand } from '../lib/commands/sync.js';
import { verifyCommand } from '../lib/commands/verify.js';
// Display banner
console.log(chalk.blue('Git for Bolt.new'));
// Set up version from package.json
const packageJson = JSON.parse(
fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8')
);
program.version(packageJson.version);
// Verify command
program
.command('verify')
.description('Verify GitHub token access to the current repository')
.action(verifyCommand);
// Config command
program
.command('config')
.description('Set Git configuration values')
.argument('<key=value>', 'Configuration key and value (e.g., author.name=John Doe)')
.action(configCommand);
// Sync command (new user-friendly command)
program
.command('sync')
.description('Sync your code with GitHub (init, commit, pull, and push in one command)')
.action(syncCommand);
// Initialize repository
program
.command('init')
.description('Initialize and connect to a GitHub repository')
.argument('<repo-url>', 'GitHub repository URL')
.option('-t, --token <token>', 'GitHub personal access token')
.action(initCommand);
// Add files
program
.command('add')
.description('Add file(s) to the staging area')
.argument('<filepath>', 'File or directory path to add')
.action(addCommand);
// Commit changes
program
.command('commit')
.description('Commit staged changes')
.option('-m, --message <message>', 'Commit message', 'Update files')
.action(commitCommand);
// Push changes
program
.command('push')
.description('Push commits to remote repository')
.option('-b, --branch <branch>', 'Branch name (defaults to current branch)')
.action(pushCommand);
// Pull changes
program
.command('pull')
.description('Pull latest changes from remote repository')
.option('-b, --branch <branch>', 'Branch name (defaults to current branch)')
.action(pullCommand);
// Log command
program
.command('log')
.description('Show commit history')
.option('-d, --depth <number>', 'Number of commits to show', parseInt)
.action(logCommand);
// Branch operations
program
.command('branch')
.description('List, create, or checkout branches')
.argument('[name]', 'Branch name')
.option('-c, --create', 'Create a new branch')
.option('-l, --list', 'List all branches')
.action(branchCommand);
// Fetch changes
program
.command('fetch')
.description('Fetch latest changes from remote repository')
.option('-b, --branch <branch>', 'Branch name (defaults to current branch)')
.action(fetchCommand);
// Show status
program
.command('status')
.description('Show the working tree status')
.action(statusCommand);
// Handle errors
program.on('error', (err) => {
console.error(chalk.red('Error:'), err.message);
process.exit(1);
});
// Show help if no command is provided
if (process.argv.length === 2) {
program.help();
}
// Parse arguments
program.parse(process.argv);