55eval $(
66 zz_args " Install npm plugins from package.json configuration" $0 " $@ " << -help
77 f file json_file Package.json file path (default: ./package.json)
8+ g - global Install plugins globally (npm -g)
89 - key json_key JSON key path to extract plugins from
910help
1011)
@@ -18,15 +19,15 @@ if [ -z "$json_key" ]; then
1819fi
1920
2021zz_log i " Using file {B $json_file }..."
21- plugins=$( jq -r " $json_key " " $json_file " | tr -d " '[]:,\" " )
22+ plugins=$( jq -r " $json_key " " $json_file " | tr -d " '[]:,\" " | sort -u | tr ' \n ' ' ' | sed ' s/ */ /g;s/^ *//;s/ *$// ' )
2223
2324if [ -z " $plugins " ]; then
2425 zz_log w " No plugins found at key {B $json_key } in {U $json_file }"
2526 exit 0
2627fi
2728
2829# Load the config file
29- config=$( dirname $0 ) /.ci-plugins
30+ config=$( dirname $0 ) /PLUGINS
3031
3132# if config file only contains comments and empty lines, make it empty
3233if [ -f " $config " ] && [ -z " $( grep -v -e ' ^#' -e ' ^$' $config ) " ]; then
4849# Reload the plugins list
4950plugins=$( cat $config | grep -v ' ^$' | tr ' \n' ' ' )
5051
52+ # List of plugins to install
53+ zz_log i " Plugins to install: {B $plugins }"
54+
5155# For each plugin, check if it is already installed
5256for plugin in $plugins ; do
53- if npm list --depth=0 | grep -q " $plugin @" ; then
57+ if npm list $global --depth=0 | grep -q " $plugin @" ; then
5458 plugins=$( echo $plugins | sed " s#$plugin ##g" | tr -s ' ' )
5559 fi
5660done
5761
5862# Install the plugins if there are any to install
5963if [ -n " $plugins " ]; then
6064 zz_log i " Installing plugins {B $plugins } ..."
61- if ! npm install --no-save $plugins 2> /dev/null 1>&2 ; then
65+ if ! npm install $global --no-save $plugins 2> /dev/null 1>&2 ; then
6266 zz_log e " Failed to install one of plugins {B $plugins }!"
6367 exit 1
6468 fi
6569 zz_log s " Plugins {B $plugins } installed successfully!"
70+ else
71+ zz_log s " All plugins are already installed."
6672fi
0 commit comments