Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Commit

Permalink
Adding gh version module and improving the performance of the version…
Browse files Browse the repository at this point in the history
… update notifier. #344
  • Loading branch information
henvic committed Feb 15, 2015
1 parent e8e1fde commit 3a3c4c4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 18 deletions.
37 changes: 21 additions & 16 deletions lib/base.js
Expand Up @@ -32,31 +32,36 @@ exports.github = new github({
version: baseConfig.api.version
});

function checkVersionPkgFileHandler(err, data) {
var notifier,
pkg = JSON.parse(data);
exports.asyncReadPackages = function(callback) {
function async(err, data) {
if (err) {
throw err;
}

notifier = updateNotifier({
callback(JSON.parse(data));
}

fs.readFile(path.join(__dirname, '..', 'package.json'), async);

configs.getPlugins().forEach(function(plugin) {
fs.readFile(path.join(
configs.getNodeModulesGlobalPath(), plugin, 'package.json'), async);
});
};

exports.notifyVersion = function(pkg) {
var notifier = updateNotifier({
packageName: pkg.name,
packageVersion: pkg.version
});

if (notifier.update) {
notifier.notify();
}
}

exports.checkVersion = function(opt_callback) {
opt_callback && opt_callback();

fs.readFile(path.join(__dirname, '..', 'package.json'),
checkVersionPkgFileHandler);
};

configs.getPlugins().forEach(function(plugin) {
fs.readFile(path.join(
configs.getNodeModulesGlobalPath(), plugin, 'package.json'),
checkVersionPkgFileHandler);
});
exports.checkVersion = function() {
exports.asyncReadPackages(exports.notifyVersion);
};

exports.expandAliases = function(options) {
Expand Down
3 changes: 1 addition & 2 deletions lib/cmd.js
Expand Up @@ -105,8 +105,6 @@ exports.run = function () {
remain = parsed.argv.remain,
cooked = parsed.argv.cooked;

operations.push(base.checkVersion);

operations.push(function(callback) {
var module = remain[0];

Expand Down Expand Up @@ -139,6 +137,7 @@ exports.run = function () {

User.login(callback);
}
base.checkVersion();

if (tracker.optOut !== undefined) {
start();
Expand Down
1 change: 1 addition & 0 deletions lib/cmds/help.js
Expand Up @@ -53,6 +53,7 @@ Help.prototype.run = function() {

// Remove help from command list
files.splice(files.indexOf('help.js'), 1);
files.splice(files.indexOf('version.js'), 1);

// Get external plugins
plugins = configs.getPlugins();
Expand Down
40 changes: 40 additions & 0 deletions lib/cmds/version.js
@@ -0,0 +1,40 @@
/*
* Copyright 2013-2015, All Rights Reserved.
*
* Code licensed under the BSD License:
* https://github.com/node-gh/gh/blob/master/LICENSE.md
*
* @author Author <email@email.com>
*/

'use strict';

// -- Requires -------------------------------------------------------------------------------------

var base = require('../base'),
logger = require('../logger');

// -- Constructor ----------------------------------------------------------------------------------

function Version(options) {
this.options = options;
}

// -- Constants ------------------------------------------------------------------------------------

Version.DETAILS = {
alias: '',
description: 'Print gh version.',
};

// -- Commands -------------------------------------------------------------------------------------

Version.prototype.run = function() {
base.asyncReadPackages(this.printVersion);
};

Version.prototype.printVersion = function(pkg) {
logger.log(pkg.name + ' ' + pkg.version);
};

exports.Impl = Version;

0 comments on commit 3a3c4c4

Please sign in to comment.