Created
December 21, 2017 21:51
-
-
Save TheWass/1792e4244e2b0e0eb48a51ef0bfba5d0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env node | |
/** | |
* This cordova hook checks to see if the developer is building a release version, | |
* but not in a production environment. | |
* | |
* Add this to config.xml | |
* <hook src="envcheck.js" type="before_prepare" /> | |
* <hook src="envcheck.js" type="after_build" /> | |
*/ | |
module.exports = function(ctx) { | |
if (ctx.opts.options.release) { | |
var fs = ctx.requireCordovaModule('fs'), | |
path = ctx.requireCordovaModule('path') | |
// Check the environment configuration. | |
// THIS WILL NEED TO BE CUSTOMIZED FOR EVERY PROJECT!! | |
var configFilePath = path.join(ctx.opts.projectRoot, 'src/js/config.js'); | |
var configFileContents = fs.readFileSync(configFilePath, 'utf8'); | |
var buildEnvIsProduction = configFileContents.includes('"env":"production"'); | |
if (!buildEnvIsProduction) { | |
console.error("======================================================================") | |
console.error("======================================================================") | |
console.error("============= WARNING: THIS IS NOT A PRODUCTION BUILD! =============") | |
console.error("======================================================================") | |
console.error("======================================================================") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment