Search code examples
cordovaionic-frameworkphonegap

How to exit a "cordova build" command from a hook?


I use Cordova with a hook on after_prepare. I want to exit if the command is not correct.

For example, this command is correct :

cordova run android --ENV=PRD

This one is incorrect and I want the lifecycle of Cordova be interrupted :

cordova run android --ENV=AEZAZEZ

My hook looks like :

module.exports = function(ctx) {

var env     = ctx.opts.options.ENV;

if ( !CONFIG[env] ) {
    // there is a problem in the CLI, I want to exit

} else {

How to modify a hook to exit from Cordova run command ?


Solution

  • Throw an unhandled exception:

    if ( !CONFIG[env] ) {
        throw "there is a problem in the CLI, I want to exit";
    }