From 40944de1294db99bb46ec59899be21f0e7449172 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Sat, 15 Feb 2020 22:51:02 +0530 Subject: [PATCH] Fix phalcon caching on darwin --- dist/index.js | 7 +++--- src/extensions.ts | 7 +++--- src/scripts/ext/phalcon_darwin.sh | 42 +++++++++++++++++++++++++------ 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/dist/index.js b/dist/index.js index 8aa9c986..cfe5cc02 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2716,15 +2716,14 @@ function addExtensionDarwin(extension_csv, version, pipe) { pipe; break; case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): - install_command = + script += 'sh ' + path.join(__dirname, '../src/scripts/ext/phalcon_darwin.sh') + ' ' + extension + ' ' + - version + - pipe; - break; + version; + return; default: install_command = 'sudo pecl install -f ' + extension + pipe; break; diff --git a/src/extensions.ts b/src/extensions.ts index a434b887..7507e9ac 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -55,15 +55,14 @@ export async function addExtensionDarwin( pipe; break; case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): - install_command = + script += 'sh ' + path.join(__dirname, '../src/scripts/ext/phalcon_darwin.sh') + ' ' + extension + ' ' + - version + - pipe; - break; + version; + return; default: install_command = 'sudo pecl install -f ' + extension + pipe; break; diff --git a/src/scripts/ext/phalcon_darwin.sh b/src/scripts/ext/phalcon_darwin.sh index 8869c304..0297eed2 100644 --- a/src/scripts/ext/phalcon_darwin.sh +++ b/src/scripts/ext/phalcon_darwin.sh @@ -1,17 +1,43 @@ +# Function to log result of a operation +add_log() { + mark=$1 + subject=$2 + message=$3 + if [ "$mark" = "$tick" ]; then + printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message" + else + printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message" + fi +} + +# Function to install phalcon +install_phalcon() { + ( + brew tap shivammathur/homebrew-phalcon >/dev/null 2>&1 + brew install phalcon@"$php_version"_"$extension_major" >/dev/null 2>&1 + sudo cp /usr/local/opt/psr@"$php_version"/psr.so "$ext_dir" >/dev/null 2>&1 + sudo cp /usr/local/opt/phalcon@"$php_version"_"$extension_major"/phalcon.so "$ext_dir" >/dev/null 2>&1 + add_log "$tick" "$extension" "Installed and enabled" + ) || add_log "$cross" "$extension" "Could not install $extension on PHP $semver" +} + +tick="✓" +cross="✗" extension=$1 extension_major=${extension: -1} php_version=$2 +semver=$(php -v | head -n 1 | cut -f 2 -d ' ') ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||") if [ -e "$ext_dir/psr.so" ] && [ -e "$ext_dir/phalcon.so" ]; then - echo "extension=psr" >>"$ini_file" - echo "extension=phalcon" >>"$ini_file" - phalcon_version=$(php -d="extension=phalcon" -r "echo phpversion('phalcon');" | cut -d'.' -f 1) + phalcon_version=$(php -d="extension=psr.so" -d="extension=phalcon.so" -r "echo phpversion('phalcon');" | cut -d'.' -f 1) if [ "$phalcon_version" != "$extension_major" ]; then - brew tap shivammathur/homebrew-phalcon - brew install phalcon@"$php_version"_"$extension_major" + install_phalcon + else + echo "extension=psr.so" >>"$ini_file" + echo "extension=phalcon.so" >>"$ini_file" + add_log "$tick" "$extension" "Enabled" fi else - brew tap shivammathur/homebrew-phalcon - brew install phalcon@"$php_version"_"$extension_major" -fi \ No newline at end of file + install_phalcon +fi