2
0
Fork 0

added regex filtering support

This commit is contained in:
Willem 2015-03-14 16:16:31 +01:00
parent 3662aac188
commit 144854400f

View file

@ -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 = { var assemblerEventLog = {