From c704b4ac20c9457e7621f764ed4e2d283cb16790 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Tue, 21 Apr 2020 02:17:36 +0200 Subject: [PATCH] Splitting ynh_composer in is own file --- scripts/_common.sh | 47 ------------------------------------ scripts/install | 1 + scripts/upgrade | 1 + scripts/ynh_composer__2 | 53 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 47 deletions(-) create mode 100644 scripts/ynh_composer__2 diff --git a/scripts/_common.sh b/scripts/_common.sh index 59d849ba..0d843eb4 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -17,53 +17,6 @@ extra_pkg_dependencies="php7.3-bcmath php7.3-ctype php7.3-curl php7.3-exif php7. # EXPERIMENTAL HELPERS #================================================= -# Execute a command with Composer -# -# usage: ynh_composer_exec --phpversion=phpversion [--workdir=$final_path] --commands="commands" -# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. -# | arg: -c, --commands - Commands to execute. -ynh_composer_exec () { - # Declare an array to define the options of this helper. - local legacy_args=vwc - declare -Ar args_array=( [v]=phpversion= [w]=workdir= [c]=commands= ) - local phpversion - local workdir - local commands - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - workdir="${workdir:-$final_path}" - phpversion="${phpversion:-7.0}" - - COMPOSER_HOME="$workdir/.composer" \ - php${phpversion} "$workdir/composer.phar" $commands \ - -d "$workdir" --quiet --no-interaction -} - -# Install and initialize Composer in the given directory -# -# usage: ynh_install_composer --phpversion=phpversion [--workdir=$final_path] -# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. -ynh_install_composer () { - # Declare an array to define the options of this helper. - local legacy_args=vw - declare -Ar args_array=( [v]=phpversion= [w]=workdir= ) - local phpversion - local workdir - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - workdir="${workdir:-$final_path}" - phpversion="${phpversion:-7.0}" - - curl -sS https://getcomposer.org/installer \ - | COMPOSER_HOME="$workdir/.composer" \ - php${phpversion} -- --quiet --install-dir="$workdir" \ - || ynh_die --message="Unable to install Composer." - - # update dependencies to create composer.lock - ynh_composer_exec --phpversion="${phpversion}" --workdir="$workdir" --commands="install --no-dev" \ - || ynh_die --message="Unable to update core dependencies with Composer." -} - # Install another version of php. # # usage: ynh_install_php --phpversion=phpversion [--package=packages] diff --git a/scripts/install b/scripts/install index ec93df8a..26f7611a 100644 --- a/scripts/install +++ b/scripts/install @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_composer__2 source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index dcf158a2..05f54ba1 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_composer__2 source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/ynh_composer__2 b/scripts/ynh_composer__2 new file mode 100644 index 00000000..5c8775b0 --- /dev/null +++ b/scripts/ynh_composer__2 @@ -0,0 +1,53 @@ +#!/bin/bash + +# Execute a command with Composer +# +# usage: ynh_composer_exec [--phpversion=phpversion] [--workdir=$final_path] --commands="commands" +# | arg: -v, --phpversion - PHP version to use with composer +# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. +# | arg: -c, --commands - Commands to execute. +ynh_composer_exec () { + # Declare an array to define the options of this helper. + local legacy_args=vwc + declare -Ar args_array=( [v]=phpversion= [w]=workdir= [c]=commands= ) + local phpversion + local workdir + local commands + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + workdir="${workdir:-$final_path}" + phpversion="${phpversion:-7.0}" + + COMPOSER_HOME="$workdir/.composer" \ + php${phpversion} "$workdir/composer.phar" $commands \ + -d "$workdir" --quiet --no-interaction +} + +# Install and initialize Composer in the given directory +# +# usage: ynh_install_composer [--phpversion=phpversion] [--workdir=$final_path] [--install_args="--optimize-autoloader"] +# | arg: -v, --phpversion - PHP version to use with composer +# | arg: -w, --workdir - The directory from where the command will be executed. Default $final_path. +# | arg: -a, --install_args - Additional arguments provided to the composer install. Argument --no-dev already include +ynh_install_composer () { + # Declare an array to define the options of this helper. + local legacy_args=vwa + declare -Ar args_array=( [v]=phpversion= [w]=workdir= [a]=install_args=) + local phpversion + local workdir + local install_args + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + workdir="${workdir:-$final_path}" + phpversion="${phpversion:-7.0}" + install_args="${install_args:-}" + + curl -sS https://getcomposer.org/installer \ + | COMPOSER_HOME="$workdir/.composer" \ + php${phpversion} -- --quiet --install-dir="$workdir" \ + || ynh_die "Unable to install Composer." + + # update dependencies to create composer.lock + ynh_composer_exec --phpversion="${phpversion}" --workdir="$workdir" --commands="install --no-dev $install_args" \ + || ynh_die "Unable to update core dependencies with Composer." +}