From 7a5070173df54ca506f667b4b4443fd7a4642825 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 7 Feb 2018 22:39:15 -0800 Subject: [PATCH] add progress spinner --- cmd.js | 25 +++++++++++++++++++++---- package.json | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cmd.js b/cmd.js index c591eff..6da5e26 100755 --- a/cmd.js +++ b/cmd.js @@ -19,6 +19,10 @@ const DOWNLOADS_URL_LIMIT = 128 const readPackageTreeAsync = pify(readPackageTree) init().catch(handleError) +const spinner = ora({ + spinner: 'moon', + text: chalk`Getting ready to {cyan give thanks} to {magenta maintainers}...` +}).start() async function init () { const client = createRegistryClient() @@ -27,17 +31,21 @@ async function init () { const cwd = argv._[0] || process.cwd() // Get all packages in the nearest `node_modules` folder + spinner.text = chalk`Reading {cyan dependencies} from package tree in {magenta node_modules}...` const rootPath = await pkgDir(cwd) const packageTree = await readPackageTreeAsync(rootPath) // Get latest registry data on each local package, since the local data does // not include the list of maintainers + spinner.text = chalk`Fetching package {cyan maintainers} from {red npm}...` const pkgNames = packageTree.children.map(node => node.package.name) const allPkgs = await Promise.all(pkgNames.map(fetchPkg)) // Fetch download counts for each package + spinner.text = chalk`Fetching package {cyan download counts} from {red npm}...` const downloadCounts = await bulkFetchDownloads(pkgNames) + // Author name -> list of packages, ordered by download count const authorInfos = computeAuthorInfos(allPkgs, downloadCounts) const rows = Object.keys(authorInfos) @@ -59,12 +67,21 @@ async function init () { chalk.underline('Dependencies') ]) - const tableOpts = { - stringLength: str => stripAnsi(str).length + if (rows.length) { + spinner.succeed(chalk`You depend on {cyan ${rows.length} authors} who are {magenta seeking donations!} ✨\n`) + printTable(rows) + } else { + spinner.succeed('You don\'t depend on any packages from maintainers seeking donations') } - const table = textTable(rows, tableOpts) - console.log(table) + + function printTable (rows) { + const tableOpts = { + stringLength: str => stripAnsi(str).length + } + const table = textTable(rows, tableOpts) + console.log(table + '\n') + } async function fetchPkg (pkgName) { // The registry does not support fetching versions for scoped packages diff --git a/package.json b/package.json index a6cfd23..c851f72 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "got": "^8.0.3", "minimist": "^1.2.0", "npm-registry-client": "^8.5.0", + "ora": "^1.4.0", "pify": "^3.0.0", "pkg-dir": "^2.0.0", "read-package-tree": "^5.1.6",