PhoneGap 09 使用Plugman管理Plugins

来源:互联网 发布:三菱plc步进编程实例 编辑:程序博客网 时间:2024/05/19 02:19

从3.0开始,Cordova通过插件实现了所有的设备API,但是默认情况下是不启用的。这里有两种不同的方式增加或者移除插件。第一种方式是使用Cordova CLI,第二种方式是使用低级的 Plugman命令行接口,这两种方式的主要区别是Plugman一次只能增加一个平台,而CLI可以一次增加所需要的所有平台。由于这个原因,当你是在单平台进行开发的坏时候,使用Plugman是比较好的。而其他的情况使用CLI比较好。

更多关于Plugman的信息可以参考PhoneGap的readme文件

安装Plugman

为了安装Plugman,在你的电脑中必须安装有node。然后你可以运行下面的命令去安装Plugman。

$ npm install -g plugman
为了直接从远程安装Plugins,在你的电脑的环境变量中必须有 git 环境变量

注意:当你安装了plugman之后始终无法运行plugman命令,请确保增加了 npm 目录到环境变量中。

    创建一个Cordova项目

在使用Plugman之前,必须先创建一个项目:

$ phonegap create hello com.example.hello Hello  

增加一个插件

一旦已经安装了plugman,并且创建了一个项目,就可以开始向平台里面增加插件了,如下所示:

$ 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> ...]]

使用上面的参数,这个命令可以安装一个插件到一个平台。你必须指定 --platform、--project及--plugin参数,--plugin的name、url和path说明如下:

  • name:插件的目录名称必须存在。这个必须在--plugins_dir下面或者在cordova注册的一个插件存在的目录。
  • url:以https:// 或者 git://开头的,指向一个有用的、包含plugin.xml的git仓库,这个仓库里面的内容必须能够复制到--plugins_dir里面去。
  • path:包含一个有用的、包含plugin.xml的插件目录。该目录的内容可以复制到--plugins_dir里面去
其他的参数:
  • --plugins_dir:默认是 <project>/cordova/plugins,但是可以是任何包含plugins子目录的目录
  • --www: 默认是项目的www文件夹地址,但是也可以是任何包含一个web项目资源的目录
  • --variable:在安装的时候允许指明一个变量。
删除一个插件
为了卸载一个插件,你可以简单的使用--uninstall标识和提供一个plugin ID就可以了,如下:
$ plugman --uninstall --platform <ios|amazon-fireos|android|blackberry10|wp7|wp8> --project <directory> --plugin <id> [--www <directory>] [--plugins_dir <directory>]

帮助命令
使用下面的命令可以得到plugman的所有可用帮助:
plugman -helpplugman  # same as above

注册行为(Actions)
plugman中有许多与插件注册(Plugin registry)相关的命令,请注意,这些注册命令是指明用于plugins.phonegap.com才插件的,第三方实现的插件不能使用。

搜索一个插件
你可以使用plugman去搜索注册了的插件,通过,如下:
plugman search <plugin keywords>
改变一个插件的注册
你可以使用plugman去获得或者设置一个插件的URL,如下:
plugman config set registry <url-to-registry>plugman config get registry

获取插件信息
你可以使用get命令获取特定id插件的信息,如下:
plugman info <id>
安装核心插件
下面是一些核心插件的安装命令:
cordova-plugin-battery-statusplugman --platform  --project  --plugin org.apache.cordova.battery-statuscordova-plugin-camera plugman --platform  --project  --plugin org.apache.cordova.cameracordova-plugin-console plugman --platform  --project  --plugin org.apache.cordova.consolecordova-plugin-contacts plugman --platform  --project  --plugin org.apache.cordova.contactscordova-plugin-device plugman --platform  --project  --plugin org.apache.cordova.devicecordova-plugin-device-motion (accelerometer) plugman --platform  --project  --plugin org.apache.cordova.device-motioncordova-plugin-device-orientation (compass) plugman --platform  --project  --plugin org.apache.cordova.device-orientationcordova-plugin-dialogs plugman --platform  --project  --plugin org.apache.cordova.dialogscordova-plugin-file plugman --platform  --project  --plugin org.apache.cordova.filecordova-plugin-file-transfer plugman --platform  --project  --plugin org.apache.cordova.file-transfercordova-plugin-geolocation plugman --platform  --project  --plugin org.apache.cordova.geolocationcordova-plugin-globalization plugman --platform  --project  --plugin org.apache.cordova.globalizationcordova-plugin-inappbrowser plugman --platform  --project  --plugin org.apache.cordova.inappbrowsercordova-plugin-media plugman --platform  --project  --plugin org.apache.cordova.mediacordova-plugin-media-capture plugman --platform  --project  --plugin org.apache.cordova.media-capturecordova-plugin-network-information plugman --platform  --project  --plugin org.apache.cordova.network-informationcordova-plugin-splashscreen plugman --platform  --project  --plugin org.apache.cordova.splashscreencordova-plugin-vibration plugman --platform  --project  --plugin org.apache.cordova.vibration

原文链接:Using Plugman to Manage Plugins

0 0
原创粉丝点击