我正在制作Cordova插件,并且我希望能够在插件安装中拥有--variable VARIABLE="someValue"
。
我的plugin.xml
内有一个after_prepare脚本。
的plugin.xml
<preference name="VARIABLE" default="defaultValue" />
<hook src="script.js" type="after_prepare" />
插件的用法如下所示:
cordova plugin add pluginsource.git --fetch --variable VARIABLE="customvalue"
在script.js中,如果用户在安装时选择使用该变量,我如何引用该变量的值(所以我看到&#34; customvalue&#34;)?
答案 0 :(得分:0)
您的变量和参数将出现在process.argv
中,因为cordova cli是一个nodejs工具。
console.log(process.argv)
应该为您提供platform add
命令使用中包含的字符串数组。
在after-prepare.js中使用变量的示例插件是cordova facebook plugin