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?
This question is related to
cordova
cordova-plugins
npm update -f
its working form me
npm update -f
it will update all plugins and cli
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.)
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
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
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.
You don't need remove, just add again.
cordova plugin add https://github.com/apache/cordova-plugin-camera
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! :)
cordova-check-plugins --update=auto --force
use the command line
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
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
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
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
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.
Source: Stackoverflow.com