diff --git a/__tests__/features.test.ts b/__tests__/features.test.ts index 182602ed..b900b95e 100644 --- a/__tests__/features.test.ts +++ b/__tests__/features.test.ts @@ -29,7 +29,7 @@ describe('Features tests', () => { ); win32 = await features.addExtension('does_not_exist', '7.2', 'win32'); - expect(win32).toContain('Could not find extension: does_not_exist'); + expect(win32).toContain('Could not find does_not_exist for PHP7.2 on PECL'); win32 = await features.addExtension('xdebug', '7.2', 'fedora'); expect(win32).toContain('Platform fedora is not supported'); @@ -65,7 +65,9 @@ describe('Features tests', () => { expect(darwin).toContain('sudo pecl install xdebug-2.5.5'); darwin = await features.addExtension('does_not_exist', '7.2', 'darwin'); - expect(darwin).toContain('Could not find extension: does_not_exist'); + expect(darwin).toContain( + 'Could not find does_not_exist for PHP7.2 on PECL' + ); darwin = await features.addExtension('xdebug', '7.2', 'fedora'); expect(darwin).toContain('Platform fedora is not supported'); diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts index 7808ca7a..e74c3bea 100644 --- a/__tests__/utils.test.ts +++ b/__tests__/utils.test.ts @@ -106,7 +106,7 @@ describe('Utils tests', () => { // "Write-Host '" + message + "' -ForegroundColor yellow" // ); warning_log = await utils.log(message, 'linux', 'warning'); - expect(warning_log).toEqual('echo -e "\\033[33;1m' + message + '\\033[0m"'); + expect(warning_log).toEqual('echo "\\033[33;1m' + message + '\\033[0m"'); warning_log = await utils.log(message, 'darwin', 'warning'); expect(warning_log).toEqual('echo -e "\\033[33;1m' + message + '\\033[0m"'); @@ -115,7 +115,7 @@ describe('Utils tests', () => { // "Write-Host '" + message + "' -ForegroundColor red" // ); error_log = await utils.log(message, 'linux', 'error'); - expect(error_log).toEqual('echo -e "\\033[31;1m' + message + '\\033[0m"'); + expect(error_log).toEqual('echo "\\033[31;1m' + message + '\\033[0m"'); error_log = await utils.log(message, 'darwin', 'error'); expect(error_log).toEqual('echo -e "\\033[31;1m' + message + '\\033[0m"'); @@ -124,7 +124,7 @@ describe('Utils tests', () => { // "Write-Host '" + message + "' -ForegroundColor green" // ); success_log = await utils.log(message, 'linux', 'success'); - expect(success_log).toEqual('echo -e "\\033[32;1m' + message + '\\033[0m"'); + expect(success_log).toEqual('echo "\\033[32;1m' + message + '\\033[0m"'); success_log = await utils.log(message, 'darwin', 'success'); expect(success_log).toEqual('echo -e "\\033[32;1m' + message + '\\033[0m"'); }); diff --git a/lib/features.js b/lib/features.js index c63582d3..2e39b4b3 100644 --- a/lib/features.js +++ b/lib/features.js @@ -58,10 +58,12 @@ function enableExtensionWindows(extension) { $exist = Test-Path -Path $ext_dir\\php_${extension}.dll if(!(php -m | findstr -i ${extension}) -and $exist) { Add-Content C:\\tools\\php\\php.ini "extension=php_${extension}.dll"\n` + - (yield utils.log(extension + ' enabled', 'win32', 'success')) + - `} + (yield utils.log('Enabled ' + extension, 'win32', 'success')) + + ` } elseif(php -m | findstr -i ${extension}) {\n` + + (yield utils.log('Extension ' + extension + ' was already enabled', 'win32', 'success')) + + ` } } catch [Exception] {\n` + - (yield utils.log(extension + ' could not be installed', 'win32', 'error')) + + (yield utils.log(extension + ' could not be enabled', 'win32', 'error')) + ` }\n`); }); } @@ -70,12 +72,15 @@ exports.enableExtensionWindows = enableExtensionWindows; * Enable extensions which are installed but not enabled on unix * * @param extension + * @param os_version */ -function enableExtensionUnix(extension) { +function enableExtensionUnix(extension, os_version) { return __awaiter(this, void 0, void 0, function* () { - return (`if [ ! "$(php -m | grep ${extension})" ] && [ -e "$ext_dir/${extension}.so" ]; then + return (`if [ ! "$(php -m | grep -i ${extension})" ] && [ -e "$ext_dir/${extension}.so" ]; then echo "extension=${extension}.so" >> 'php -i | grep "Loaded Configuration" | sed -e "s|.*=>\s*||"'\n` + - (yield utils.log(extension + ' enabled', 'unix', 'success')) + + (yield utils.log('Enabled ' + extension, os_version, 'success')) + + `;\n elif [ "$(php -m | grep -i ${extension})" ]; then \n` + + (yield utils.log('Extension ' + extension + ' was already enabled', os_version, 'success')) + `; fi\n`); }); } @@ -94,26 +99,31 @@ function addExtensionDarwin(extension_csv, version) { return __awaiter(this, void 0, void 0, function* () { extension = extension.toLowerCase(); // add script to enable extension is already installed along with php - script += yield enableExtensionUnix(extension); + script += yield enableExtensionUnix(extension, 'darwin'); switch (yield pecl.checkPECLExtension(extension)) { case true: - extension = - version === '5.6' && extension === 'xdebug' - ? 'xdebug-2.5.5' - : extension; + let extension_version = version === '5.6' && extension === 'xdebug' + ? 'xdebug-2.5.5' + : extension; script += - 'if [ ! "$(php -m | grep ' + + 'if [ ! "$(php -m | grep -i ' + extension + ')" ]; then sudo pecl install ' + - extension + + extension_version + + ' >/dev/null 2>&1 && ' + + (yield utils.log('Installed and enabled ' + extension, 'darwin', 'success')) + ' || ' + - (yield utils.log("Couldn't install extension: " + extension, 'darwin', 'error')) + + (yield utils.log('Could not install ' + extension + ' on PHP' + version, 'darwin', 'error')) + '; fi\n'; break; case false: default: script += - (yield utils.log('Could not find extension: ' + extension, 'darwin', 'error')) + '\n'; + 'if [ ! "$(php -m | grep -i ' + + extension + + ')" ]; then \n' + + (yield utils.log('Could not find ' + extension + ' for PHP' + version + ' on PECL', 'darwin', 'error')) + + '; fi\n'; break; } }); @@ -157,14 +167,20 @@ function addExtensionWindows(extension_csv, version) { extension + ' -MinimumStability ' + extension_version + + '\n' + + (yield utils.log('Installed and enabled ' + extension, 'win32', 'success')) + ' } catch [Exception] { ' + - (yield utils.log('Could not install extension: ' + extension, 'win32', 'error')) + + (yield utils.log('Could not install ' + extension + ' on PHP' + version, 'win32', 'error')) + ' } }\n'; break; case false: default: script += - (yield utils.log('Could not find extension: ' + extension, 'win32', 'error')) + '\n'; + 'if(!(php -m | findstr -i ' + + extension + + ')) { ' + + (yield utils.log('Could not find ' + extension + ' for PHP' + version + ' on PECL', 'win32', 'error')) + + ' } \n'; break; } }); @@ -187,16 +203,18 @@ function addExtensionLinux(extension_csv, version) { return __awaiter(this, void 0, void 0, function* () { extension = extension.toLowerCase(); // add script to enable extension is already installed along with php - script += yield enableExtensionUnix(extension); + script += yield enableExtensionUnix(extension, 'linux'); script += - 'if [ ! "$(php -m | grep ' + + 'if [ ! "$(php -m | grep -i ' + extension + ')" ]; then sudo DEBIAN_FRONTEND=noninteractive apt install -y php' + version + '-' + extension + + ' >/dev/null 2>&1 && ' + + (yield utils.log('Installed and enabled ' + extension, 'linux', 'success')) + ' || ' + - (yield utils.log("Couldn't find extension php" + version + '-' + extension, 'linux', 'error')) + + (yield utils.log('Could not find php' + version + '-' + extension + ' on APT repository', 'linux', 'error')) + '; fi\n'; }); }); diff --git a/lib/utils.js b/lib/utils.js index 83ea9595..001b79bd 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -119,6 +119,11 @@ function INIArray(ini_values_csv) { exports.INIArray = INIArray; function log(message, os_version, log_type) { return __awaiter(this, void 0, void 0, function* () { + const unix_color = { + error: '31', + success: '32', + warning: '33' + }; switch (os_version) { case 'win32': const color = { @@ -128,13 +133,9 @@ function log(message, os_version, log_type) { }; return "Write-Host '" + message + "' -ForegroundColor " + color[log_type]; case 'linux': + return ('echo "\\033[' + unix_color[log_type] + ';1m' + message + '\\033[0m"'); case 'darwin': default: - const unix_color = { - error: '31', - success: '32', - warning: '33' - }; return ('echo -e "\\033[' + unix_color[log_type] + ';1m' + message + '\\033[0m"'); } }); diff --git a/package-lock.json b/package-lock.json index 386b3ee4..a5c0117c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "setup-php", - "version": "1.3.5", + "version": "1.3.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index b201388e..8bc4cb29 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "setup-php", - "version": "1.3.5", + "version": "1.3.6", "private": false, "description": "Setup php action", "main": "lib/setup-php.js", diff --git a/src/darwin.sh b/src/darwin.sh index 7f8c123a..4914a0d3 100644 --- a/src/darwin.sh +++ b/src/darwin.sh @@ -1,11 +1,11 @@ export HOMEBREW_NO_INSTALL_CLEANUP=TRUE -brew tap exolnet/homebrew-deprecated > /dev/null 2>&1 -brew install php@"$1" composer -brew link --force --overwrite php@"$1" +brew tap exolnet/homebrew-deprecated >/dev/null 2>&1 +brew install php@"$1" composer >/dev/null 2>&1 +brew link --force --overwrite php@"$1" >/dev/null 2>&1 ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") ext_dir=$(/usr/bin/php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||") sudo chmod 777 "$ini_file" mkdir -p "$(pecl config-get ext_dir)" -composer global require hirak/prestissimo +composer global require hirak/prestissimo >/dev/null 2>&1 php -v composer -V diff --git a/src/features.ts b/src/features.ts index 266b47b9..104869cb 100644 --- a/src/features.ts +++ b/src/features.ts @@ -49,10 +49,16 @@ export async function enableExtensionWindows(extension: string) { $exist = Test-Path -Path $ext_dir\\php_${extension}.dll if(!(php -m | findstr -i ${extension}) -and $exist) { Add-Content C:\\tools\\php\\php.ini "extension=php_${extension}.dll"\n` + - (await utils.log(extension + ' enabled', 'win32', 'success')) + - `} + (await utils.log('Enabled ' + extension, 'win32', 'success')) + + ` } elseif(php -m | findstr -i ${extension}) {\n` + + (await utils.log( + 'Extension ' + extension + ' was already enabled', + 'win32', + 'success' + )) + + ` } } catch [Exception] {\n` + - (await utils.log(extension + ' could not be installed', 'win32', 'error')) + + (await utils.log(extension + ' could not be enabled', 'win32', 'error')) + ` }\n` ); } @@ -61,12 +67,22 @@ export async function enableExtensionWindows(extension: string) { * Enable extensions which are installed but not enabled on unix * * @param extension + * @param os_version */ -export async function enableExtensionUnix(extension: string) { +export async function enableExtensionUnix( + extension: string, + os_version: string +) { return ( - `if [ ! "$(php -m | grep ${extension})" ] && [ -e "$ext_dir/${extension}.so" ]; then + `if [ ! "$(php -m | grep -i ${extension})" ] && [ -e "$ext_dir/${extension}.so" ]; then echo "extension=${extension}.so" >> 'php -i | grep "Loaded Configuration" | sed -e "s|.*=>\s*||"'\n` + - (await utils.log(extension + ' enabled', 'unix', 'success')) + + (await utils.log('Enabled ' + extension, os_version, 'success')) + + `;\n elif [ "$(php -m | grep -i ${extension})" ]; then \n` + + (await utils.log( + 'Extension ' + extension + ' was already enabled', + os_version, + 'success' + )) + `; fi\n` ); } @@ -86,21 +102,27 @@ export async function addExtensionDarwin( await utils.asyncForEach(extensions, async function(extension: string) { extension = extension.toLowerCase(); // add script to enable extension is already installed along with php - script += await enableExtensionUnix(extension); + script += await enableExtensionUnix(extension, 'darwin'); switch (await pecl.checkPECLExtension(extension)) { case true: - extension = + let extension_version: string = version === '5.6' && extension === 'xdebug' ? 'xdebug-2.5.5' : extension; script += - 'if [ ! "$(php -m | grep ' + + 'if [ ! "$(php -m | grep -i ' + extension + ')" ]; then sudo pecl install ' + - extension + + extension_version + + ' >/dev/null 2>&1 && ' + + (await utils.log( + 'Installed and enabled ' + extension, + 'darwin', + 'success' + )) + ' || ' + (await utils.log( - "Couldn't install extension: " + extension, + 'Could not install ' + extension + ' on PHP' + version, 'darwin', 'error' )) + @@ -109,11 +131,15 @@ export async function addExtensionDarwin( case false: default: script += + 'if [ ! "$(php -m | grep -i ' + + extension + + ')" ]; then \n' + (await utils.log( - 'Could not find extension: ' + extension, + 'Could not find ' + extension + ' for PHP' + version + ' on PECL', 'darwin', 'error' - )) + '\n'; + )) + + '; fi\n'; break; } }); @@ -157,9 +183,15 @@ export async function addExtensionWindows( extension + ' -MinimumStability ' + extension_version + + '\n' + + (await utils.log( + 'Installed and enabled ' + extension, + 'win32', + 'success' + )) + ' } catch [Exception] { ' + (await utils.log( - 'Could not install extension: ' + extension, + 'Could not install ' + extension + ' on PHP' + version, 'win32', 'error' )) + @@ -168,11 +200,15 @@ export async function addExtensionWindows( case false: default: script += + 'if(!(php -m | findstr -i ' + + extension + + ')) { ' + (await utils.log( - 'Could not find extension: ' + extension, + 'Could not find ' + extension + ' for PHP' + version + ' on PECL', 'win32', 'error' - )) + '\n'; + )) + + ' } \n'; break; } }); @@ -194,17 +230,23 @@ export async function addExtensionLinux( await utils.asyncForEach(extensions, async function(extension: string) { extension = extension.toLowerCase(); // add script to enable extension is already installed along with php - script += await enableExtensionUnix(extension); + script += await enableExtensionUnix(extension, 'linux'); script += - 'if [ ! "$(php -m | grep ' + + 'if [ ! "$(php -m | grep -i ' + extension + ')" ]; then sudo DEBIAN_FRONTEND=noninteractive apt install -y php' + version + '-' + extension + + ' >/dev/null 2>&1 && ' + + (await utils.log( + 'Installed and enabled ' + extension, + 'linux', + 'success' + )) + ' || ' + (await utils.log( - "Couldn't find extension php" + version + '-' + extension, + 'Could not find php' + version + '-' + extension + ' on APT repository', 'linux', 'error' )) + diff --git a/src/linux.sh b/src/linux.sh index 894dec32..a74f5575 100644 --- a/src/linux.sh +++ b/src/linux.sh @@ -1,13 +1,13 @@ version=$(php-config --version | cut -c 1-3) if [ "$version" != "$1" ]; then if [ ! -e "/usr/bin/php$1" ]; then - sudo DEBIAN_FRONTEND=noninteractive add-apt-repository ppa:ondrej/php -y > /dev/null 2>&1 - sudo DEBIAN_FRONTEND=noninteractive apt update -y > /dev/null 2>&1 - sudo DEBIAN_FRONTEND=noninteractive apt install -y php"$1" curl php"$1"-curl; + sudo DEBIAN_FRONTEND=noninteractive add-apt-repository ppa:ondrej/php -y >/dev/null 2>&1 + sudo DEBIAN_FRONTEND=noninteractive apt update -y >/dev/null 2>&1 + sudo DEBIAN_FRONTEND=noninteractive apt install -y php"$1" curl php"$1"-curl >/dev/null 2>&1 fi for tool in php phar phar.phar php-cgi php-config phpize; do if [ -e "/usr/bin/$tool$1" ]; then - sudo update-alternatives --set $tool /usr/bin/"$tool$1"; + sudo update-alternatives --set $tool /usr/bin/"$tool$1" fi done fi @@ -26,7 +26,7 @@ if [ ! -e "/usr/bin/composer" ]; then rm composer-setup.php fi -composer global require hirak/prestissimo > /dev/null 2>&1 +composer global require hirak/prestissimo >/dev/null 2>&1 ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") ext_dir=$(/usr/bin/php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||") sudo chmod 777 "$ini_file" diff --git a/src/utils.ts b/src/utils.ts index 51ea7475..d576239a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -121,6 +121,11 @@ export async function log( os_version: string, log_type: string ): Promise { + const unix_color: any = { + error: '31', + success: '32', + warning: '33' + }; switch (os_version) { case 'win32': const color: any = { @@ -131,13 +136,11 @@ export async function log( return "Write-Host '" + message + "' -ForegroundColor " + color[log_type]; case 'linux': + return ( + 'echo "\\033[' + unix_color[log_type] + ';1m' + message + '\\033[0m"' + ); case 'darwin': default: - const unix_color: any = { - error: '31', - success: '32', - warning: '33' - }; return ( 'echo -e "\\033[' + unix_color[log_type] + ';1m' + message + '\\033[0m"' );