From 258cbe7029914c45d0a7b97d1a47c0becd7af07f Mon Sep 17 00:00:00 2001 From: Mat Scales Date: Tue, 9 Apr 2013 12:18:23 +0100 Subject: [PATCH 1/2] Integrate update notifier (#202) --- bin/bower | 12 ++++++++---- package.json | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/bin/bower b/bin/bower index 58aa1794..a22419fd 100755 --- a/bin/bower +++ b/bin/bower @@ -1,9 +1,10 @@ #!/usr/bin/env node -var semver = require('semver'); -var nopt = require('nopt'); -var path = require('path'); -var pkg = require(path.join(__dirname, '..', 'package.json')); +var semver = require('semver'); +var nopt = require('nopt'); +var path = require('path'); +var pkg = require(path.join(__dirname, '..', 'package.json')); +var updateNotifier = require('update-notifier'); var template = require('../lib/util/template'); var bower = require('../lib'); @@ -15,6 +16,9 @@ var input = process.argv; var nodeVer = process.version; var reqVer = pkg.engines.node; var errors = []; +var notifier = updateNotifier({ packageName: pkg.name, packageVersion: pkg.version }); + +if (notifier.update) notifier.notify(); process.title = 'bower'; diff --git a/package.json b/package.json index 92b5ef1c..37ef9475 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,8 @@ "unzip": "0.1.4", "tar": "~0.1.13", "promptly": "~0.1.0", - "abbrev": "~1.0.4" + "abbrev": "~1.0.4", + "update-notifier": "~0.1.3" }, "scripts": { "test": "mocha --reporter spec --timeout 40000" From ba20766ec36e2a2c5c726b2ecaad66eff88a7af9 Mon Sep 17 00:00:00 2001 From: Mat Scales Date: Tue, 9 Apr 2013 14:59:03 +0100 Subject: [PATCH 2/2] Output the update notice on stderr so as not to interfere with the actual output of the commands --- bin/bower | 4 +++- templates/update-notice.mustache | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 templates/update-notice.mustache diff --git a/bin/bower b/bin/bower index a22419fd..28ceaecc 100755 --- a/bin/bower +++ b/bin/bower @@ -18,7 +18,9 @@ var reqVer = pkg.engines.node; var errors = []; var notifier = updateNotifier({ packageName: pkg.name, packageVersion: pkg.version }); -if (notifier.update) notifier.notify(); +if (notifier.update) { + process.stderr.write(template('update-notice', notifier.update, true)); +} process.title = 'bower'; diff --git a/templates/update-notice.mustache b/templates/update-notice.mustache new file mode 100644 index 00000000..a9af17ee --- /dev/null +++ b/templates/update-notice.mustache @@ -0,0 +1,4 @@ +{{#red}}-----------------------------------------{{/red}} +Update available: {{#yellow}}{{latest}}{{/yellow}} {{#cyan}}(current: {{current}}){{/cyan}} +Run {{#yellow}}npm update -g {{name}}{{/yellow}} to update +{{#red}}-----------------------------------------{{/red}}