This commit is contained in:
Shivam Mathur 2019-09-28 03:06:41 +05:30
parent 932b66f3fc
commit ca33947c62
10 changed files with 131 additions and 65 deletions

View File

@ -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');

View File

@ -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"');
});

View File

@ -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';
});
});

View File

@ -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"');
}
});

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "setup-php",
"version": "1.3.5",
"version": "1.3.6",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -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",

View File

@ -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

View File

@ -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'
)) +

View File

@ -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"

View File

@ -121,6 +121,11 @@ export async function log(
os_version: string,
log_type: string
): Promise<string> {
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"'
);