Cordova: Exclude plugins and platforms

23tux

I would like to not include the platforms and plugins in my git repository for my cordova project. Instead, I only include platforms/platforms.json and plugins/fetch.json. My .gitignore looks like this

platforms/**
!platforms/platforms.json
plugins/**
!plugins/fetch.json

This ensures that only the two json files are tracked by git. This is my platforms.json:

{
    "ios": "3.9.1",
    "android": "4.1.1"
}

However, I thought that a cordova prepare would look into the platforms.json and would install the proper version automatically for my project. The same would be very handy for the fetch.json inside the plugins directory. However, I noticed that here no versions, git commit hashes... are tracked, it just looks like this:

"cordova-plugin-console": {
    "source": {
        "type": "registry",
        "id": "cordova-plugin-console"
    },
    "is_top_level": true,
    "variables": {}
}

So my questions are:

  1. Is it best-practise to exclude platforms and plugins from the git repository?
  2. Is there (or will be) a bundler-like way, to lock plugins and platforms to a specific version, and just run a command, and everything gets installed?
  3. What would be a good way, to not include the platforms and plugins directory, and share the project with other developers?
Simon Prickett
  1. I would say yes, so long as you set the versions of the platforms and plugins you want to use - keeping things that the CLI can generate out of source control is a good thing

  2. Yes, you can use the @ notation for example:

    cordova platform add [email protected]

This applies to platforms as well, and each version of the Cordova CLI defaults to a specific version of the Cordova platform unless you override it.

Regarding running a command, I use hooks for this and have a post platform add hook that runs a script that installs all my plugins using the @ notation to get exactly the version I want.

  1. Follow the advice above and you should be able to do this. If you find yourself needing to manually modify anything in platforms folder in your project consider whether you can script this using the available build hooks before adding platforms to the source repository. If you find yourself altering plugins and thinking you need to check those in, then fork the plugin you are using, make your changes in the forked repo and use cordova plugin add to add your version of the plugin from your git repo or a local folder rather than polluting your main Cordova project repo.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related