向Cordova-CLI Hook脚本添加参数? [英] Add Parameters to Cordova-CLI Hook Scripts?

查看:193
本文介绍了向Cordova-CLI Hook脚本添加参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将命令参数传递给Cordova-CLI钩子脚本?具体来说,我想为几个客户端的应用程序皮肤,我想通过传递一个id号或某事,在构建之前在他们的特定设置中复制。

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.

推荐答案

您可以通过环境变量访问传递给cordova钩子的参数。您可以设置一个环境变量,为当前会话保持活动。

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.

例如,如果我们有一个名为TARGET的变量:

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

Windows cmd:

Windows cmd:

SET TARGET=someValue
cordova build android

Powershell:

Powershell:

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

然后,您可以使用以下语法访问这些环境变量假设你使用node.js编写你的钩子):

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);

这篇关于向Cordova-CLI Hook脚本添加参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆