Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova CLI, using Git, and saving plugins/platforms

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?

like image 795
runlevelsix Avatar asked Feb 14 '14 23:02

runlevelsix


People also ask

What is the Cordova CLI used for?

This guide shows you how to create applications and deploy them to various native mobile platforms using the cordova command-line interface (CLI). This tool allows you to create new projects, build them on different platforms, and run on real devices or within emulators.

What are the different platforms supported by Cordova?

Cordova-Android requires the Android SDK, which can be installed on either macOS, Linux, or Windows.

Which command is used to install plugin in Cordova?

The cordova plugin add command requires you to specify the repository for the plugin code. Please note that when you follow the Web Project Dev workflow and use the CLI, the CLI will take care of adding the plugin code to the appropriate place for each platform.


2 Answers

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.

like image 146
Nikolai Samteladze Avatar answered Sep 29 '22 15:09

Nikolai Samteladze


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!

like image 22
mooreds Avatar answered Sep 29 '22 16:09

mooreds