Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Notify if Punch is outdated

  • Loading branch information...
commit 5bf5c3c29248da88acbd3de8957aee6a7893b723 1 parent fd25034
@laktek authored
Showing with 77 additions and 31 deletions.
  1. +56 −31 lib/cli.js
  2. +21 −0 spec/cli.spec.js
View
87 lib/cli.js
@@ -1,4 +1,5 @@
var path = require("path");
+var child_process = require('child_process');
var _ = require("underscore");
var project_creator = require(path.join(__dirname, "../lib/project_creator.js"));
@@ -9,26 +10,41 @@ var config_handler = require(path.join(__dirname, "../lib/config_handler.js"));
module.exports = {
+ notifyIfOutdated: function(callback) {
+ child_process.exec("npm outdated punch", function(err, stdout, stderr) {
+ if (stdout.trim() != "") {
+ console.log("There's a new version of Punch available. You can upgrade to it by running `npm install -g punch`");
+ console.log("[" + stdout + "]");
+ }
+
+ return callback();
+ });
+ },
+
setup: function(args) {
- var template_path = null;
+ var self = this;
+
+ self.notifyIfOutdated(function() {
+ var template_path = null;
+
+ _.any(args, function(arg, i) {
+ if (arg === "-t" || arg === "--template") {
+ template_path = args[i + 1];
- _.any(args, function(arg, i) {
- if (arg === "-t" || arg === "--template") {
- template_path = args[i + 1];
+ args.splice(i, 2);
- args.splice(i, 2);
+ return true;
+ } else {
+ return false;
+ }
+ });
- return true;
+ if (template_path) {
+ return project_creator.createStructure(args.pop(), template_path);
} else {
- return false;
+ return project_creator.createStructure(args.pop());
}
});
-
- if (template_path) {
- return project_creator.createStructure(args.pop(), template_path);
- } else {
- return project_creator.createStructure(args.pop());
- }
},
server: function(args){
@@ -81,24 +97,33 @@ module.exports = {
});
},
- version: function(){
- var package_meta = require("../package.json");
- console.log("Punch version " + package_meta.version);
- },
+ version: function() {
+ var self = this;
- help: function(){
- console.log("Usage: punch COMMAND [ARGS]\n");
- console.log("You can use following commands:");
- console.log(" setup - create a new site structure in the given path. (punch setup PATH [-t TEMPLATE_PATH])");
- console.log(" server - start the Punch server. (punch s [PORT])");
- console.log(" publish - publish the site. (punch p)");
- console.log(" generate - generate all pages in the site. (punch g)");
- console.log(" version - version of the Punch installation. (punch v)");
- console.log(" help - show help. (punch h)\n");
- console.log("For more information about Punch visit: http://laktek.github.com/punch");
+ self.notifyIfOutdated(function() {
+ var package_meta = require("../package.json");
+ console.log("Punch version " + package_meta.version);
+ });
+ },
+
+ help: function() {
+ var self = this;
+
+ self.notifyIfOutdated(function() {
+ console.log("Usage: punch COMMAND [ARGS]\n");
+ console.log("You can use following commands:");
+ console.log(" setup - create a new site structure in the given path. (punch setup PATH [-t TEMPLATE_PATH])");
+ console.log(" server - start the Punch server. (punch s [PORT])");
+ console.log(" publish - publish the site. (punch p)");
+ console.log(" generate - generate all pages in the site. (punch g)");
+ console.log(" version - version of the Punch installation. (punch v)");
+ console.log(" help - show help. (punch h)\n");
+ console.log("For more information about Punch visit: http://laktek.github.com/punch");
+ });
},
- init: function(args){
+ init: function(args) {
+ var self = this;
var commands = ["setup", "server", "generate", "publish", "help", "version"];
@@ -107,11 +132,11 @@ module.exports = {
var command = args.shift();
if(_.include(commands, command)){
- return this[command](args);
+ return self[command](args);
} else if(_.include(_.keys(short_codes), command)){
- return this[short_codes[command]](args);
+ return self[short_codes[command]](args);
} else {
- return this["help"]();
+ return self["help"]();
}
}
View
21 spec/cli.spec.js
@@ -1,5 +1,7 @@
var cli = require("../lib/cli.js");
+var child_process = require('child_process');
+
var project_creator = require("../lib/project_creator.js");
var server = require("../lib/server.js");
var generator = require("../lib/site_generator.js");
@@ -37,6 +39,7 @@ describe("init", function() {
describe("setup a new site", function() {
it("create a site in target path with default template", function() {
+ spyOn(cli, "notifyIfOutdated").andCallFake(function(cb) { return cb(); });
spyOn(project_creator, "createStructure");
cli.setup(["path/target"]);
@@ -45,6 +48,7 @@ describe("setup a new site", function() {
});
it("create a site in target path with given template", function() {
+ spyOn(cli, "notifyIfOutdated").andCallFake(function(cb) { return cb(); });
spyOn(project_creator, "createStructure");
cli.setup(["--template", "path/to/template", "path/target"]);
@@ -53,6 +57,7 @@ describe("setup a new site", function() {
});
it("create a site in current path with given template", function() {
+ spyOn(cli, "notifyIfOutdated").andCallFake(function(cb) { return cb(); });
spyOn(project_creator, "createStructure");
cli.setup(["-t", "path/to/template"]);
@@ -61,6 +66,7 @@ describe("setup a new site", function() {
});
it("create a site in current path with default template", function() {
+ spyOn(cli, "notifyIfOutdated").andCallFake(function(cb) { return cb(); });
spyOn(project_creator, "createStructure");
cli.setup([]);
@@ -173,3 +179,18 @@ describe("publish a site", function() {
});
});
+
+describe("notify if outdated", function() {
+
+ it("call the callback", function() {
+ spyOn(child_process, "exec").andCallFake(function(cmd, cb) {
+ return cb(null, "outdated message");
+ });
+
+ var spyCallback = jasmine.createSpy();
+ cli.notifyIfOutdated(spyCallback);
+
+ expect(spyCallback).toHaveBeenCalled();
+ });
+
+});
Please sign in to comment.
Something went wrong with that request. Please try again.