Skip to content
44 changes: 20 additions & 24 deletions bin/npm-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
conf._exit = true
npm.load(conf, function (er) {
if (er) return errorHandler(er)
const useUnicode = npm.config.get('unicode')
if (
!isGlobalNpmUpdate &&
npm.config.get('update-notifier') &&
Expand All @@ -89,12 +90,19 @@
!isCI
) {
const color = require('ansicolors')
const useColor = npm.config.get('color')
const useUnicode = npm.config.get('unicode')
const old = notifier.update.current
const latest = notifier.update.latest
let old = notifier.update.current
let latest = notifier.update.latest
let type = notifier.update.type
if (useColor) {
let changelogLabel = 'Changelog:'
let changelog = `https://github.com/npm/cli/releases/tag/v${latest}`
let installCommand = `npm install -g ${pkg.name}`
const arrow = useUnicode ? '→' : '->'
if (npm.config.get('color')) {
old = color.red(old)
latest = color.green(latest)
changelogLabel = color.yellow(changelogLabel)
changelog = color.cyan(changelog)
installCommand = color.green(installCommand)
switch (type) {
case 'major':
type = color.red(type)
Expand All @@ -107,23 +115,11 @@
break
}
}
const changelog = `https://github.com/npm/cli/releases/tag/v${latest}`
notifier.notify({
message: `New ${type} version of ${pkg.name} available! ${
useColor ? color.red(old) : old
} ${useUnicode ? '→' : '->'} ${
useColor ? color.green(latest) : latest
}\n` +
`${
useColor ? color.yellow('Changelog:') : 'Changelog:'
} ${
useColor ? color.cyan(changelog) : changelog
}\n` +
`Run ${
useColor
? color.green(`npm install -g ${pkg.name}`)
: `npm i -g ${pkg.name}`
} to update!`
message:
`New ${type} version of ${pkg.name} available! ${old} ${arrow} ${latest}\n` +
`${changelogLabel} ${changelog}\n` +
`Run ${installCommand} to update!`
})
}
}
Expand All @@ -138,11 +134,11 @@
) {
console.error(
`\n ${
npm.config.get('unicode') ? '🎵 ' : ''
useUnicode ? '🎵 ' : ''
} I Have the Honour to Be Your Obedient Servant,${
npm.config.get('unicode') ? '🎵 ' : ''
useUnicode ? '🎵 ' : ''
} ~ npm ${
npm.config.get('unicode') ? '📜🖋 ' : ''
useUnicode ? '📜🖋 ' : ''
}\n`
)
}
Expand Down