140

I am wondering is there an easier way to update cordova plugin?

I googled, found a hook (@ year 2013), but this is not 100% what I want.

I know I can do this by two steps: rm, then add but I am looking for a better (official) way to help me which plugins have newer version? and I can update ALL of them in one command. (just like: npm update)

for example:

$ cordova plugin list
/* list all installed plugins, their dependencies, and newer versions */

$ cordova plugin update
/* update all of them for me */

if there is no official way, is there some other helper? yo?

Santino Wang
  • 1,529
  • 2
  • 10
  • 3

15 Answers15

241

I got tired of manually checking for plugin updates so created a tool to do it for me: https://github.com/dpa99c/cordova-check-plugins

Install it globally:

$ npm install -g cordova-check-plugins

Then run from the root of your Cordova project. You can optionally update outdated plugins interactively or automatically, e.g.

$ cordova-check-plugins --update=auto

CLI screenshot

DaveAlden
  • 30,083
  • 11
  • 93
  • 155
  • I got errors while running the second line: error like: plugin: cordova-plugin-statusbar source: npm://cordova-plugin-statusbar installed version: UNKNOWN - check plugins/fetch.json for orphaned entries. remote version: 2.1.1 How can I resolve it? thank you – Agnosco Mar 09 '16 at 22:55
  • @Agnosco it means the plugin cannot determine the local version number, probably because of corrupt `fetch.json`. I would suggest manually removing and re-installing the affected plugin. – DaveAlden Apr 25 '16 at 13:11
  • That's amazing ! A possible enhancement would be to add the possibility to give args to the command when updating, like for the facebook plugin it would be possible to update automatically and not have this problem `Error: Variable(s) missing (use: --variable APP_ID=value --variable APP_NAME=value)` – Jeremy Belolo May 03 '16 at 14:44
  • 4
    @JeremyBelolo cordova-check-plugins@1.1.4 adds support to preserve variables when updating :-) – DaveAlden Aug 28 '16 at 18:50
  • 1
    @Al-Mothafar You have misunderstood the purpose of why security vulnerabilities are reported by npm. As I stated in the [issue you opened](https://github.com/dpa99c/cordova-check-plugins/issues/36), the package vulnerabilities reported by npm are irrelevant here since this is a CLI tool designed to be deployed to a local dev machine to which only you have access, not a remote public-facing server where they can be exploited by hackers. – DaveAlden Feb 14 '19 at 11:10
  • This worked really great! but not quite sure if this also updates package.json, maybe need to do ncu -u for updating package.json – Naga Feb 04 '22 at 15:06
70

You can't update it. What you can do is uninstall the cordova plugin and add it again.

cordova plugin rm https://github.com/apache/cordova-plugin-camera --save
cordova plugin add https://github.com/apache/cordova-plugin-camera --save
David Dal Busco
  • 7,975
  • 15
  • 55
  • 96
Nurdin
  • 23,382
  • 43
  • 130
  • 308
52

ionic state is deprecated as on ionic@3.7.0

If you happen to be using ionic and the ionic cli you can run:

ionic state reset

As long as all your plugin information was saved in your package.json earlier, this will essentially perform an rm/add for all your plugins. Just note that this will also rm/add your platforms as well, but that shouldn't matter.

This is also nice for when you ignore your plugin folders from your repo, and want to setup the project on another machine.

Obviously this doesn't directly answer the question, but many people are currently using both, and will end up here.

Venkat Kotra
  • 10,413
  • 3
  • 49
  • 53
Matt Way
  • 32,319
  • 10
  • 79
  • 85
  • if you have the plugins defined in the `config.xml` file, you can really just delete the plugins, and do an rm/add cycle on the platforms. `ionic platform add` will spot missing plugins and add them. But only the ones defined in `config.xml` – A.Grandt Apr 12 '16 at 09:15
  • `ionic state reset` definitely removes plugins - `ionic state restore` may be needed to reinstall them. – emc Feb 23 '17 at 20:40
  • 1
    ionic state reset - has been depreciated in ionic-v1 so you can no longer use this command. – FrodmanG Sep 19 '17 at 11:30
  • 1
    [ERROR] ionic state has been removed as of CLI 3.0. We recommend using Cordova directly to manage Cordova plugins and platforms. – Anil8753 Nov 04 '17 at 06:22
35

Found another answer from the npmjs.org

https://www.npmjs.com/package/cordova-plugin-update

Basically its installing the tool into your project:

npm install -g cordova-plugin-update

when done you then have to run the command

cordova-plugin-update

and it will prompt you to update if ever a newer version of a plugin is available

Flash
  • 1,105
  • 14
  • 16
28

Here's a bash script I use, works on OSX 10.11.3.

#!/bin/bash

PLUGINS=$(cordova plugin list | awk '{print $1}')

for PLUGIN in $PLUGINS; do
    cordova plugin rm $PLUGIN --save && cordova plugin add $PLUGIN --save
done

This may help if there are conflicts, per shan's comment. The difference is the addition of the --force flag when removing.

#!/bin/bash

PLUGINS=$(cordova plugin list | awk '{print $1}')

for PLUGIN in $PLUGINS; do
    cordova plugin rm $PLUGIN --force --save && cordova plugin add $PLUGIN --save
done
nick.graziano
  • 677
  • 6
  • 12
  • 1
    this is a nice hack, but will fail for plugins that require parameters upon installation, like cordova-plugin-facebook4 – Max Sep 18 '17 at 07:45
  • 2
    adding --force may help in conflicts cordova plugin rm $PLUGIN --force --save – Dan Jay Jan 10 '18 at 06:09
16

Go to your cordova project directory then write

npm outdated

npm will be display your outdated plugins, if any plugin outdated then write this command

npm update

Console Preview

Rajib Chy
  • 800
  • 10
  • 22
10

This is my Windows Batch version for update all plugins in one command

How to use:

From command line, in the same folder of project, run

c:\> batchNameFile

or

c:\> batchNameFile autoupdate

Where "batchNameFile" is the name of .BAT file, with the script below.

For only test ( first exmple ) or to force every update avaiable ( 2nd example )

@echo off

cls

set pluginListFile=update.plugin.list

if exist %pluginListFile% del %pluginListFile%

Echo "Reading installed Plugins"
Call cordova plugins > %pluginListFile%
echo.

for /F "tokens=1,2 delims= " %%a in ( %pluginListFile% ) do (
   Echo "Checking online version for %%a"

   for /F "delims=" %%I in ( 'npm info %%a version' ) do (
     Echo "Local : %%b"
     Echo "Online: %%I"
     if %%b LSS %%I Call :toUpdate %%a %~1
     :cont
     echo.
   )
)

if exist %pluginListFile% del %pluginListFile%

Exit /B

:toUpdate
Echo "Need Update !"
if '%~2' == 'autoupdate' Call :DoUpdate %~1
goto cont

:DoUpdate
Echo "Removing Plugin"
Call cordova plugin rm %~1
Echo "Adding Plugin"
Call cordova plugin add %~1
goto cont

This batch was only tested in Windows 10

Marco Scarnatto
  • 117
  • 1
  • 9
5

npm update -f its working form me

npm update -f

it will update all plugins and cli

  • cordova-sqlite-storage@2.3.0
  • cordova-plugin-x-socialsharing@5.3.2
  • onesignal-cordova-plugin@2.3.3
  • @ionic-native/device@4.6.0
  • @ionic-native/screen-orientation@4.6.0
  • @ionic-native/onesignal@4.6.0
  • @ionic-native/status-bar@4.6.0
  • @ionic-native/splash-screen@4.6.0
  • @ionic-native/core@4.6.0
  • @ionic-native/social-sharing@4.6.0
  • @angular/cli@1.7.3
  • cordova-plugin-splashscreen@5.0.3-dev added 322 packages, removed 256 packages, updated 91 packages and moved 8 packages in 350.86s
3

I too would LOVE something like this - plugin management with the PhoneGap/Cordova CLI is so annoying. This blog post here may be a start to something like this - but I'm not quite sure A) how to leverage it yet or B) how well it would work.

http://nocurve.com/cordova-update-all-plugins-in-project

My initial attempt at running the entire script right in the terminal command line did create an output of text with add/remove plugin commands ... but they didn't actually execute they just echoed into the terminal. I've reached out to the author hoping they will explain a bit more.

Christopher
  • 1,639
  • 19
  • 22
  • 1
    blog author here - I have no idea why I just echoed the commands - they were supposed to be run - must have pasted a test version of the script. Anyway, hope it helps someone... – Amnon Mar 24 '16 at 21:59
2

you cannot update ,but i wrote a batch file that removes my plugins and install again so in this case my all plugins are updated automatically, hope this solves your problem

@echo off
for %%a in (
"com.ionic.keyboard"
"com.phonegap.plugins.PushPlugin"
"cordova-instagram-plugin"
"cordova-plugin-camera"
"cordova-plugin-crosswalk-webview"
"cordova-plugin-file"
"cordova-plugin-file-transfer"

) do call cordova plugin rm %%a


for %%b in (
"com.ionic.keyboard"
"com.phonegap.plugins.PushPlugin"
"cordova-instagram-plugin"
"cordova-plugin-camera"
"cordova-plugin-crosswalk-webview"
"cordova-plugin-file"
"cordova-plugin-file-transfer"


) do call cordova plugin add %%b
Pranay Dutta
  • 2,483
  • 2
  • 30
  • 42
  • any way to update this script to scrape the plugin names from the output of `cordova plugins`? – mix3d Mar 17 '16 at 18:02
1

The easiest way would be to delete the plugins folder. Run this command: cordova prepare But, before you run it, you can check each plugin's version that you think would work for your build on Cordova's plugin repository website, and then you should modify the config.xml file, manually. Use upper carrots, "^" in the version field of the universal modeling language file, "config," to indicate that you want the specified plugin to update to the latest version in the future (the next time you run the command.)

morphytronx
  • 113
  • 3
  • Heehee, upper carrots, love it. That's put a smile on my face. Actually it's singular and called a caret (^). – AlphaBeta Jul 11 '19 at 13:50
  • Yeah, growing up as a child, when my uncle used to talk computer terms, I picked his terminology up not knowing what it actually meant, rather, what it sounded like. Some of it still carries to this day, since no one ever really learns about all the various symbols on a keyboard unless it is relevant to a project. – morphytronx Mar 06 '22 at 03:26
0

If you install the third party package:

npm i cordova-check-plugins

You can then run a simple command of

cordova-check-plugins --update=auto --force

Keep in mind forcing anything always comes with potential risks of breaking changes.

As other answers have stated, the connecting NPM packages that manage these plugins also require a consequent update when updating the plugins, so now you can check them with:

npm outdated

And then sweeping update them with

npm update

Now tentatively serve your app again and check all of the things that have potentially gone awry from breaking changes. The joy of software development! :)

Grant
  • 5,709
  • 2
  • 38
  • 50
0

You have to add this Cordova command in the command prompt:

npm install -g cordova-plugin-update

cordova-plugin-update

after entering this command the plugin will be added.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
-2
cordova-check-plugins --update=auto --force

use the command line

-9

You don't need remove, just add again.

cordova plugin add https://github.com/apache/cordova-plugin-camera
Daniel Faria
  • 1,476
  • 5
  • 24
  • 45