2019-09-20 09:41:20 +07:00
|
|
|
"use strict";
|
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
});
|
|
|
|
};
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
var result = {};
|
|
|
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
|
|
result["default"] = mod;
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
const utils = __importStar(require("./utils"));
|
|
|
|
const pecl = __importStar(require("./pecl"));
|
2019-10-04 21:04:05 +07:00
|
|
|
function addExtension(extension_csv, version, os_version, log_prefix = 'Add Extension') {
|
2019-09-20 09:41:20 +07:00
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
2019-09-26 04:03:39 +07:00
|
|
|
switch (os_version) {
|
|
|
|
case 'win32':
|
2019-10-04 21:04:05 +07:00
|
|
|
return yield addExtensionWindows(extension_csv, version, log_prefix);
|
2019-09-26 04:03:39 +07:00
|
|
|
case 'darwin':
|
2019-10-04 21:04:05 +07:00
|
|
|
return yield addExtensionDarwin(extension_csv, version, log_prefix);
|
2019-09-26 04:03:39 +07:00
|
|
|
case 'linux':
|
2019-10-04 21:04:05 +07:00
|
|
|
return yield addExtensionLinux(extension_csv, version, log_prefix);
|
2019-09-26 04:03:39 +07:00
|
|
|
default:
|
2019-10-04 21:04:05 +07:00
|
|
|
return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error', log_prefix);
|
2019-09-20 09:41:20 +07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
exports.addExtension = addExtension;
|
|
|
|
/**
|
|
|
|
* Enable extensions which are installed but not enabled on windows
|
|
|
|
*
|
|
|
|
* @param extension
|
|
|
|
*/
|
2019-10-04 21:04:05 +07:00
|
|
|
function enableExtensionWindows(extension, log_prefix) {
|
2019-09-20 09:41:20 +07:00
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
2019-09-26 04:03:39 +07:00
|
|
|
return (`try {
|
2019-09-20 09:41:20 +07:00
|
|
|
$exist = Test-Path -Path $ext_dir\\php_${extension}.dll
|
2019-09-24 20:25:45 +07:00
|
|
|
if(!(php -m | findstr -i ${extension}) -and $exist) {
|
2019-09-28 10:19:11 +07:00
|
|
|
Add-Content C:\\tools\\php\\php.ini "${yield utils.getExtensionPrefix(extension)}=php_${extension}.dll"\n` +
|
2019-10-04 21:04:05 +07:00
|
|
|
(yield utils.log('Enabled ' + extension, 'win32', 'success', log_prefix)) +
|
2019-09-28 04:36:41 +07:00
|
|
|
` } elseif(php -m | findstr -i ${extension}) {\n` +
|
2019-10-04 21:04:05 +07:00
|
|
|
(yield utils.log(extension + ' was already enabled', 'win32', 'success', log_prefix)) +
|
2019-09-28 04:36:41 +07:00
|
|
|
` }
|
2019-09-26 04:03:39 +07:00
|
|
|
} catch [Exception] {\n` +
|
2019-10-04 21:04:05 +07:00
|
|
|
(yield utils.log(extension + ' could not be enabled', 'win32', 'error', log_prefix)) +
|
2019-09-26 04:03:39 +07:00
|
|
|
` }\n`);
|
2019-09-20 09:41:20 +07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
exports.enableExtensionWindows = enableExtensionWindows;
|
|
|
|
/**
|
|
|
|
* Enable extensions which are installed but not enabled on unix
|
|
|
|
*
|
|
|
|
* @param extension
|
2019-09-28 04:36:41 +07:00
|
|
|
* @param os_version
|
2019-09-20 09:41:20 +07:00
|
|
|
*/
|
2019-10-04 21:04:05 +07:00
|
|
|
function enableExtensionUnix(extension, os_version, log_prefix) {
|
2019-09-20 09:41:20 +07:00
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
2019-09-28 21:39:05 +07:00
|
|
|
return (`if [ ! "$(php -m | grep -i ${extension})" ] && [ -e "$ext_dir/${extension}.so" ]; then
|
2019-10-10 22:43:51 +07:00
|
|
|
echo "${yield utils.getExtensionPrefix(extension)}=${extension}" >> $ini_file\n` +
|
2019-10-04 21:04:05 +07:00
|
|
|
(yield utils.log('Enabled ' + extension, os_version, 'success', log_prefix)) +
|
2019-09-28 04:36:41 +07:00
|
|
|
`;\n elif [ "$(php -m | grep -i ${extension})" ]; then \n` +
|
2019-10-04 21:04:05 +07:00
|
|
|
(yield utils.log(extension + ' was already enabled', os_version, 'success', log_prefix)) +
|
2019-09-26 04:03:39 +07:00
|
|
|
`; fi\n`);
|
2019-09-20 09:41:20 +07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
exports.enableExtensionUnix = enableExtensionUnix;
|
|
|
|
/**
|
|
|
|
* Install and enable extensions for darwin
|
|
|
|
*
|
|
|
|
* @param extension_csv
|
2019-09-26 04:03:39 +07:00
|
|
|
* @param version
|
2019-09-20 09:41:20 +07:00
|
|
|
*/
|
2019-10-04 21:04:05 +07:00
|
|
|
function addExtensionDarwin(extension_csv, version, log_prefix) {
|
2019-09-20 09:41:20 +07:00
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
let extensions = yield utils.extensionArray(extension_csv);
|
|
|
|
let script = '\n';
|
|
|
|
yield utils.asyncForEach(extensions, function (extension) {
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
2019-09-26 04:03:39 +07:00
|
|
|
extension = extension.toLowerCase();
|
2019-09-20 09:41:20 +07:00
|
|
|
// add script to enable extension is already installed along with php
|
2019-10-04 21:04:05 +07:00
|
|
|
script += yield enableExtensionUnix(extension, 'darwin', log_prefix);
|
2019-09-26 04:03:39 +07:00
|
|
|
switch (yield pecl.checkPECLExtension(extension)) {
|
|
|
|
case true:
|
2019-09-28 21:39:05 +07:00
|
|
|
let install_command = '';
|
2019-09-28 10:19:11 +07:00
|
|
|
switch (version + extension) {
|
|
|
|
case '7.4xdebug':
|
2019-09-28 21:39:05 +07:00
|
|
|
install_command =
|
|
|
|
'sh ./xdebug_darwin.sh >/dev/null 2>&1 && echo "zend_extension=xdebug.so" >> $ini_file';
|
|
|
|
break;
|
|
|
|
case '7.4pcov':
|
|
|
|
install_command =
|
|
|
|
'sh ./pcov.sh >/dev/null 2>&1 && echo "extension=pcov.so" >> $ini_file';
|
|
|
|
break;
|
|
|
|
case '5.6xdebug':
|
|
|
|
install_command = 'sudo pecl install xdebug-2.5.5 >/dev/null 2>&1';
|
2019-09-28 10:19:11 +07:00
|
|
|
break;
|
|
|
|
default:
|
2019-09-28 21:39:05 +07:00
|
|
|
install_command =
|
|
|
|
'sudo pecl install ' + extension + ' >/dev/null 2>&1';
|
2019-09-28 10:19:11 +07:00
|
|
|
break;
|
|
|
|
}
|
2019-09-26 04:03:39 +07:00
|
|
|
script +=
|
2019-09-28 04:36:41 +07:00
|
|
|
'if [ ! "$(php -m | grep -i ' +
|
2019-09-26 04:03:39 +07:00
|
|
|
extension +
|
2019-09-28 21:39:05 +07:00
|
|
|
')" ]; then ' +
|
|
|
|
install_command +
|
|
|
|
' && ' +
|
2019-10-04 21:04:05 +07:00
|
|
|
(yield utils.log('Installed and enabled ' + extension, 'darwin', 'success', log_prefix)) +
|
2019-09-26 04:03:39 +07:00
|
|
|
' || ' +
|
2019-10-04 21:04:05 +07:00
|
|
|
(yield utils.log('Could not install ' + extension + ' on PHP' + version, 'darwin', 'error', log_prefix)) +
|
2019-09-26 04:03:39 +07:00
|
|
|
'; fi\n';
|
|
|
|
break;
|
|
|
|
case false:
|
|
|
|
default:
|
|
|
|
script +=
|
2019-09-28 04:36:41 +07:00
|
|
|
'if [ ! "$(php -m | grep -i ' +
|
|
|
|
extension +
|
|
|
|
')" ]; then \n' +
|
2019-10-04 21:04:05 +07:00
|
|
|
(yield utils.log('Could not find ' + extension + ' for PHP' + version + ' on PECL', 'darwin', 'error', log_prefix)) +
|
2019-09-28 04:36:41 +07:00
|
|
|
'; fi\n';
|
2019-09-26 04:03:39 +07:00
|
|
|
break;
|
2019-09-20 09:41:20 +07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return script;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
exports.addExtensionDarwin = addExtensionDarwin;
|
|
|
|
/**
|
|
|
|
* Install and enable extensions for windows
|
|
|
|
*
|
|
|
|
* @param extension_csv
|
|
|
|
* @param version
|
|
|
|
*/
|
2019-10-04 21:04:05 +07:00
|
|
|
function addExtensionWindows(extension_csv, version, log_prefix) {
|
2019-09-20 09:41:20 +07:00
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
let extensions = yield utils.extensionArray(extension_csv);
|
|
|
|
let script = '\n';
|
|
|
|
yield utils.asyncForEach(extensions, function (extension) {
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
2019-09-26 04:03:39 +07:00
|
|
|
extension = extension.toLowerCase();
|
2019-09-20 09:41:20 +07:00
|
|
|
// add script to enable extension is already installed along with php
|
2019-10-04 21:04:05 +07:00
|
|
|
script += yield enableExtensionWindows(extension, log_prefix);
|
2019-09-26 04:03:39 +07:00
|
|
|
switch (yield pecl.checkPECLExtension(extension)) {
|
|
|
|
case true:
|
2019-09-28 21:39:05 +07:00
|
|
|
let install_command = '';
|
2019-09-28 10:19:11 +07:00
|
|
|
switch (version + extension) {
|
|
|
|
case '7.4xdebug':
|
2019-09-28 21:39:05 +07:00
|
|
|
const extension_url = 'https://xdebug.org/files/php_xdebug-2.8.0beta2-7.4-vc15.dll';
|
|
|
|
install_command =
|
|
|
|
'Invoke-WebRequest -Uri ' +
|
|
|
|
extension_url +
|
|
|
|
' -OutFile C:\\tools\\php\\ext\\php_xdebug.dll\n';
|
|
|
|
install_command += 'Enable-PhpExtension xdebug';
|
2019-09-28 10:19:11 +07:00
|
|
|
break;
|
|
|
|
case '7.2xdebug':
|
|
|
|
default:
|
2019-09-28 21:39:05 +07:00
|
|
|
install_command = 'Install-PhpExtension ' + extension;
|
2019-09-28 10:19:11 +07:00
|
|
|
break;
|
|
|
|
}
|
2019-09-26 04:03:39 +07:00
|
|
|
script +=
|
|
|
|
'if(!(php -m | findstr -i ' +
|
|
|
|
extension +
|
|
|
|
')) { ' +
|
2019-09-28 21:39:05 +07:00
|
|
|
'try { ' +
|
|
|
|
install_command +
|
2019-09-28 04:36:41 +07:00
|
|
|
'\n' +
|
2019-10-04 21:04:05 +07:00
|
|
|
(yield utils.log('Installed and enabled ' + extension, 'win32', 'success', log_prefix)) +
|
2019-09-26 04:03:39 +07:00
|
|
|
' } catch [Exception] { ' +
|
2019-10-04 21:04:05 +07:00
|
|
|
(yield utils.log('Could not install ' + extension + ' on PHP' + version, 'win32', 'error', log_prefix)) +
|
2019-09-26 04:03:39 +07:00
|
|
|
' } }\n';
|
|
|
|
break;
|
|
|
|
case false:
|
|
|
|
default:
|
|
|
|
script +=
|
2019-09-28 04:36:41 +07:00
|
|
|
'if(!(php -m | findstr -i ' +
|
|
|
|
extension +
|
|
|
|
')) { ' +
|
2019-10-04 21:04:05 +07:00
|
|
|
(yield utils.log('Could not find ' + extension + ' for PHP' + version + ' on PECL', 'win32', 'error', log_prefix)) +
|
2019-09-28 04:36:41 +07:00
|
|
|
' } \n';
|
2019-09-26 04:03:39 +07:00
|
|
|
break;
|
2019-09-20 09:41:20 +07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return script;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
exports.addExtensionWindows = addExtensionWindows;
|
|
|
|
/**
|
|
|
|
* Install and enable extensions for linux
|
|
|
|
*
|
|
|
|
* @param extension_csv
|
|
|
|
* @param version
|
|
|
|
*/
|
2019-10-04 21:04:05 +07:00
|
|
|
function addExtensionLinux(extension_csv, version, log_prefix) {
|
2019-09-20 09:41:20 +07:00
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
let extensions = yield utils.extensionArray(extension_csv);
|
|
|
|
let script = '\n';
|
|
|
|
yield utils.asyncForEach(extensions, function (extension) {
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
2019-09-26 04:03:39 +07:00
|
|
|
extension = extension.toLowerCase();
|
2019-09-20 09:41:20 +07:00
|
|
|
// add script to enable extension is already installed along with php
|
2019-10-04 21:04:05 +07:00
|
|
|
script += yield enableExtensionUnix(extension, 'linux', log_prefix);
|
2019-09-28 21:39:05 +07:00
|
|
|
let install_command = '';
|
|
|
|
switch (version + extension) {
|
|
|
|
case '7.4xdebug':
|
|
|
|
install_command =
|
|
|
|
'./xdebug.sh >/dev/null 2>&1 && echo "zend_extension=xdebug.so" >> $ini_file';
|
|
|
|
break;
|
|
|
|
case '7.4pcov':
|
|
|
|
install_command =
|
|
|
|
'./pcov.sh >/dev/null 2>&1 && echo "extension=pcov.so" >> $ini_file';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
install_command =
|
|
|
|
'sudo DEBIAN_FRONTEND=noninteractive apt install -y php' +
|
|
|
|
version +
|
|
|
|
'-' +
|
|
|
|
extension +
|
|
|
|
' >/dev/null 2>&1';
|
|
|
|
break;
|
|
|
|
}
|
2019-09-20 09:41:20 +07:00
|
|
|
script +=
|
2019-09-28 04:36:41 +07:00
|
|
|
'if [ ! "$(php -m | grep -i ' +
|
2019-09-20 09:41:20 +07:00
|
|
|
extension +
|
2019-09-28 21:39:05 +07:00
|
|
|
')" ]; then ' +
|
|
|
|
install_command +
|
|
|
|
' && ' +
|
2019-10-04 21:04:05 +07:00
|
|
|
(yield utils.log('Installed and enabled ' + extension, 'linux', 'success', log_prefix)) +
|
2019-09-26 04:03:39 +07:00
|
|
|
' || ' +
|
2019-10-04 21:04:05 +07:00
|
|
|
(yield utils.log('Could not find php' + version + '-' + extension + ' on APT repository', 'linux', 'error', log_prefix)) +
|
2019-09-26 04:03:39 +07:00
|
|
|
'; fi\n';
|
2019-09-20 09:41:20 +07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
return script;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
exports.addExtensionLinux = addExtensionLinux;
|