Skip to content

Commit

Permalink
add ansi logging
Browse files Browse the repository at this point in the history
  • Loading branch information
maccman committed Oct 28, 2011
1 parent 1ee778a commit b131ddd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 22 additions & 3 deletions bin/spine
Expand Up @@ -2,8 +2,25 @@
var argv = process.argv.slice(2),
util = require("util"),
fs = require("fs"),
fd = require("path")

fd = require("path");

var ansi = function(message, color){
var ANSI_CODES = {
"off": 0,
"red": 31,
"green": 32,
"yellow": 33
};

if ( !color ) color = "green";

var str = "";
str += "\033[" + ANSI_CODES[color] + "m";
str += message;
str += "\033[" + ANSI_CODES["off"] + "m";
return str;
};

var isDir = function(path){
return(fs.statSync(path).isDirectory());
};
Expand Down Expand Up @@ -52,11 +69,13 @@ Template.prototype.write = function(){

if ( isDir(path) ) {
fs.mkdirSync(out, 0775);
console.log(ansi("\tcreate\t"), out);
} else if (fd.existsSync(out)) {
throw(path + " already exists");
} else {
var data = this.parse(fs.readFileSync(path, "utf8"));
fs.writeFileSync(out, data);
console.log(ansi("\tcreate\t"), out);
}
}, this);
};
Expand All @@ -82,7 +101,7 @@ var help = [

var generators = {};

generators.app = function(){
generators.app = generators.new = function(){
var template = __dirname + "/../templates/app";
var path = fd.normalize(argv[1]);

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "spine.app",
"description": "Spine app generator",
"version": "0.2.8",
"version": "0.2.9",
"repository": {
"type": "git",
"url": "git://github.com/maccman/spine.app.git"
Expand Down

0 comments on commit b131ddd

Please sign in to comment.