Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace update-notifier with own implementation #2035

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions bin/nodemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ const options = cli.parse(process.argv);

nodemon(options);

const fs = require('fs');

// checks for available update and returns an instance
const pkg = JSON.parse(fs.readFileSync(__dirname + '/../package.json'));
const pkg = require('../package.json');

if (pkg.version.indexOf('0.0.0') !== 0 && options.noUpdateNotifier !== true) {
require('update-notifier')({ pkg }).notify();
require('../lib/update-notifier')(pkg);
}
31 changes: 31 additions & 0 deletions lib/update-notifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const https = require('https')
const ConfigStore = require('configstore')
const { compare } = require('compare-versions')

const CHECK_INTERVAL = 1000 * 60 * 60 * 24

module.exports = function (pkg) {
const pkgName = pkg.name
const pkgVer = pkg.version

const config = new ConfigStore(`update-notifier-${pkgName}`)
if (Date.now() - config.get('lastUpdateCheck') < CHECK_INTERVAL) {
return;
}

https.get(`https://registry.npmjs.org/-/package/${pkgName}/dist-tags`, (res) => {
let body = ''
res.on('data', (chunk) => body += chunk)
res.on('end', () => {
const jsonBody = JSON.parse(body)
const latestVer = jsonBody['latest']
if (compare(latestVer, pkgVer, '>')) {
const msg = ` Update of \x1b[36m${pkgName}\x1b[0m available \x1b[30m${pkgVer}\x1b[0m → \x1b[32m${latestVer}\x1b[0m`
console.log('')
console.log(msg)
console.log('')
}
config.set('lastUpdateCheck', Date.now())
})
})
}
Loading