Cordova hook and access to build settings

余生长醉 提交于 2020-08-09 13:37:07

问题


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

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.

Is this at all possible?


回答1:


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": {...}
}

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.



来源:https://stackoverflow.com/questions/47236115/cordova-hook-and-access-to-build-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!