Created
June 15, 2012 19:40
-
-
Save blakmatrix/2938367 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.commands.file = function file (filename, cb) { | |
this.log.info('Attempting to open "' + filename +'"'); | |
var newFile = getNewFile( filename ,cb); | |
app.log.info("Changes are comming!:\n"+newFile); | |
cb(null); | |
}; | |
var getNewFile = function(filename, cb){ | |
fs.readFile(filename, function (err, data) { | |
if (err) cb( err); | |
//app.log.info(data); | |
// app.log.info("Regex"); | |
var re = /require\s*\(\s*['"]sys['"]\s*\)/g; | |
var reFull = /sys\s*=\s*require\s*\(\s*['"]sys['"]\s*\)/g; | |
var rePart = /sys\./g; | |
var replacement = "require('util')"; | |
var replacementFull = "util = require('util')"; | |
var replacementPart = 'util.'; | |
var dataMod = ''; | |
if (XRegExp.test(data, re)){ | |
if (XRegExp.test(data, reFull)){ | |
dataMod = XRegExp.replace(XRegExp.replace(data, rePart , replacementPart , 'all' ), reFull , replacementFull , 'all' ); | |
}else{ | |
dataMod = XRegExp.replace(data, re , replacement , 'all' ); | |
} | |
//do stuff to dataMod | |
//app.log.info(dataMod); | |
return dataMod; | |
}else{ | |
//app.log.info('No '+'require(\'sys\')'.magenta.bold+' text found in file'); | |
return null; | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment