05. 使用 cordova plugman 编辑和添加插件

简介: 05. 使用 cordova plugman 编辑和添加插件

安装 Plugman


$ npm install -g plugman


你必须在你的 PATH 上有 git,才能直接从远程 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> 项目所在目录


--plugin <name|url|path>   此存储库的内容将复制到--plugins_dir


[--plugins_dir <directory>]  默认为<project>/cordova/plugins


[--www <directory>] 默认为项目的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 创建插件


$ 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 接口提供了面向前端的接口,但是你需要调用 cordova.exec 与本地平台通信,使用以下语法:


示例一: 官网示例

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 该级目录后操作


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 构建插件


想这样


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


添加插件,调用定位


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


目录
相关文章
|
6月前
|
前端开发 JavaScript PHP
【vscode编辑器插件】前端 php unity自用插件分享
【vscode编辑器插件】前端 php unity自用插件分享
42 0
|
7月前
|
JSON 小程序 前端开发
小程序使用npm以及常用的移动端UI插件
小程序使用npm以及常用的移动端UI插件
53 0
|
Web App开发 JavaScript 前端开发
推荐几个 vscode开发需要的插件
推荐几个我在开发中使用到的vscode的几个插件:
221 0
|
Web App开发 JavaScript 前端开发
VsCode 常用好用插件/配置+开发Vue 必装的插件
VsCode 常用好用插件/配置+开发Vue 必装的插件
296 0
vscode彻底删除安装过的插件和个人配置信息
vscode彻底删除安装过的插件和个人配置信息
1688 0
vscode彻底删除安装过的插件和个人配置信息
CTK框架 - 将菜单按钮写到插件中
之前我们在的两个插件Core和About,在Core和About中加入了界面,并且Core中插入了一个菜单,点击之后弹出About界面。 我们现在来用之前的知识把菜单改成注册的,并且点击之后弹出About界面。 我这里的思路是使用事件或者是在Core中加注册的服务来注册菜单。之后点击菜单的时候发送事件。
122 0
|
存储 机器学习/深度学习 传感器
vscode 常用的扩展插件有哪些?
VS Code有许多常用的扩展插件,下面是一些常见且受欢迎的扩展插件: 1. Live Server:提供了一个本地开发服务器,可以在编辑器中实时预览和调试HTML、CSS和JavaScript文件。 2. Prettier - Code formatter:自动格式化代码,使其符合一致的编码风格。 3. GitLens — Git supercharged:增强了对Git存储库的操作和视觉化,可以轻松查看文件的Git历史、作者信息以及行级别的注释和更改。 4. ESLint:集成了ESLint静态代码分析工具,用于在编写代码时捕获常见的错误和编码规范问题。 5. Visual St
297 0
|
IDE Java 程序员
没有颜值插件的编辑器是没有灵魂的--【idea-theme插件】
没有颜值插件的编辑器是没有灵魂的--【idea-theme插件】
SVG VSCode 插件(语法提示补全、预览插件)
SVG VSCode 插件(语法提示补全、预览插件)
1493 0
|
Devops
发布vscode插件
发布vscode插件
135 0
发布vscode插件