Skip to content

Instantly share code, notes, and snippets.

@TheWass
Created December 21, 2017 21:51
Show Gist options
  • Save TheWass/1792e4244e2b0e0eb48a51ef0bfba5d0 to your computer and use it in GitHub Desktop.
Save TheWass/1792e4244e2b0e0eb48a51ef0bfba5d0 to your computer and use it in GitHub Desktop.
#!/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