Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jul 18, 2012
Arnout Kazemier 3rd-Eden Added a square#outofdate method that will check the current github re…
…pository's package.json version

to see if they matches, if they are not the same it will probably mean that your version is out of date
and that you need to download a new version from NPM..

This command is added because people never check for updates on command-line utilities, yet is important
to always run the latest version as it has many bug's fixes
3c9d818
Arnout Kazemier 3rd-Eden Merge branch 'master' of github.com:observing/square into development
Conflicts:
	bin/square
	lib/square.js
13bd298
Showing with 114 additions and 37 deletions.
  1. +44 −24 bin/square
  2. +60 −13 lib/square.js
  3. +10 −0 test/square.api.test.js
68 bin/square
View
@@ -2,31 +2,32 @@
"use strict";
/**
- * Library modules.
+ * Native modules.
*/
var fs = require('fs')
- , path = require('path')
- , color = require('colors')
- , _ = require('lodash')
- , program = require('commander');
+ , path = require('path');
/**
- * Do we need to silence all the output because we spit the shit to std out?
- * This needs to be checked before we parse the argv's using commander so we can
- * silence the output before that.
+ * Third party modules.
*/
-program.silence = ~process.argv.indexOf('--output') || ~process.argv.indexOf('-o');
+var _ = require('lodash')
+ , color = require('colors')
+ , program = require('commander');
/**
* Square library internals.
*/
var Square = require('../lib/square')
- , npm = require('../package')
, square = new Square({ cli: true });
+// Do we need to silence all the output because we spit the shit to std out?
+// This needs to be checked before we parse the argv's using commander so we can
+// silence the output before that.
+program.silence = ~process.argv.indexOf('--output') || ~process.argv.indexOf('-o');
+
/**
* Argument filters for commander.
*
@@ -61,7 +62,7 @@ var filters = {
// Setup the command line interface.
program
- .version(npm.version)
+ .version(require('../package.json').version)
.usage('[options]')
.option('-b, --bundle <dir/file.json>', 'the location of the package file')
.option('-e, --extension <extension>', 'filter on this file extension')
@@ -246,7 +247,7 @@ if (!program.silence)
[
''
, 'o-o o-o o o o-o o-o o-o '.cyan
- , ' \\ | | | | |-| | |- '.cyan + (' version: ' + npm.version).white
+ , ' \\ | | | | |-| | |- '.cyan + (' version: ' + program._version).white
, 'o-o o-O o--o o o-o o-o '.cyan
, ' | '.cyan
, ' o '.cyan
@@ -304,26 +305,45 @@ program.notFound = function notFound () {
// This is for example the case for the init/bootstrap commands.
if (program.commands_exec) return;
-/**
- * Make sure that the bundle location exists, so we don't get any ENOENT errors
- */
+// Make sure that the bundle location exists, so we don't get any ENOENT errors
+if (!fs.existsSync(program.bundle)) return program.notFound();
+
+// Start search the given directory tree for square.json files. If we cannot
+// parse the bundle we are just gonna return because don't need to do any more
+// processing in this run.
+if (!square.parse(program.bundle)) return;
-if (!fs.existsSync(program.bundle)) {
- return program.notFound();
-}
/**
- * Start search the given directory tree for square.json files. If we cannot
- * parse the bundle we are just gonna return because don't need to do any more
- * processing in this run.
+ * Called when our version is no longer the same version as our upstream
+ * repository.
+ *
+ * @param {String} latest upstream version
+ * @param {String} current current version
*/
-if (!square.parse(program.bundle)) return;
+function outofdate(latest, current) {
+ [
+ 'The [square] build system is out of date, the latest version is '.white
+ + latest.green + '.'.white
+ , 'but you are still running version '.white + current.red
+ + '. Please consider upgrading to the'
+ , 'latest version to receive all bugfixes and new features.'
+ , ''
+ , 'type: '.white + 'npm install square -g'.green
+ + ' to download the latest version.'.white
+ , ''
+ ].forEach(function log (line) {
+ square.logger.warning(line);
+ });
+}
// process the plugins
program.plugins.forEach(function load (plugin) {
square.plugin(plugin);
});
-// building all the things
-square.build(program.group);
+square
+ .once('outofdate', outofdate)
+ .outofdate(true)
+ .build();
73 lib/square.js
View
@@ -4,29 +4,30 @@
* Native modules.
*/
-var fs = require('fs')
- , os = require('os')
+var EventEmitter = require('events').EventEmitter
+ , createHash = require('crypto').createHash
, zlib = require('zlib')
, path = require('path')
- , createHash = require('crypto').createHash
- , EventEmitter = require('events').EventEmitter;
+ , fs = require('fs')
+ , os = require('os');
/**
- * Super charge the EventEmitters, and sprinkle everything with sugar.
+ * Third party modules.
*/
-require('eventreactor');
-require('sugar');
+var canihaz = require('canihaz')('square')
+ , exec = require('shelljs').exec
+ , Logger = require('devnull')
+ , async = require('async')
+ , eson = require('eson')
+ , _ = require('lodash');
/**
- * Third party modules.
+ * Super charge the EventEmitters, and sprinkle everything with sugar.
*/
-var Logger = require('devnull')
- , async = require('async')
- , eson = require('eson')
- , _ = require('lodash')
- , exec = require('shelljs').exec;
+require('eventreactor');
+require('sugar');
/**
* Pre-process filters.
@@ -667,6 +668,52 @@ Square.prototype.build = function build(extension, fn) {
};
/**
+ * Check if we are running an out of date build of square. Because users are not
+ * actively checking if their binary is up to date and will be missing out on
+ * critical bug fixes and feature releases.
+ *
+ * @param {Boolean} random should we do a random check
+ * @param {String} branch optional branch
+ * @returns {Boolean} allowed to check
+ * @api public
+ */
+
+Square.prototype.outofdate = function outofdate(random, branch) {
+ // allow users to cancel our update check
+ if (this.package.configuration && this.package.configuration.noupdate) return false;
+
+ var luckynumber = Math.floor(Math.random() * 11)
+ , url = 'https://raw.github.com/observing/square/'
+ + (branch || 'master')
+ + '/package.json'
+ , self = this;
+
+ // rate limit the amount of checks that we are allowed to do, we don't want to
+ // check github for every invocation of square
+ if (random && luckynumber !== 7) return false
+
+ canihaz.request(function lazyload (err, request) {
+ if (err) return;
+
+ request({ uri: url }, function done (err, res, body) {
+ var latest;
+
+ // no need to do error handling here.. if there was an error, we can't
+ // probably parse JSON anyways and it will just die inside the JSON.parse
+ try { latest = JSON.parse(body.toString('utf8')).version; }
+ catch (e) { return; }
+
+ if (latest && latest !== self.version) {
+ self.emit('outofdate', latest, self.version);
+ }
+ });
+ });
+
+ return;
+};
+
+
+/**
* Process the template string.
*
* @param {String} str
10 test/square.api.test.js
View
@@ -153,6 +153,16 @@ describe('[square] API', function () {
describe('#build', function () {});
+ describe('#outofdate', function () {
+ it('should check the upstream repo for its version number');
+
+ it('should check different branches of the upstream');
+
+ it('should randomly check for an upstream');
+
+ it('should not check upstream if forbidden by configuration');
+ });
+
describe('#tag', function () {
it('should return the branch name, as this is a git repository');

No commit comments for this range

Something went wrong with that request. Please try again.