05. 使用 cordova plugman 編輯和添加插件

安裝 Plugman

$ npm install -g plugman

你必須在你的 PATH 上有 git来惧,才能直接從遠(yuǎn)程 git url 安裝插件及塘。

添加 Plugin

$ plugman install --platform <ios|android> --project <directory> --plugin <name|url|path> [--plugins_dir <directory>] [--www <directory>] [--variable <name>=<value> [--variable <name>=<value> ...]]

$ plugman install
--platform <ios|android>
--project <directory> 項(xiàng)目所在目錄
--plugin <name|url|path> 此存儲(chǔ)庫的內(nèi)容將復(fù)制到--plugins_dir
[--plugins_dir <directory>] 默認(rèn)為<project>/cordova/plugins
[--www <directory>] 默認(rèn)為項(xiàng)目的www, used as cordova project application web assets.
[--variable <name>=<value> [--variable <name>=<value> ...]]

Parameters:

  • platform <platform>: One of android, ios, blackberry10, wp8, or windows8
  • project <directory>: Path reference to a cordova-generated project of the platform you specify
  • plugin <plugin>: One of a path reference to a local copy of a plugin, or a remote https: or git: URL pointing to a cordova plugin (optionally append #branch:subdir) or a plugin ID from http://plugins.cordova.io
  • variable NAME=VALUE: Some plugins require install-time variables to be defined. These could be things like API keys/tokens or other app-specific variables.
    Optional parameters:
  • www <directory>: www assets for the plugin will be installed into this directory. Default is to install into the standard www directory for the platform specified
  • plugins_dir <directory>: a copy of the plugin will be stored in this directory. Default is to install into the <project directory>/plugins folder
  • searchpath <directory>: when looking up plugins by ID, look in this directory and each of its subdirectories for the plugin before hitting the registry.
    Multiple search paths can be used by either specifying the flag multiple times, or by separating paths with a delimiter (: on 'nix, ; on Windows).

例如安裝核心插件的示例:

  • cordova-plugin-battery-status
    plugman install --platform <ios|android> --project <directory> --plugin cordova-plugin-battery-status
  • cordova-plugin-camera
    plugman install --platform <ios|android> --project <directory> --plugin cordova-plugin-camera

Uninstall a plugin 卸載插件

$ plugman uninstall --platform <ios|android> --project <directory> --plugin <id> [--www <directory>] [--plugins_dir <directory>]

$ plugman uninstall
--platform <ios|android>
--project <directory>
--plugin <id>
[--www <directory>]
[--plugins_dir <directory>]

  • platform <platform>: One of android, ios, blackberry10, wp8, or windows8
  • project <directory>: Path reference to a cordova-generated project of the platform you specify
  • plugin <plugin-id>: The plugin to remove, identified by its id (see the plugin.xml's <plugin id> attribute)

Create A Plugin 創(chuàng)建插件

$ plugman create --name <pluginName> --plugin_id <pluginID> --plugin_version <version> [--path <directory>] [--variable NAME=VALUE]

Parameters:

  • <pluginName>: The name of the plugin
  • <pluginID>: An ID for the plugin, ex: org.bar.foo
  • <version>: A version for the plugin, ex: 0.0.1
  • <directory>: An absolute or relative path for the directory where the plugin project will be created
  • variable NAME=VALUE: Extra variables such as description or Author

例如我$ plugman create --name MyPluginName --plugin_id cordova-plugin-my --plugin_version 0.0.1

Javascript 接口提供了面向前端的接口矛物,但是你需要調(diào)用 cordova.exec 與本地平臺(tái)通信介牙,使用以下語法:

示例一: 官網(wǎng)示例

window.echo = function(str, callback) {
    cordova.exec(callback, function(err) {
        callback('Nothing to echo.');
    }, "Echo", "echo", [str]);
};

示例二: 自定義plugin生成

var exec = require('cordova/exec');

exports.coolMethod = function (arg0, success, error) {
    exec(success, error, 'MyPluginName', 'coolMethod', [arg0]);
};

示例三: device.js

cordova.define("cordova-plugin-device.device", function(require, exports, module) {
  var exec = require('cordova/exec');
  ...
  module.exports = new Device();

Add a Platform to a Plugin

$ plugman platform add --platform_name <platform>
Parameters:

  • <platform>: One of android, ios

必須在 cd platform directory 該級(jí)目錄后操作

Add a Package.JSON file to plugin

Creates a package.json file in the plugin based on values from plugin.xml.
$ plugman createpackagejson <directory>

Building a Plugin 構(gòu)建插件

想這樣
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git

添加插件房待,調(diào)用定位

cordova plugin add C:\Users\HD\GaoDeLocation

$ plugman -help
plugman manages plugin.xml-compatible cordova plugins into cordova-generated projects.

Usage

To display this help file, use one of the following:

$ plugman --help
$ plugman -h

To display the plugman version, use one of the following:

 $ plugman --version
 $ plugman -v

Optional flags

--debug|-d : Verbose mode

Install a plugin

$ plugman install --platform <platform> --project <directory> --plugin <plugin> [--variable NAME=VALUE]

Parameters:

  • platform <platform>: One of android, ios, blackberry10, wp8, or windows8
  • project <directory>: Path reference to a cordova-generated project of the platform you specify
  • plugin <plugin>: One of a path reference to a local copy of a plugin, or a remote https: or git: URL pointing to a cordova plugin (optionally append #branch:subdir) or a plugin ID from http://plugins.cordova.io
  • variable NAME=VALUE: Some plugins require install-time variables to be defined. These could be things like API keys/tokens or other app-specific variables.

Optional parameters:

  • www <directory>: www assets for the plugin will be installed into this directory. Default is to install into the standard www directory for the platform specified
  • plugins_dir <directory>: a copy of the plugin will be stored in this directory. Default is to install into the <project directory>/plugins folder
  • searchpath <directory>: when looking up plugins by ID, look in this directory and each of its subdirectories for the plugin before hitting the registry.
    Multiple search paths can be used by either specifying the flag multiple times, or by separating paths with a delimiter (: on 'nix, ; on Windows).

卸載 plugin

$ plugman uninstall --platform <platform> --project <directory> --plugin <plugin-id>

Parameters:

  • platform <platform>: One of android, ios, blackberry10, wp8, or windows8
  • project <directory>: Path reference to a cordova-generated project of the platform you specify
  • plugin <plugin-id>: The plugin to remove, identified by its id (see the plugin.xml's <plugin id> attribute)

Interacting with the registry

NOTICE: The Cordova Plugin registry became read-only, so the following commands have been deprecated and removed:

$ plugman adduser
$ plugman publish
$ plugman unpublish
$ plugman owner add/rm

For managing plugins for the npm registry, use corresponding npm commands. For more info on npm commands see npm help <command>.
Learn more about publishing your plugins to npm at http://plugins.cordova.io/npm/developers.html

Search for a plugin

$ plugman search <keyword1 keyword2 ...>

Display plugin information

$ plugman info <pluginID>

Manage registry configuration

Display current configuration settings:

$ plugman config ls

Display the current registry URL:

$ plugman config get registry

Set registry URL:

$ plugman config set registry <url>

Example:

$ plugman config set registry http://localhost:5984/registry/_design/app/_rewrite

Manage Owners

Plugin owners are allowed to publish updates to a plugin. To display a list of owners for a plugin, use:

$ plugman owner ls <pluginID>

Example:

$ plugman owner ls org.apache.cordova.core.file

Create A Plugin

$ plugman create --name <pluginName> --plugin_id <pluginID> --plugin_version <version> [--path <directory>] [--variable NAME=VALUE]

Parameters:

  • <pluginName>: The name of the plugin
  • <pluginID>: An ID for the plugin, ex: org.bar.foo
  • <version>: A version for the plugin, ex: 0.0.1
  • <directory>: An absolute or relative path for the directory where the plugin project will be created
  • variable NAME=VALUE: Extra variables such as description or Author

Add a Package.JSON file to plugin

Creates a package.json file in the plugin based on values from plugin.xml.

$ plugman createpackagejson <directory>

Add a Platform to a Plugin

$ plugman platform add --platform_name <platform>

Parameters:

  • <platform>: One of android, ios

Remove a Platform from a Plugin

$ plugman platform remove --platform_name <platform>

Parameters:

  • <platform>: One of android, ios
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末柬脸,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子妄均,更是在濱河造成了極大的恐慌柱锹,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,427評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件丰包,死亡現(xiàn)場(chǎng)離奇詭異奕纫,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)烫沙,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,551評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來隙笆,“玉大人锌蓄,你說我怎么就攤上這事〕湃幔” “怎么了瘸爽?”我有些...
    開封第一講書人閱讀 165,747評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長铅忿。 經(jīng)常有香客問我剪决,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,939評(píng)論 1 295
  • 正文 為了忘掉前任柑潦,我火速辦了婚禮享言,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘渗鬼。我一直安慰自己览露,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,955評(píng)論 6 392
  • 文/花漫 我一把揭開白布譬胎。 她就那樣靜靜地躺著差牛,像睡著了一般。 火紅的嫁衣襯著肌膚如雪堰乔。 梳的紋絲不亂的頭發(fā)上偏化,一...
    開封第一講書人閱讀 51,737評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音镐侯,去河邊找鬼侦讨。 笑死,一個(gè)胖子當(dāng)著我的面吹牛析孽,可吹牛的內(nèi)容都是我干的搭伤。 我是一名探鬼主播,決...
    沈念sama閱讀 40,448評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼袜瞬,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼怜俐!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起邓尤,我...
    開封第一講書人閱讀 39,352評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤拍鲤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后汞扎,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體季稳,經(jīng)...
    沈念sama閱讀 45,834評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,992評(píng)論 3 338
  • 正文 我和宋清朗相戀三年澈魄,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了景鼠。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,133評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡痹扇,死狀恐怖铛漓,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情鲫构,我是刑警寧澤浓恶,帶...
    沈念sama閱讀 35,815評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站结笨,受9級(jí)特大地震影響包晰,放射性物質(zhì)發(fā)生泄漏湿镀。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,477評(píng)論 3 331
  • 文/蒙蒙 一伐憾、第九天 我趴在偏房一處隱蔽的房頂上張望勉痴。 院中可真熱鬧,春花似錦塞耕、人聲如沸蚀腿。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,022評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽莉钙。三九已至,卻和暖如春筛谚,著一層夾襖步出監(jiān)牢的瞬間磁玉,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,147評(píng)論 1 272
  • 我被黑心中介騙來泰國打工驾讲, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留蚊伞,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,398評(píng)論 3 373
  • 正文 我出身青樓吮铭,卻偏偏與公主長得像时迫,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子谓晌,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,077評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容