I'm making a Cordova plugin and I'd like to be able to have a --variable VARIABLE="someValue"
in the plugin installation.
I have an after_prepare script within my plugin.xml
.
plugin.xml
<preference name="VARIABLE" default="defaultValue" />
<hook src="script.js" type="after_prepare" />
Usage of plugin would look like this:
cordova plugin add pluginsource.git --fetch --variable VARIABLE="customvalue"
Inside the script.js, how can I reference the value of that variable (so I see "customvalue") if the user chose to use that variable when installing?
Your variable and arguments will be present in process.argv
as the cordova cli is a nodejs tool.
console.log(process.argv)
should provide you with an array of strings included in the platform add
command use.
An example plugin which uses variables in after-prepare.js is the cordova facebook plugin