UNPKG

build-in-public-bot

Version:

AI-powered CLI bot for automating build-in-public tweets with code screenshots

279 lines 12.1 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.autoAliasCommand = void 0; const commander_1 = require("commander"); const chalk_1 = __importDefault(require("chalk")); const ora_1 = __importDefault(require("ora")); const shell_detector_1 = require("../services/shell-detector"); const errors_1 = require("../utils/errors"); const logger_1 = require("../utils/logger"); const readline = __importStar(require("readline/promises")); const DEFAULT_ALIASES = [ { alias: 'bip', command: 'build-in-public', description: 'Main build-in-public bot command' }, { alias: 'bippost', command: 'bip post', description: 'Quick post to Twitter' }, { alias: 'bipcode', command: 'bip code', description: 'Post code screenshot' }, { alias: 'bipscreen', command: 'bip screenshot', description: 'Take code screenshot' }, { alias: 'bipterm', command: 'bip terminal', description: 'Capture terminal output' }, { alias: 'bipwatch', command: 'bip watch', description: 'Watch for changes and suggest tweets' }, { alias: 'bipauto', command: 'bip auto start', description: 'Start auto-posting mode' } ]; exports.autoAliasCommand = new commander_1.Command('auto-alias') .description('Automatically set up shell aliases for common commands') .option('-s, --shell <shell>', 'Target specific shell (bash, zsh, fish)') .option('-l, --list', 'List current aliases') .option('-r, --remove', 'Remove installed aliases') .option('-c, --custom <alias:command>', 'Add custom alias') .option('--skip-reload', 'Skip shell reload instruction') .action(async (options) => { try { const detector = new shell_detector_1.ShellDetector(); const spinner = (0, ora_1.default)(); if (options.list) { const shells = detector.detectInstalledShells(); console.log(chalk_1.default.cyan('Current build-in-public aliases:\n')); for (const shell of shells) { const aliases = detector.getAliases(shell); const bipAliases = Array.from(aliases.entries()) .filter(([alias]) => alias.startsWith('bip')); if (bipAliases.length > 0) { console.log(chalk_1.default.yellow(`${shell.name}:`)); for (const [alias, command] of bipAliases) { console.log(` ${chalk_1.default.green(alias)}${command}`); } console.log(); } } return; } let targetShells = []; if (options.shell) { const shells = detector.detectInstalledShells(); const target = shells.find(s => s.name === options.shell); if (!target) { throw new Error(`Shell '${options.shell}' not found or not installed`); } targetShells = [target]; } else { const currentShell = detector.detectCurrentShell(); if (currentShell) { targetShells = [currentShell]; } else { targetShells = detector.detectInstalledShells(); } } if (targetShells.length === 0) { throw new Error('No supported shells detected'); } if (options.remove) { spinner.start('Removing aliases...'); for (const shell of targetShells) { let removed = 0; for (const config of DEFAULT_ALIASES) { if (detector.removeAlias(shell, config.alias)) { removed++; } } if (removed > 0) { logger_1.logger.info(`Removed ${removed} aliases from ${shell.name}`); } } spinner.succeed('Aliases removed successfully'); return; } const aliasesToInstall = []; if (options.custom) { const [alias, ...commandParts] = options.custom.split(':'); if (!alias || commandParts.length === 0) { throw new Error('Invalid custom alias format. Use: alias:command'); } aliasesToInstall.push({ alias, command: commandParts.join(':'), description: 'Custom alias' }); } else { aliasesToInstall.push(...DEFAULT_ALIASES); } const existingAliases = new Map(); for (const shell of targetShells) { for (const config of aliasesToInstall) { if (detector.checkAliasExists(shell, config.alias)) { if (!existingAliases.has(config.alias)) { existingAliases.set(config.alias, []); } existingAliases.get(config.alias).push(shell.name); } } } if (existingAliases.size > 0 && !options.custom) { console.log(chalk_1.default.yellow('⚠️ Some aliases already exist:')); for (const [alias, shells] of existingAliases) { console.log(` ${alias} in ${shells.join(', ')}`); } const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); const answer = await rl.question('\nOverwrite existing aliases? (y/N) '); rl.close(); if (answer.toLowerCase() !== 'y') { console.log(chalk_1.default.gray('Installation cancelled')); return; } } spinner.start('Installing aliases...'); const results = new Map(); for (const shell of targetShells) { let installed = 0; for (const config of aliasesToInstall) { try { detector.installAlias(shell, config); installed++; } catch (error) { logger_1.logger.error(`Failed to install '${config.alias}' to ${shell.name}:`, error); } } if (installed > 0) { results.set(shell.name, installed); } } spinner.succeed('Aliases installed successfully'); console.log(chalk_1.default.green('\n✅ Installation complete!\n')); for (const [shellName, count] of results) { console.log(chalk_1.default.gray(` ${shellName}: ${count} aliases installed`)); } if (!options.custom) { console.log(chalk_1.default.cyan('\nInstalled aliases:')); for (const config of DEFAULT_ALIASES) { console.log(` ${chalk_1.default.green(config.alias)}${config.command}`); if (config.description) { console.log(chalk_1.default.gray(` ${config.description}`)); } } } if (!options.skipReload) { console.log(chalk_1.default.yellow('\n📌 To use the aliases, reload your shell:')); for (const shell of targetShells) { switch (shell.name) { case 'bash': console.log(chalk_1.default.gray(` source ~/.bashrc`)); break; case 'zsh': console.log(chalk_1.default.gray(` source ~/.zshrc`)); break; case 'fish': console.log(chalk_1.default.gray(` source ~/.config/fish/config.fish`)); break; default: console.log(chalk_1.default.gray(` source ${shell.configFile}`)); } } console.log(chalk_1.default.gray('\n Or simply open a new terminal window')); } } catch (error) { (0, errors_1.handleError)(error); } }); exports.autoAliasCommand .command('check') .description('Check if aliases are properly installed') .action(async () => { try { const detector = new shell_detector_1.ShellDetector(); const currentShell = detector.detectCurrentShell(); if (!currentShell) { console.log(chalk_1.default.red('Could not detect current shell')); return; } console.log(chalk_1.default.cyan(`Checking aliases in ${currentShell.name}...\n`)); let found = 0; let missing = 0; for (const config of DEFAULT_ALIASES) { const exists = detector.checkAliasExists(currentShell, config.alias); if (exists) { console.log(chalk_1.default.green(`✓ ${config.alias}`)); found++; } else { console.log(chalk_1.default.red(`✗ ${config.alias}`)); missing++; } } console.log(chalk_1.default.gray(`\nFound: ${found}, Missing: ${missing}`)); if (missing > 0) { console.log(chalk_1.default.yellow('\nRun "bip auto-alias" to install missing aliases')); } } catch (error) { (0, errors_1.handleError)(error); } }); exports.autoAliasCommand .command('suggest') .description('Suggest useful custom aliases based on usage') .action(async () => { try { console.log(chalk_1.default.cyan('Suggested custom aliases:\n')); const suggestions = [ { alias: 'bipinit', command: 'bip init', description: 'Initialize new project' }, { alias: 'bipstyle', command: 'bip style', description: 'Configure tweet style' }, { alias: 'biphist', command: 'bip history', description: 'View tweet history' }, { alias: 'bipdoc', command: 'bip doctor', description: 'Run health checks' }, { alias: 'bipconfig', command: 'bip config show', description: 'Show configuration' } ]; for (const suggestion of suggestions) { console.log(`${chalk_1.default.green(suggestion.alias)}${suggestion.command}`); if (suggestion.description) { console.log(chalk_1.default.gray(` ${suggestion.description}`)); } } console.log(chalk_1.default.gray('\nTo install a suggestion:')); console.log(chalk_1.default.gray(' bip auto-alias --custom "alias:command"')); } catch (error) { (0, errors_1.handleError)(error); } }); exports.default = exports.autoAliasCommand; //# sourceMappingURL=auto-alias.js.map