-
-
Save FokkeZB/5865528 to your computer and use it in GitHub Desktop.
My complete alloy.jmk will be here ;)
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
function isProduction(alloyConfig) | |
{ | |
return 'production' == alloyConfig.deployType; | |
} | |
function removeUnimportantLogCallsFromContent(content) | |
{ | |
if (!content) { | |
return; | |
} | |
content = content.replace(/console.debug/g, ''); | |
content = content.replace(/console.log/g, ''); | |
return content; | |
} | |
function removeUnimportantLogCallsFromFile(file) | |
{ | |
var fs = require('fs'); | |
var resourceContent = fs.readFileSync(file).toString(); | |
var replacedContent = removeUnimportantLogCallsFromContent(resourceContent); | |
fs.writeFileSync(file, replacedContent); | |
} | |
function isJsFile(filename) | |
{ | |
return (filename.match(/\.js$/)); | |
} | |
function removeUnimportantLogCallsFromJsFiles(dir) | |
{ | |
var path = require('path'); | |
var wrench = require('wrench'); | |
var resourcesPath = dir.resources; | |
wrench.readdirSyncRecursive(resourcesPath).forEach(function(target) { | |
if (!isJsFile(target)) { | |
return; | |
} | |
var jsFile = path.join(resourcesPath, target); | |
removeUnimportantLogCallsFromFile(jsFile); | |
}); | |
} | |
task("post:compile", function(event, logger) { | |
if (isProduction(event.alloyConfig)) { | |
logger.info("Removing Unimportant Log Calls"); | |
removeUnimportantLogCallsFromJsFiles(event.dir); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment