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

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