jviotti
jviotti

Reputation: 18909

Cordova plugin development workflow

When building an Hybrid iOS Cordova application (relying on Cordova CLI) I stumbled the need to build a custom plugin.

My workflow was the following:

  1. I scaffolded my Cordova plugin outside my Hybrid Application directory.
  2. Code it blindly (in Vim) and push to GitHub.
  3. Use cordova plugin rm and cordova plugin add to reinstall the plugin.
  4. Test.
  5. Repeat from step 2.

I deployed the plugin successfully in the product, however this process of coding Objective C blindly with Vim and doing a whole push to GitHub just to test it in my project feels awkward, however I couldn't find any information on the internet about a better workflow.

Ideally, this is the workflow I'd expect:

  1. Scaffold my plugin inside my application directory (maybe in plugins/ or in my custom src/) and publish when I'm ready to do so (or not publish closed-source plugins at all).
  2. Code the plugin using XCode.
  3. Reinstall the plugin from the local filesystem, this totally avoiding a separate repo/push.
  4. Test and iterate from step 2.

Is this workflow achievable?

Upvotes: 3

Views: 313

Answers (2)

andreimarinescu
andreimarinescu

Reputation: 3641

Personally, I've used the same approach, with a twist:

Step 1:

I've coded the boilerplate part of the plugin using Sublime Text (vim works as well :) )

Step 2:

cordova plugin add --link ../path_to_my_plugin

Step 3:

I can add the platforms/android to Android Studio (you should be able to do the same with platforms/ios)

Step 4:

Any changes to the native part are reflected in the original sources (because of the --link parameter), any changes needed to the js part of the plugin I can edit directly in the app directory itself

Step 5:

Commit and push the files in your original plugin directory

If you need to reconfigure some part of the boilerplate (plugin.xml configurations), I've just:

cordova plugin remove <plugin-name>

And then resumed from step 2

Upvotes: 1

Vlad Stirbu
Vlad Stirbu

Reputation: 1792

You could try the following workflow:

  1. have the plugin in a specific directory within the project
  2. have a grunt task that watches for changes in the above directory that copies the relevant files to the plugins directory and runs cordova prepare right after the copy step is complete
  3. edite and test...

Upvotes: 1

Related Questions