Cordova钩子并访问构建设置 [英] Cordova hook and access to build settings

查看:176
本文介绍了Cordova钩子并访问构建设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在对Cordova
进行钩挂时,例如 before_build / before_prepare

During a hook for Cordova on for example before_build/before_prepare:

cordova build
-> before prepare hook
-> prepare
-> after prepare hook
-> before build hook
-> build
-> after build hook

是否可以获取有关构建的设置?如果是发行版本或开发版本,或者当前平台是'ios'或'android'或其他任何原因。

Is it possible to obtain settings about the build? If it's a release build or a development build, if the current platform is 'ios' or 'android' or anything else for that matter.

这完全可能吗?

推荐答案

是的,完全有可能像文档。您的hook(-function)传递了一个 context 对象,其中包含您需要的所有信息。示例上下文

Yes it is possible exactly like mentioned in the documentation. Your hook(-function) gets passed a context object which contains all the information you need. Example context:

{
  "hook": "before_plugin_install",
  "scriptLocation": "c:\\script\\full\\path\\appBeforePluginInstall.js",
  "cmdLine": "The\\exact\\command\\cordova\\run\\with arguments",
  "opts": {
    "projectRoot":"C:\\path\\to\\the\\project",
    "cordova": {
      "platforms": ["android"],
      "plugins": ["plugin-withhooks"],
      "version": "0.21.7-dev"
    },
    "plugin": {
      "id": "plugin-withhooks",
      "pluginInfo": {
        ...
      },
      "platform": "android",
      "dir": "C:\\path\\to\\the\\project\\plugins\\plugin-withhooks"
    }
  },
  "cordova": {...}
}

尤其是 cmdLine 属性将使您感兴趣,以检查是否传递了-release 标志并检测构建了哪个平台。

Especially the cmdLine property will be of interest for you to check if a --release flag was passed and to detect which platform was built.

这篇关于Cordova钩子并访问构建设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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