Skip to content

Commit

Permalink
up too late, whoops. however this is more awesome now.
Browse files Browse the repository at this point in the history
  • Loading branch information
digiwano committed Aug 22, 2011
1 parent 6765bc4 commit cef3df7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 16 deletions.
75 changes: 61 additions & 14 deletions lib/auton.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
(function(){

var
watch = require( 'watch-tree' ),
async = require( 'asyncjs' ),
fs = require( 'fs' ),
util = require( 'util' ),
path = require( 'path' ),
inspect = util.inspect,
plugins = require('./plugins');
watch = require( 'watch-tree' ),
async = require( 'asyncjs' ),
fs = require( 'fs' ),
colorize = require( 'colorize' ),
console = colorize.console,
util = require( 'util' ),
path = require( 'path' ),
inspect = util.inspect,
fs = require( 'fs' ),
plugins = require('./plugins');

module.exports.plugins = plugins;
module.exports.Compiler = Compiler;
Expand All @@ -21,6 +24,20 @@
this.waitTime = 100; // time to wait for write after noticing a change
return this;
}

var levelColorMap = {
'error' : 'red',
'success' : 'green',
'msg' : 'plain',
'info' : 'cyan',
'warn' : 'yellow'
};

Compiler.prototype.log = function( level, coloredPart, plainPart ) {
var color = levelColorMap[level],
outputString = colorize.ansify("#" + color + "[ " + coloredPart + " ]") + " - " + plainPart;
util.log( outputString );
}

Compiler.prototype.start = function() {
var that = this,
Expand All @@ -42,9 +59,9 @@
watcher.on( 'fileDeleted', _delete );
watcher.on( 'allPreexistingFilesReported', function(){
if (watchMode) {
console.log("-----> Entering watch mode!");
that.log('info', "----->", "Entering watch mode!");
} else {
console.log("-----> Done!");
that.log('info', "----->", "Done scanning for changed files!");
watcher.end();
}
});
Expand All @@ -61,7 +78,7 @@
Compiler.prototype.copy = function( test ) {
this.rules.push({
test: test,
outputFilenameFunction: function(type, filePath){ return type === 'original' ? filePath : null; },
outputFilenameFunction: function(type, filePath){ return (type === 'original' || type === '__age_check__') ? filePath : null; },
ruleList: [plugins.read, plugins.save]
});
}
Expand Down Expand Up @@ -113,17 +130,47 @@
rule: rule,
path: file,
save: { }
};
var go = function() {
},
go = function() {
async.list(functions).call(args).end(function(e){
if (e) {
console.log("---\n---\n---\n\nERROR IN FILE: "+file+"\n\nError: "+e+"\n\n---\n---\n---\n");
args.compiler.log( 'error', "Error in "+file, "\n" + e.toString() + "\n" );
} else {
// console.log(" COMPILED: " + file);
}
});
}
setTimeout( go, this.waitTime );

var ageCheckFilename = rule.outputFilenameFunction( '__age_check__', file );
if (ageCheckFilename) {
var infile = path.join( this.rootDir, file )
outfile = path.join( this.outputDir, ageCheckFilename );
fs.stat( infile, function(err, infileStats){
if (err) {
args.compiler.log( 'error', 'couldnt stat '+infile, err);
return;
}
path.exists( outfile, function(exists){
if (exists) {
fs.stat( outfile, function(err, outfileStats){
if (err) {
args.compiler.log( 'error', 'couldnt stat '+outfile, err);
return;
}
if (Date.parse(infileStats.mtime) > Date.parse(outfileStats.mtime)) {
setTimeout( go, args.compiler.waitTime );
} else {
}
});
} else {
setTimeout( go, args.compiler.waitTime );
}

});
});
} else {
setTimeout( go, args.compiler.waitTime );
}
}


Expand Down
2 changes: 1 addition & 1 deletion lib/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ var plugins = {},
dirname = path.dirname( fullPath );

if (filename) {
util.log("Saved -> " + fullPath);
that.compiler.log('success', "Saved", fullPath);
mkdir_p( dirname, function(e){
if (e) { return next(e); }

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"uglify-js": ">=1.0.6",
"coffee-script": ">=1.1.1",
"watch-tree": ">=0.1.1",
"asyncjs": ">=0.0.5"
"asyncjs": ">=0.0.5",
"colorize": ">=0.1.0"
},
"devDependencies": {},
"licenses": [{
Expand Down

0 comments on commit cef3df7

Please sign in to comment.