Update cordova plugins in one command
Asked Answered
D

15

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?

Deanndeanna answered 28/2, 2015 at 16:24 Comment(3)
AFAIK I don't think soFinely
Here is a bash script that does this https://mcmap.net/q/165532/-update-cordova-plugins-in-one-commandKoetke
I went a step further and in my ios project folder ran pod updateBalzac
R
243

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

Receptor answered 11/12, 2015 at 12:15 Comment(6)
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 youWorms
@Worms 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.Receptor
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)Batsheva
@JeremyBelolo [email protected] adds support to preserve variables when updating :-)Receptor
@Al-Mothafar You have misunderstood the purpose of why security vulnerabilities are reported by npm. As I stated in the issue you opened, 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.Receptor
This worked really great! but not quite sure if this also updates package.json, maybe need to do ncu -u for updating package.jsonTartrazine
E
71

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
Estrellaestrellita answered 2/3, 2015 at 3:55 Comment(1)
I think the --save is not needed, see cordova.apache.org/docs/en/latest/guide/cli.Gillespie
P
52

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.

Purposely answered 8/10, 2015 at 14:59 Comment(4)
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.xmlRapacious
ionic state reset definitely removes plugins - ionic state restore may be needed to reinstall them.Tinstone
ionic state reset - has been depreciated in ionic-v1 so you can no longer use this command.Gunner
[ERROR] ionic state has been removed as of CLI 3.0. We recommend using Cordova directly to manage Cordova plugins and platforms.Slight
A
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

Abigail answered 15/3, 2018 at 16:5 Comment(2)
I tried it but it removed plugins from config.xml, just updated in package.jsonInstil
@Receptor mentions this in his answer from 2015Balzac
K
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
Koetke answered 2/4, 2016 at 21:30 Comment(2)
this is a nice hack, but will fail for plugins that require parameters upon installation, like cordova-plugin-facebook4Testerman
adding --force may help in conflicts cordova plugin rm $PLUGIN --force --saveSaunderson
S
19

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

Stokehole answered 20/8, 2019 at 11:19 Comment(2)
it's too bad this answer is buried, it's pretty slickBalzac
it only updated the npm plugins, not the one installed via cordova plugin add (if i check it with "cordova plugin list" they appear still in the old version). Is this because they were not installed via npm?Henke
M
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

Monosome answered 16/4, 2016 at 21:44 Comment(1)
This definitely worked at least partially for me - thank you for making/sharing.Sibship
U
5

npm update -f its working form me

npm update -f

it will update all plugins and cli

Unisexual answered 24/3, 2018 at 0:12 Comment(0)
S
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.

Sibship answered 16/8, 2015 at 12:48 Comment(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...Morbihan
F
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
Fulk answered 31/8, 2015 at 17:14 Comment(1)
any way to update this script to scrape the plugin names from the output of cordova plugins?Yarber
G
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.)

Grotesque answered 26/1, 2018 at 0:48 Comment(2)
Heehee, upper carrots, love it. That's put a smile on my face. Actually it's singular and called a caret (^).Kleinstein
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.Grotesque
H
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! :)

Hoot answered 14/5, 2020 at 3:32 Comment(0)
T
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.

Trimerous answered 30/10, 2021 at 10:29 Comment(0)
Q
-2
cordova-check-plugins --update=auto --force

use the command line

Qualm answered 22/9, 2017 at 7:4 Comment(1)
This isn't a tool that is installed by default.Romanticize
B
-10

You don't need remove, just add again.

cordova plugin add https://github.com/apache/cordova-plugin-camera
Bitty answered 4/12, 2015 at 18:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.