Skip to content

Commit

Permalink
add boxen to version-checker output
Browse files Browse the repository at this point in the history
  • Loading branch information
olore committed Aug 29, 2018
1 parent 7cb6443 commit 228abd0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
18 changes: 11 additions & 7 deletions bin/npm-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,16 @@
})
})

var versionCheckerMessages = []
versionChecker.check()
.stdout.on('data', function (data) {
versionCheckerMessages.push(data.toString())
if (process.stdout.isTTY) {
var versionCheckerMessages = []
versionChecker.check()
.stdout.on('data', function (data) {
versionCheckerMessages.push(data.toString())
})
process.on('exit', () => {
if (versionCheckerMessages.length > 0) {
console.error(versionCheckerMessages.join('\n'))
}
})
process.on('exit', () => {
console.error(versionCheckerMessages.join('\n'))
})
}
})()
12 changes: 11 additions & 1 deletion lib/utils/version-checker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const boxen = require('boxen')
const log = require('npmlog')
const pacote = require('pacote')
const semver = require('semver')
Expand Down Expand Up @@ -61,7 +62,7 @@ function generateMessage (oldVersion, latestVersion, diffType, npm) {
}
const changelog = `https://github.com/npm/cli/releases/tag/v${latestVersion}`

return `New ${diffType} version of npm available! ${
let message = `New ${diffType} version of npm available! ${
useColor ? color.red(oldVersion) : oldVersion
} ${useUnicode ? '→' : '->'} ${
useColor ? color.green(latestVersion) : latestVersion
Expand All @@ -76,4 +77,13 @@ function generateMessage (oldVersion, latestVersion, diffType, npm) {
? color.green(`npm install -g npm`)
: `npm i -g npm`
} to update!`

const boxenOptions = {
padding: 1,
margin: 1,
align: 'center',
borderColor: 'yellow',
borderStyle: 'round'
}
return boxen(message, boxenOptions)
}
16 changes: 9 additions & 7 deletions node_modules/boxen/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"archy": "~1.0.0",
"bin-links": "^1.1.2",
"bluebird": "~3.5.1",
"boxen": "^1.3.0",
"byte-size": "^4.0.3",
"cacache": "^11.1.0",
"call-limit": "~1.1.0",
Expand Down Expand Up @@ -151,6 +152,7 @@
"cacache",
"call-limit",
"bluebird",
"boxen",
"bin-links",
"chownr",
"cmd-shim",
Expand Down Expand Up @@ -245,7 +247,6 @@
"umask",
"unique-filename",
"unpipe",
"update-notifier",
"uuid",
"validate-npm-package-license",
"validate-npm-package-name",
Expand Down

0 comments on commit 228abd0

Please sign in to comment.