Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Parameters to Cordova-CLI Hook Scripts?

Is there a way to pass in command parameters to a Cordova-CLI hook script? Specifically I want to skin an application for a few clients and I would like to copy in their specific settings before the build by passing in an id number or something.

like image 908
RiddlerDev Avatar asked Jan 28 '14 22:01

RiddlerDev


1 Answers

You can access parameters passed to cordova hooks via environment variables. You can set an environment variable that will stay 'alive' for the current session.

For example, if we have a variable called 'TARGET':

Windows cmd:

SET TARGET=someValue
cordova build android

Powershell:

$env:TARGET = "someValue"
iex "cordova build android"

You can then access these environment variables in your hooks with the following syntax (this is assuming you are writing your hooks with node.js):

var target = "someDefaultValue";

// Check for existence of the environment variable
if (process.env.TARGET) {

    // Log the value to the console
    console.log('process.env.TARGET is set to: ' + process.env.TARGET);

    // Override the default
    target = process.env.TARGET;
}

// Log the set value
console.log('Target is set to: ' + target);
like image 150
Steven Anderson Avatar answered Sep 20 '22 09:09

Steven Anderson