Last active
November 8, 2017 02:12
-
-
Save tsteur/5745279 to your computer and use it in GitHub Desktop.
Simple build configuration file for Titanium Mobile Alloy to remove unimportant log calls if build type is production
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