From 5b7fe8d7be415ab278630a60deca1b461f6fee9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Tue, 20 Jun 2017 22:46:00 +0200 Subject: [PATCH] feat(package): report number of temp packages installed --- child.js | 8 ++++++-- index.js | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/child.js b/child.js index b4d8267..93efda9 100644 --- a/child.js +++ b/child.js @@ -26,14 +26,18 @@ module.exports.spawn = spawn function spawn (cmd, args, opts) { return BB.fromNode(cb => { const child = cp.spawn(cmd, args, opts) + let stdout = '' + let stderr = '' + child.stdout && child.stdout.on('data', d => { stdout += d }) + child.stderr && child.stderr.on('data', d => { stderr += d }) child.on('error', cb) child.on('close', code => { if (code) { const err = new Error(Y`Command failed: ${cmd} ${args.join(' ')}`) err.exitCode = code cb(err) - } else { - cb() + } else if (child.stdout || child.stderr) { + cb(null, {code, stdout, stderr}) } }) }) diff --git a/index.js b/index.js index 954f943..819f567 100755 --- a/index.js +++ b/index.js @@ -40,6 +40,8 @@ function main (argv) { return } + const startTime = Date.now() + // First, we look to see if we're inside an npm project, and grab its // bin path. This is exactly the same as running `$ npm bin`. return localBinPath(process.cwd()).then(local => { @@ -66,7 +68,11 @@ function main (argv) { } if ((!existing && !argv.call) || argv.packageRequested) { // Some npm packages need to be installed. Let's install them! - return ensurePackages(argv.package, argv).then(() => existing) + return ensurePackages(argv.package, argv).then(results => { + console.error(Y`npx: installed ${ + results.added.length + results.updated.length + } in ${(Date.now() - startTime) / 1000}s`) + }).then(() => existing) } else { // We can skip any extra installation, 'cause everything exists. return existing @@ -159,12 +165,12 @@ function buildArgs (specs, prefix, opts) { } module.exports._installPackages = installPackages -function installPackages (specs, prefix, npmOpts) { - const args = buildArgs(specs, prefix, npmOpts) - return which(npmOpts.npm).then(npmPath => { +function installPackages (specs, prefix, opts) { + const args = buildArgs(specs, prefix, opts) + return which(opts.npm).then(npmPath => { return child.spawn(npmPath, args, { - stdio: [0, 'ignore', 2] - }).catch(err => { + stdio: [0, 'pipe', 2] + }).then(deets => deets.stdout ? JSON.parse(deets.stdout) : null, err => { if (err.exitCode) { err.message = Y`Install for ${specs} failed with code ${err.exitCode}` }