Using Plugman to Manage Plugins

Using Plugman to Manage Plugins

From version 3.0 onward, Cordova implements all device APIs as plugins, and leaves them disabled by default. It also supports two different ways to add and remove plugins. The first is by using the cordova CLI described in The Command-Line Interface. The second is by using a lower-level Plugman command-line interface ("Native platform dev" workflow.) The main difference between these two development paths is that Plugman can only add plugins to one platform at a time, whereas the CLI will add plugins to all of the platforms that you are targeting. Because of this, it makes more sense to use Plugman when you are working closely with a single platform, hence the "Native Platform Dev" name of the workflow.

For more information on Plugman, especially if you are interested in consuming Plugman as a node module or hacking on the Plugman code, see the README file in its repository.

Installing Plugman

To install plugman, you must have node installed on your machine. Then you can run the following command from anywhere in your environment to install plugman globally, so that it is available from any directory on your machine:

$ npm install -g plugman

You must have also have git on your PATH to be able to install plugins directly from remote git URLs.

TIP: If you find that after installing plugman with npm you are still unable to run any plugman commands, make sure that you have added the /npm/ directory into your PATH.

NOTE: You can skip this step if you don't want to pollute your global npm namespace by installing Plugman globally. If this is the case, then when you create a Cordova project with the shell tools, there will be a node_modules directory inside your project which contains Plugman. Since you did not instally globally, you will have to invoke node for every Plugman command, for example node ./node_modules/plugman/main.js -version. The rest of this guide assumes you have installed Plugman globally, meaning you can invoke it with just plugman.

Create a Cordova Project

Before you can use Plugman, you must create a Cordova project. You can do this with either the Command-line Interface or with the lower level shell scripts. Instructions for using the shell scripts to create your project are located in the various "Command-line Tools" guides listed on the Platform Guides page.

Adding a Plugin

Once you have installed Plugman and have created a Cordova project, you can start adding plugins to the platform with:

$ plugman --platform <ios|amazon-fireos|android|blackberry10|wp7|wp8> --project <directory> --plugin <name|url|path> [--plugins_dir <directory>] [--www <directory>] [--variable <name>=<value> [--variable <name>=<value> ...]]

Using minimum parameters, this command installs a plugin into a cordova project. You must specify a platform and cordova project location for that platform. You also must specify a plugin, with the different --plugin parameter forms being:

Other parameters:

Remove a Plugin

To uninstall a plugin, you simply pass the --uninstall flag and provide the plugin ID.

$ plugman --uninstall --platform <ios|amazon-fireos|android|blackberry10|wp7|wp8> --project <directory> --plugin <id> [--www <directory>] [--plugins_dir <directory>]

Help Commands

Plugman features a global help command which may help you if you get stuck or are experiencing problems. It will display a list of all available Plugman commands and their syntax:

plugman -help
plugman  # same as above

NOTE: plugman -help may show some additional registry-related commands. These commands are for plugin developers and may not be implemented on third-party plugin registries.

You can also append the --debug|-d flag to any Plugman command to run that command in verbose mode, which will display any internal debugging messages as they are emitted and may help you track down problems like missing files.

# Adding Android battery-status plugin to "myProject":
plugman -d --platform android --project myProject --plugin org.apache.cordova.battery-status

Finally, you can use the --version|-v flag to see which version of Plugman you are using.

plugman -v

Registry Actions

There are a number of plugman commands that can be used for interacting with the Plugin registry. Please note that these registry commands are specific to the plugins.phonegap.com plugin registry and may not be implemented by third-party plugin registries.

Searching for a Plugin

You can use Plugman to search the Plugin registry for plugin id's that match the given space separated list of keywords.

plugman search <plugin keywords>

Changing the Plugin Registry

You can get or set the URL of the current plugin registry that plugman is using. Generally you should leave this set at http://registry.phonegap.com unless you want to use a third party plugin registry.

plugman config set registry <url-to-registry>
plugman config get registry

Get Plugin Information

You can get information about any specific plugin stored in the plugin repository with:

plugman info <id>

This will contact the plugin registry and fetch information such as the plugin's version number.

Installing Core Plugins

The examples below show how to add plugins as needed so that any Cordova APIs you use in your project still work after you upgrade to version 3.0. For each command, you need to select the target platform, and reference the platform's project directory.