diff --git a/lib/factory.js b/lib/factory.js index 9b805e7..0a3d369 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -29,6 +29,40 @@ var assemblerConstructors = { }); }; }, + readFileRegex : function(regexData) { + if (regexData === undefined) { + // Simple regex which cleans most stuff from js and css. + regexData = { + '(\\s\\\|\\|\\s)': '||', // clean bit-or space + '(\\s\\\&\\&\\s)': '&&', // clean bit-and space + '(if\\s\\(\\s)': 'if(', // clean if space + '(for\\s\\(\\s)': 'for(', // clean for space + '(\\s*{\\s*)': '{', // clean bracket open + '(^\\s*}\\s*)': '}\n', // clean bracket close + '(^\\s+)': '', // clean up white space + '(\\{[\\s\\/]+\\/.*)': '{', // rm comment on functions + '(^|\\s\\/\\/.*)': '', // rm comment lines + '(\\/\\*[\\s\\*\\!][\\s\\S]*?\\*\\/)': '', // rm comment blocks + }; + } + return function(file, callback) { + fs.readFile(file, function(err, data) { + if (err) { + callback(err); + } else { + data = ''+data; + var regexList = Object.keys(regexData); + for (var i = 0; i < regexList.length; i++) { + var regex = new RegExp(regexList[i],'gm'); + var regexReplace = regexData[regexList[i]]; + //console.log('regex: \''+regex+'\' replace: \''+regexReplace+'\''); + data = data.replace(regex,regexReplace); + } + callback(null, data); + } + }); + }; + }, }; var assemblerEventLog = {