Git Product home page Git Product logo

cordova-plugman's Introduction

plugman

Node CI codecov.io

A command line tool to install and uninstall plugins for use with Apache Cordova projects.

This document defines tool usage.

Requirements

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

Plugin Specification

--> Available on docs.cordova.io <--

Quickstart

npm install -g plugman

Design Goals

  • Facilitate programmatic installation and manipulation of plugins
  • Detail the dependencies and components of individual plugins
  • Allow code reuse between different target platforms

Supported Platforms

  • Amazon Fire OS
  • Android
  • BlackBerry 10
  • iOS
  • Tizen
  • Windows Phone 8
  • Windows 8

Command Line Usage

Display all available plugman commands:

plugman help

Plugin Management

Install a plugin into a Cordova project:

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

Uninstall a Plugin from a Cordova project:

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

For each command (install and uninstall), 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:

  • name: The directory name where the plugin contents exist. This must be an existing directory under the --plugins_dir path (see below for more info) or a plugin in the Cordova registry.
  • url: A URL starting with https:// or git://, pointing to a valid git repository that is clonable and contains a plugin.xml file. The contents of this repository would be copied into the --plugins_dir.
  • path: A path to a directory containing a valid plugin which includes a plugin.xml file. This path's contents will be copied into the --plugins_dir.

Other parameters:

  • --plugins_dir defaults to <project>/cordova/plugins, but can be any directory containing a subdirectory for each fetched plugin.
  • --www defaults to the project's www folder location, but can be any directory that is to be used as cordova project application web assets.
  • --variable allows to specify certain variables at install time, necessary for certain plugins requiring API keys or other custom, user-defined parameters. Please see the plugin specification for more information.

Registry Search

Search the Plugin registry for plugin id's that match the given space separated list of keywords.

plugman search <plugin keywords>

Configuration Management:

Display the current list of configuration settings:

plugman config ls

Display the current repository endpoint:

plugman config get registry

Set the registry endpoint:

plugman config set registry <url-to-registry>

You should leave this set to http://registry.cordova.io, unless you want to use a third party plugin registry.

Node Module Usage

This section details how to consume Plugman as a node module and is only for Cordova tool authors and other hackers. You should not need to read this section if you are just using Plugman to manage a Cordova project.

node
> require('plugman')
{ install: [Function: installPlugin],
  uninstall: [Function: uninstallPlugin],
  fetch: [Function: fetchPlugin],
  search: [Function: search],
  publish: [Function: publish],
  unpublish: [Function: unpublish],
  adduser: [Function: adduser],
  prepare: [Function: handlePrepare],
  create: [Function: create],
  platform: [Function: platform] }

install method

module.exports = function installPlugin(platform, project_dir, id, plugins_dir, subdir, cli_variables, www_dir, callback) {

Installs a plugin into a specified cordova project of a specified platform.

  • platform: one of amazon-fireos, android, ios, blackberry10, or wp8
  • project_dir: path to an instance of the above specified platform's cordova project
  • id: a string representing the id of the plugin, a path to a cordova plugin with a valid plugin.xml file, or an https:// or git:// url to a git repository of a valid cordova plugin or a plugin published to the Cordova registry
  • plugins_dir: path to directory where plugins will be stored, defaults to <project_dir>/cordova/plugins
  • subdir: subdirectory within the plugin directory to consider as plugin directory root, defaults to .
  • cli_variables: an object mapping cordova plugin specification variable names (see plugin specification) to values
  • www_dir: path to directory where web assets are to be copied to, defaults to the specified project directory's www dir (dependent on platform)
  • callback: callback to invoke once complete. If specified, will pass in an error object as a first parameter if the action failed. If not and an error occurs, plugman will throw the error

uninstall method

module.exports = function uninstallPlugin(platform, project_dir, id, plugins_dir, cli_variables, www_dir, callback) {

Uninstalls a previously-installed cordova plugin from a specified cordova project of a specified platform.

  • platform: one of amazon-fireos, android, ios, blackberry10, or wp8
  • project_dir: path to an instance of the above specified platform's cordova project
  • id: a string representing the id of the plugin
  • plugins_dir: path to directory where plugins are stored, defaults to <project_dir>/cordova/plugins
  • subdir: subdirectory within the plugin directory to consider as plugin directory root, defaults to .
  • cli_variables: an object mapping cordova plugin specification variable names (see plugin specification) to values
  • www_dir: path to directory where web assets are to be copied to, defaults to the specified project directory's www dir (dependent on platform)
  • callback: callback to invoke once complete. If specified, will pass in an error object as a first parameter if the action failed. If not and an error occurs, plugman will throw the error

fetch method

Copies a cordova plugin into a single location that plugman uses to track which plugins are installed into a project.

module.exports = function fetchPlugin(plugin_dir, plugins_dir, link, subdir, git_ref, callback) {
  • plugin_dir: path, URL to a plugin directory/repository or name of a plugin published to the Cordova registry.
  • plugins_dir: path housing all plugins used in this project
  • link: if plugin_dir points to a local path, will create a symbolic link to that folder instead of copying into plugins_dir, defaults to false
  • subdir: subdirectory within the plugin directory to consider as plugin directory root, defaults to .
  • gitref: if plugin_dir points to a URL, this value will be used to pass into git checkout after the repository is cloned, defaults to HEAD
  • callback: callback to invoke once complete. If specified, will pass in an error object as a first parameter if the action failed. If not and an error occurs, plugman will throw the error

prepare method

Finalizes plugin installation by making configuration file changes and setting up a JavaScript loader for js-module support.

module.exports = function handlePrepare(project_dir, platform, plugins_dir) {
  • project_dir: path to an instance of the above specified platform's cordova project
  • platform: one of amazon-fireos, android, ios, blackberry10, or wp8
  • plugins_dir: path housing all plugins used in this project

Registry related actions

adduser method

Adds a user account to the registry. Function takes no arguments other than a an optional callback

module.exports = function(callback) {

publish method

Publishes plugins to the registry. plugin_paths is an array of plugin paths to publish to the registry.

module.exports = function(plugin_paths, callback) {

unpublish method

unpublishes plugins from the registry. Can unpublish a version by specifying plugin@version or the whole plugin by just specifying plugin. plugins is an array of plugin[@version] elements.

module.exports = function(plugins, callback) {

search method

Searches plugins in the registry. search_opts is an array of keywords

module.exports = function(search_opts, callback) {

config method

Configures registry settings. params is an array that describes the action /* * var params = ['get', 'registry']; * var params = ['set', 'registry', 'http://registry.cordova.io']; * module.exports = function(params, callback) { */

Create plugin related actions

create method

Creates basic scaffolding for a new plugin

module.exports = function create( name, id, version, pluginPath, options, callback ) {...}

  • name : a name for the plugin
  • id : an id for the plugin
  • version : a version for the plugin
  • pluginPath : a path to create the plugin in
  • options : an array of options
  • callback : callback to invoke once complete. If specified, will pass in an error object as a first parameter if the action failed. If not and an error occurs, plugman will throw the error

platform method

Add/Remove a platform from a newly created plugin

module.exports = function platform( { operation: operation, platform_name: cli_opts.platform_name } );

  • operation : "add or remove"
  • platform_name : ios, android

Example Plugins

Development

Basic installation:

git clone https://git-wip-us.apache.org/repos/asf/cordova-plugman.git
cd cordova-plugman
npm install -g

Linking the global executable to the git repo:

git clone https://git-wip-us.apache.org/repos/asf/cordova-plugman.git
cd cordova-plugman
npm install
sudo npm link

Running Tests

npm test

Plugin Directory Structure

A plugin is typically a combination of some web/www code, and some native code. However, plugins may have only one of these things - a plugin could be a single JavaScript file, or some native code with no corresponding JavaScript.

Here is a sample plugin named foo with android and ios platforms support, and 2 www assets.

foo-plugin/
|- plugin.xml     # xml-based manifest
|- src/           # native source for each platform
|  |- android/
|  |  `- Foo.java
|  `- ios/
|     |- CDVFoo.h
|     `- CDVFoo.m
|- README.md
`- www/
   |- foo.js
   `- foo.png

This structure is suggested, but not required.

Contributors

See the package.json file for attribution notes.

License

Apache License 2.0

cordova-plugman's People

Contributors

agrieve avatar alunny avatar audreyso avatar axelnennker avatar bennmapes avatar breautek avatar bshepherdson avatar clelland avatar cmarcelk avatar dblotsky avatar erisu avatar filmaj avatar goya avatar imhotep avatar jbondc avatar jlongster avatar johnwargo avatar jsoref avatar kamrik avatar mbillau avatar mreinstein avatar mwbrooks avatar purplecabbage avatar raphinesse avatar sgrebnov avatar shazron avatar steckelfisch avatar stevengill avatar timkim avatar xliyong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugman's Issues

`create` with plugin IDs with `-` generates invalid `clobbers`

plugman create --name cordova-plugin-math --plugin_id cordova-plugin-math --plugin_version 0.0.1

leads to

<clobbers target="cordova.plugins.cordova-plugin-math" />

which is invalid.


Fixing manually to cordova.plugins.math or similar fixes the issue.

[Bug] Plugman does not work with latest version of Cordova iOS (5.0.1)

Bug Report

Problem

Plugman does not work with latest version of Cordova iOS (5.0.1), resulting in error:
Failed to install 'cordova-plugin-background-fetch': Error: Your ios platform does not have Api.js
When running:
plugman install --platform ios --project platforms/ios --plugin cordova-background-geolocation-lt

What is expected to happen?

The plugin will install to this specific platform correctly

What does actually happen?

Fails with error:
Failed to install 'cordova-plugin-background-fetch': Error: Your ios platform does not have Api.js

Information

Cordova Version 9.0.0
Cordova iOS version 5.0.1
Plugman version: Latest (unable to check using plugman --version)

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Plugin installation fails with a registry fetch error when run using through `execSync` and npm 8.15.0

Bug Report

Problem

What is expected to happen?

Plugin installation should succeed.

What does actually happen?

Plugin installation fails with a registry fetch error (but the plugin is in the registry). It sometimes succeeds on the second try, as if the first time it didn't wait for the fetch to finish before making sure the plugin exists on disk. Installation of all plugins fails in the same manner, it's not just this one.

Information

Here is the error:

Running command: npm install [email protected] --production --no-save
Command finished with error code 0: npm install,[email protected],--production,--no-save
Failed to fetch plugin [email protected] via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Could not determine package name from output:
added 1 package, removed 1 package, and audited 2 packages in 1s

found 0 vulnerabilities
CordovaError: Failed to fetch plugin [email protected] via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Could not determine package name from output:
added 1 package, removed 1 package, and audited 2 packages in 1s

found 0 vulnerabilities
    at /Users/michael/Projects/Software/Simbioz/Ripple.Base/ripple/rcc/node_modules/.pnpm/[email protected]/node_modules/cordova-lib/src/plugman/fetch.js:146:43
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
node:child_process:915
    throw err;
    ^

Error: Command failed: node_modules/.bin/plugman -d install --platform android --project platforms/android --plugin [email protected] --plugins_dir=plugins
    at checkExecSyncError (node:child_process:841:11)
    at execSync (node:child_process:912:15)
    at /Users/michael/Projects/Software/Simbioz/Ripple.Base/ripple/rcc/scripts/install-plugins.js:29:5
    at arrayEach (/Users/michael/Projects/Software/Simbioz/Ripple.Base/ripple/rcc/node_modules/.pnpm/[email protected]/node_modules/lodash/lodash.js:530:11)
    at Function.forEach (/Users/michael/Projects/Software/Simbioz/Ripple.Base/ripple/rcc/node_modules/.pnpm/[email protected]/node_modules/lodash/lodash.js:9410:14)
    at /Users/michael/Projects/Software/Simbioz/Ripple.Base/ripple/rcc/scripts/install-plugins.js:28:5
    at /Users/michael/Projects/Software/Simbioz/Ripple.Base/ripple/rcc/node_modules/.pnpm/[email protected]/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/Users/michael/Projects/Software/Simbioz/Ripple.Base/ripple/rcc/node_modules/.pnpm/[email protected]/node_modules/lodash/lodash.js:3032:24)
    at Function.forOwn (/Users/michael/Projects/Software/Simbioz/Ripple.Base/ripple/rcc/node_modules/.pnpm/[email protected]/node_modules/lodash/lodash.js:13082:24) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 37257,
  stdout: null,
  stderr: null
}
 ELIFECYCLE  Command failed with exit code 1.

Workaround

It seems like the problem occurs because something goes wrong when plugman uses npm 8.5 while being run by execSync (in a script). If I install npm 6.X locally in the project (npm install --save-dev [email protected]), the plugman script uses that internally and installation succeeds. However, it forces me to downgrade npm to v6 for my whole project instead of staying on npm 8 which is the default for node 16.

Command or Code

execSync(
    `node_modules/.bin/plugman -d install --platform android --project platforms/android --plugin [email protected] --plugins_dir=plugins`,
    { stdio: "inherit" }
);

Environment, Platform, Device

macOS 12.6 (21G115)

Version information

node 16.17.1
npm 8.15.0
plugman 3.0.1
cordova 11.0.0
cordova-android 10.1.2
cordova-ios 6.2.0

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Unable to install plugman

When I try to install plugman with command npm install -g plugman in macOS, it gives error - Unexpected end of JSON input while parsing near '..."3.4.1":{"name":"modu'

Kindly find the entire stacktrace in attached file.

Node: v8.0.0
npm: 5.4.1
cordova: 6.5.0
OS: macOS Sierra

2018-11-22T07_18_01_475Z-debug.log

Documentation is incomplete and outdated

Missing:

Author plugins
    create               Create a plugin
    createpackagejson    Add a package.json file to a plugin
    platform             Add and remove platforms from a plugin

Outdated:

  • all the registry stuff can probably go

Set up CI

Should only be done once we have some tests (#114), so as not to give a wrong sense of security.

`plugman platform add --platform_name windows` generates crashing default

plugman create --name cordova-plugin-math --plugin_id cordova-plugin-math --plugin_version 0.0.1
plugman platform add --platform_name windows

leads to

    <js-module name="cordova-plugin-math" src="www/cordova-plugin-math.js">
        <clobbers target="cordova.plugins.math" />
    </js-module>
    <platform name="windows">
        <js-module name="cordova-plugin-math" src="src/windows/cordova-plugin-math.js">
            <runs target="" />
        </js-module>
    </platform>

Those files being named identical, leads to this exception:

image

SCRIPT5022: Unhandled exception at line 74, column 13 in ms-appx-web://io.cordova.hellocordova/www/cordova.js
0x800a139e - JavaScript runtime error: module cordova-plugin-math.cordova-plugin-math already defined

because both files begin with

cordova.define("cordova-plugin-math.cordova-plugin-math", function(require, exports, module) {

Updating js-module.name to mathProxy (and renaming src/windows/cordova-plugin-math.js to src/windows/mathProxy.js and updating the .src to that) fixes the problem. (Might have to remove and re-add the platform to get rid o the old file though)

command not found: plugman

Bug Report

Problem

What is expected to happen?

Plugman command not recognised after plugman help executed.

What does actually happen?

command not found: plugman

Information

I am planning to create plugin for Android and iOS after following steps from your documentation.

  • npm install -g plugman
  • After successfully installed try to run plugman help : "recived plugman command not found".

Tried with sudo same happening.

Command or Code

plugman help -> command not found.

Environment, Platform, Device

MacOS Catalina 10.15

Version information

Cordova 10.0.0
Plugman 3.0.0
MacOS Catalina 10.15.
Node v15.3.0

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Generated `plugin.xml` is unformatted

plugman create --name cordova-plugin-math --plugin_id cordova-plugin-math --plugin_version 0.0.1
plugman platform add --platform_name windows

results in

<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-plugin-math" version="0.0.1" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android"><name>cordova-plugin-math</name><js-module name="cordova-plugin-math" src="www/cordova-plugin-math.js"><clobbers target="cordova.plugins.cordova-plugin-math" /></js-module><platform name="windows"><js-module name="cordova-plugin-math" src="src/windows/cordova-plugin-math.js"><runs target="" /></js-module></platform></plugin>

`plugman --version` doesn't work

λ plugman --version
Usage: plugman [OPTION]... <command>

These are the available plugman commands:

Manage plugins in a Cordova project
    install              Install a plugin into a Cordova project
    uninstall            Uninstall a plugin from a Cordova project

Author plugins
    create               Create a plugin
    createpackagejson    Add a package.json file to a plugin
    platform             Add and remove platforms from a plugin

Global options:
    --help, -h           Show help for <command> or this if none was given
    --debug, -d          Enable verbose output
    --version, -v        Display the plugman version

real version is 3.0.1

Unable to Add Platform

I am getting this error when ever i am trying to add a platform by

plugman platform add --platform_name android

(node:17948) UnhandledPromiseRejectionWarning: Error: platform: true not yet supported
    at Object.add (E:\cordova-plugman\node_modules\cordova-lib\src\plugman\platform.js:51:35)
    at Object.module.exports [as platform] (E:\cordova-plugman\node_modules\cordova-lib\src\plugman\platform_operation.js:23:38)
    at Object.platform (E:\cordova-plugman\node_modules\cordova-lib\src\plugman\plugman.js:153:17)
    at Object.<anonymous> (E:\cordova-plugman\main.js:87:42)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:694:10)
(node:17948) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:17948) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

NPM 16?

Can't install plugins on NPM 16.

Failed to fetch plugin cordova-clipboard via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Could not determine package name from output:
added 1 package, removed 7 packages, and audited 2 packages in 822ms

cordova-android version not detected - lacks script

Trying to add a new plugin only to android using plugman gives below error :

Installing "cordova-plugin-firebase-messaging" for android
cordova-android version not detected (lacks script <project path>/cordova/version ), continuing.
Plugin doesn't support this project's cordova version. cordova: 9.0.1, failed version requirement: >=10.0.0
Skipping 'cordova-plugin-firebase-messaging' for android

cordova platforms list
Installed platforms:
android 12.0.1
ios 7.0.1

cordova --version
12.0.0 ([email protected])

Mac OS

-www option ignored

Bug Report

Problem

What is expected to happen?

When the -www option is used, plugins should be installed in the given directory instead of the default <project>/cordova/plugins

What does actually happen?

Plugins are still installed in the default directory.

Information

Command or Code

% ls
www myproj

% plugman install --platform ios --proj myproj --plugin cordova-plugin-device --www ./www
% plugman install --platform ios --proj myproj --plugin cordova-plugin-device --www .
% plugman install --platform ios --proj myproj --plugin cordova-plugin-device --www www

Plugins are installed in myproj/cordova/plugins, instead of the local www directory

Environment, Platform, Device

Using platofrm-ios directly, no cordova CLI. Happens with every plugin.

Version information

plugman 3.0.1
cordova-ios 6.2.0
npm 7.20.3
node 16.7.0
macOS 11.6

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Fetch specific commit?

Is there a way to fetch a specific commit? I tried:

plugman install ... --plugin cordova-plugin-keyboard#1234
plugman install ... --plugin https://github.com/cjpearson/cordova-plugin-keyboard#1234

but they all "Failed to fetch plugin from registry".

Replace outdated parts of plugman with cordova-plugin-template and documentation

Those can probably be removed:

Author plugins
    create               Create a plugin
    createpackagejson    Add a package.json file to a plugin
    platform             Add and remove platforms from a plugin

Some input:

Oh look, something like this already exists:
https://github.com/phonegap/phonegap-plugin-template
https://github.com/cesilva/cordova-plugin-template

Unfortunately this is gone:
https://www.npmjs.com/package/cordova-plugin-template
Although we probably don't need to publish this to npm anyway.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.