Skip to content

Loading…

Integrate update notifier (#202) #383

Merged
merged 2 commits into from

3 participants

@wibblymat
Bower member

No description provided.

@sindresorhus sindresorhus commented on the diff
bin/bower
@@ -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 });
@sindresorhus Bower member

var notifier = updateNotifier({ packagePath: '../package.json' });

then pkg isn't needed.

@wibblymat Bower member

pkg was already there for other things, I only changed whitespace on that require().

@sindresorhus Bower member

Oh, didn't notice, nvm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@sindresorhus
Bower member

Big :+1:

@satazor satazor commented on an outdated diff
bin/bower
@@ -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();
@satazor Bower member
satazor added a note

This can't be done in every command, e.g.: bower list --paths
Basically, in commands that output json like that one nothing else can be outputted.

@wibblymat Bower member

Could we output on stderr?

@satazor Bower member
satazor added a note

this would require a change in the update-notifier package. It does console.log. //cc @sindresorhus

@sindresorhus Bower member

.notify() is only a convenience method, create your own, all you need is on the notifier instance.

But I don't think we should output on stderr, that should be reserved for actual errors, not workarounds.

@satazor Bower member
satazor added a note

Yes, we can, totally forgot that. Anyway stderr is not only for errors but for additional information.

Standard error is another output stream typically used by programs to output error messages or diagnostics

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@satazor satazor merged commit eadc478 into bower:master

1 check passed

Details default The Travis build passed
@wibblymat wibblymat deleted the wibblymat:update-notifier branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 9, 2013
  1. @wibblymat
  2. @wibblymat
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 5 deletions.
  1. +10 −4 bin/bower
  2. +2 −1 package.json
  3. +4 −0 templates/update-notice.mustache
View
14 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,11 @@ var input = process.argv;
var nodeVer = process.version;
var reqVer = pkg.engines.node;
var errors = [];
+var notifier = updateNotifier({ packageName: pkg.name, packageVersion: pkg.version });
@sindresorhus Bower member

var notifier = updateNotifier({ packagePath: '../package.json' });

then pkg isn't needed.

@wibblymat Bower member

pkg was already there for other things, I only changed whitespace on that require().

@sindresorhus Bower member

Oh, didn't notice, nvm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+if (notifier.update) {
+ process.stderr.write(template('update-notice', notifier.update, true));
+}
process.title = 'bower';
View
3 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"
View
4 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}}
Something went wrong with that request. Please try again.