Update cordova plugins in one command

CordovaCordova Plugins

Cordova Problem Overview


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?

Cordova Solutions


Solution 1 - Cordova

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

Solution 2 - Cordova

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

Solution 3 - Cordova

ionic state is deprecated as on [email protected]

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.

Solution 4 - Cordova

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

Solution 5 - Cordova

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

Solution 6 - Cordova

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

Solution 7 - Cordova

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

Solution 8 - Cordova

npm update -f its working form me

npm update -f

it will update all plugins and cli

Solution 9 - Cordova

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.

Solution 10 - Cordova

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

Solution 11 - Cordova

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.)

Solution 12 - Cordova

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! :)

Solution 13 - Cordova

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.

Solution 14 - Cordova

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

use the command line

Solution 15 - Cordova

You don't need remove, just add again.

cordova plugin add https://github.com/apache/cordova-plugin-camera

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSantino WangView Question on Stackoverflow
Solution 1 - CordovaDaveAldenView Answer on Stackoverflow
Solution 2 - CordovaNurdinView Answer on Stackoverflow
Solution 3 - CordovaMatt WayView Answer on Stackoverflow
Solution 4 - CordovaFlashView Answer on Stackoverflow
Solution 5 - Cordovanick.grazianoView Answer on Stackoverflow
Solution 6 - CordovaMarco ScarnattoView Answer on Stackoverflow
Solution 7 - CordovaRajib ChyView Answer on Stackoverflow
Solution 8 - CordovaM Ibrahim HayatView Answer on Stackoverflow
Solution 9 - CordovaChristopherView Answer on Stackoverflow
Solution 10 - CordovaPranay DuttaView Answer on Stackoverflow
Solution 11 - CordovamorphytronxView Answer on Stackoverflow
Solution 12 - CordovaGrantView Answer on Stackoverflow
Solution 13 - Cordovageetha geethaView Answer on Stackoverflow
Solution 14 - CordovaDhanasekaranView Answer on Stackoverflow
Solution 15 - CordovaDaniel FariaView Answer on Stackoverflow