Plugin Authoring
PhoneGap Day SF 2014
Jesse MacFadyen
aka @purplecabbage
About Me
- PhoneGap developer since 2008
- Can't believe it's been that long.
- Just moved to San Francisco, from Vancouver
Who has used cordova plugins?
- Everyone, you have to now.
- Since 3.0, more than a year ago
// Install via registry
cordova plugin add org.apache.cordova.device
cordova plugin rm org.apache.cordova.device
// OR via local
cordova plugin add Repos/cordova/cordova-plugin-device
cordova plugin ls
cordova plugin rm org.apache.cordova.device
// OR github
cordova plugin add http://github.com/apache/cordova-plugin-device
cordova plugin ls
cordova plugin rm org.apache.cordova.device
Who has used plugman
- Everyone, you have to now, but you may not even know you are.
- Plugman is a node lib that does the dirty work of managing plugins
- cordova-cli uses plugman
plugman install --plugin org.apache.cordova.device --platform wp8
--project .
The 'core' plugins
- battery-status
- camera
- console
- contacts
- device
- device-motion
- device-orientation
- dialogs
- file
- file-transfer
- ... some others, more to come ...
Plugin Discovery
- http://plugins.cordova.io/
- http://plugreg.com/plugins
- https://build.phonegap.com/plugins
Plugin Authoring
plugin.xml defines your plugin
- a plugin id for registration, add/rm
- a version number, author, repo, similar to package.json
- a list of platforms and native headers, source files, resources, javascript files
- configuration items, permission requirements
- js-modules - the js entry point for your plugin
Plugman can help!
Create A Plugin
---------------
$ plugman create --name --plugin_id --plugin_version [--path ] [--variable NAME=VALUE]
Parameters:
- : A Name for a Plugin
- : An ID for the plugin, ex: org.bar.foo
- : A version for the plugin, ex: 0.0.0
- variable NAME=VALUE: Extra variables such as description or Author
plugman create --name rapture --plugin_id com.risingj.phonegap.rapture --plugin_version 0.0.1 --path .
Demo : rapture
Save a screenshot of the app to the photo-roll
Demo: Debugging a plugin
Involving an IDE, XCode or Visual Studio
Docs, Tests, and all that
- Of course you should include docs, so users know how to use your plugin. Look at any of the 'core' plugins for best practices.
- Tests can be written in Jasmine 2.0, all core plugins have adopted a strategy of having a dependent -test plugin which is installed separately and runs your tests
Questions?
twitter.com/purplecabbage
One more thing, or a few ...
- Some platforms support plugins that are separate projects
- Some plugins reference third party libraries.
- Lots to discover with plugin hooks, for when you need to do extra work when the plugin is installed, or the project is being built.