UNPKG

@shashwatrajs/repo-insights

Version:

GitHub Repository Insights - CLI tool and library to fetch GitHub repo statistics

48 lines (42 loc) 1.76 kB
const { getRepoInsights } = require('./core.cjs'); const chalk = require('chalk'); const Table = require('cli-table3'); const { Command } = require('commander'); const fs = require('fs'); const program = new Command(); program .name('repo-insights') .argument('<owner>/<repo>', 'GitHub repository') .option('--stars', 'Show only stars') .option('--forks', 'Show only forks') .option('--issues', 'Show only open issues') .option('--commits', 'Show only commit metrics') .option('--all', 'Show all metrics (default)') .option('--json', 'JSON output') .option('--save <file>', 'Save output to JSON file') .action(async (repoPath, options) => { const [owner, repo] = repoPath.split('/'); const data = await getRepoInsights(owner, repo); if (data.error) { console.error(chalk.red(`Error: ${data.error}`)); process.exit(1); } if (options.json) { console.log(JSON.stringify(data, null, 2)); } else { const table = new Table({ head: ['Metric', 'Value'] }); if (options.stars || options.all) table.push([chalk.yellow('Stars'), data.stars]); if (options.forks || options.all) table.push([chalk.blue('Forks'), data.forks]); if (options.issues || options.all) table.push([chalk.red('Open Issues'), data.issues_open]); if (options.commits || options.all) { table.push([chalk.green('Commits (30d)'), data.commits_last_30_days]); table.push([chalk.green('Last Commit'), data.last_commit_date || 'No commits']); } console.log(table.toString()); } if (options.save) { fs.writeFileSync(options.save, JSON.stringify(data, null, 2)); console.log(chalk.magenta(`Saved output to ${options.save}`)); } }); program.parse(process.argv);