#!/usr/bin/env node const Table = require('cli-table') const getUserDownloadStats = require('./get-download-stats') const table = new Table({ head: [ 'Package', 'First Download Count', 'First Download Day', 'Total Downloads', 'Average Daily Downloads', ], }) const username = process.argv[2] async function go() { const stats = await getUserDownloadStats(username) const topPackages = stats.pkgStats.slice(0, 10) for (const pkg of topPackages) { const { stats: {package, firstDownload, totalDownloads, averageDailyDownloads}, } = pkg const firstCount = firstDownload ? firstDownload.downloads : 'unknown' const firstDay = firstDownload ? firstDownload.day : 'Unknown' table.push([ package, firstCount, firstDay, totalDownloads, averageDailyDownloads, ]) } console.log( ` Stats for ${username}: - Total Packages: ${stats.pkgStats.length} - First Downloaded Package: ${stats.firstDownload.pkg} - First Download Day: ${stats.firstDownload.day} - Total Downloads: ${stats.totalDownloads} - Top ${topPackages.length} Packages: ${table.toString()} `.trim(), ) } go()