Cordova CLI, using Git, and saving plugins/platforms

核能气质少年 提交于 2020-01-01 02:36:05

问题


I'm trying to figure out how to reconcile some Cordova + git "best practices" with what I think is reality, and I'm hoping someone can shed some light on this for me.

If I understand correctly, the current "best practice" is to add these directories to my .gitignore (from the book "Developing with Cordova CLI", the current version):

platforms/
plugins/
node_modules/

This removes the easily downloadable plugins and mostly boilerplate platform code from version control because it can be easily generated with a simple Cordova CLI command.

But, this seems counter-intuitive because - and I'm thinking like NPM or Bower - with the Cordova CLI I can't save which platforms and plugins I'm using in a config file. With NPM, I can add a --save switch to save the package in the package.json file. This allows me to not version control my node_modules folder and instead use 'npm install'. With the Cordova CLI I can't seem to use the --save switch (is there an equivalent) to 'remember' the plugins or platforms I intend to use.

It seems that the config.xml file in the www/ directory doesn't save which platforms or plugins have been added.

Is there some other file in the project that keeps a memory of which platforms and plugins I want to use? How does it work?


回答1:


Cordova 4.3.0 + allows you to save and restore platforms and plugins. Saved information is stored in config.xml file. See v5.0.0 release notes and the official Cordova docs.

You can save platforms and plugins using the --save option when you add them:

cordova platforms add PLATFORM --save
cordova plugins add PLUGIN --save

Or you can save platforms and plugins that are currently added:

cordova platforms save
cordova plugins save

By doing this there is no need to check in platforms or plugins into your code repository. They will be automatically restored based on your config.xml file when cordova prepare command is run.




回答2:


I typically write a hook to capture the plugins I want to use in my project. You can see this in an article I wrote here: http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/

With the new modular architecture of Cordova 3.x, every app needs plugins, even to use basic functionality such as logging or geolocation. Rather than document which plugins/features your project needs and ask each new developer to install them, download and install them automatically with a hook in the after_platform_add step. Using this plugin, every time a developer checks out the project and adds a platform, they automatically have the required plugins.

You also may be interested in following along with this bug, which suggests npm style --save functionality: https://issues.apache.org/jira/browse/CB-5775

Platforms are a little more difficult because they don't fit into the hook architecture, but you could write a shell script which you could execute to add your platforms.

#!/bin/sh
for plat in ios android; do
   cordova platform add $plat
done

You could do something similar with the version of cordova you have installed in node_modules (at least that is what I think you are installing in node_modules)--have shell script to get the correct version of cordova:

#!/bin/sh
VERSION=3.3.1-0.4.2
npm install cordova@$VERSION

PS Glad you liked the book!



来源:https://stackoverflow.com/questions/21791323/cordova-cli-using-git-and-saving-plugins-platforms

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