setup-php/lib/extensions.js

215 lines
8.9 KiB
JavaScript
Raw Permalink Normal View History

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 });
2019-10-27 07:12:49 +07:00
const path = __importStar(require("path"));
2019-09-20 09:41:20 +07:00
const utils = __importStar(require("./utils"));
2019-10-12 00:39:05 +07:00
/**
* Install and enable extensions
*
* @param extension_csv
* @param version
* @param os_version
* @param log_prefix
*/
2019-10-17 03:11:13 +07:00
function addExtension(extension_csv, version, os_version, no_step = false) {
2019-09-20 09:41:20 +07:00
return __awaiter(this, void 0, void 0, function* () {
2019-10-17 03:11:13 +07:00
let script = '\n';
switch (no_step) {
case true:
script +=
(yield utils.stepLog('Setup Extensions', os_version)) +
(yield utils.suppressOutput(os_version));
break;
case false:
default:
script += yield utils.stepLog('Setup Extensions', os_version);
break;
}
switch (os_version) {
case 'win32':
2019-10-17 03:11:13 +07:00
return script + (yield addExtensionWindows(extension_csv, version));
case 'darwin':
2019-10-17 03:11:13 +07:00
return script + (yield addExtensionDarwin(extension_csv, version));
case 'linux':
2019-10-17 03:11:13 +07:00
return script + (yield addExtensionLinux(extension_csv, version));
default:
2019-10-17 03:11:13 +07:00
return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error');
2019-09-20 09:41:20 +07:00
}
});
}
exports.addExtension = addExtension;
/**
* Install and enable extensions for darwin
*
* @param extension_csv
* @param version
2019-09-20 09:41:20 +07:00
*/
2019-10-17 03:11:13 +07:00
function addExtensionDarwin(extension_csv, version) {
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* () {
extension = extension.toLowerCase();
2019-09-20 09:41:20 +07:00
// add script to enable extension is already installed along with php
2019-10-11 06:11:25 +07:00
let install_command = '';
switch (version + extension) {
case '7.4xdebug':
install_command =
2019-10-27 07:12:49 +07:00
'sh ' +
path.join(__dirname, '../src/scripts/xdebug_darwin.sh') +
' >/dev/null 2>&1 && echo "zend_extension=xdebug.so" >> $ini_file';
2019-10-11 06:11:25 +07:00
break;
case '7.4pcov':
install_command =
2019-10-27 07:12:49 +07:00
'sh ' +
path.join(__dirname, '../src/scripts/pcov.sh') +
' >/dev/null 2>&1 && echo "extension=pcov.so" >> $ini_file';
2019-10-11 06:11:25 +07:00
break;
case '5.6xdebug':
install_command = 'sudo pecl install xdebug-2.5.5 >/dev/null 2>&1';
break;
default:
2019-10-11 06:11:25 +07:00
install_command = 'sudo pecl install ' + extension + ' >/dev/null 2>&1';
break;
2019-09-20 09:41:20 +07:00
}
2019-10-11 06:11:25 +07:00
script +=
2019-10-17 03:11:13 +07:00
'\nadd_extension ' +
2019-10-11 06:11:25 +07:00
extension +
' "' +
install_command +
'" ' +
2019-10-17 03:11:13 +07:00
(yield utils.getExtensionPrefix(extension));
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-17 03:11:13 +07:00
function addExtensionWindows(extension_csv, version) {
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* () {
extension = extension.toLowerCase();
2019-09-20 09:41:20 +07:00
// add script to enable extension is already installed along with php
2019-10-11 06:11:25 +07:00
let install_command = '';
switch (version + extension) {
case '7.4xdebug':
const extension_url = 'https://xdebug.org/files/php_xdebug-2.8.0-7.4-vc15.dll';
2019-10-11 06:11:25 +07:00
install_command =
'Invoke-WebRequest -Uri ' +
extension_url +
' -OutFile C:\\tools\\php\\ext\\php_xdebug.dll\n';
install_command += 'Enable-PhpExtension xdebug';
break;
2019-10-11 06:11:25 +07:00
case '7.2xdebug':
default:
2019-10-11 06:11:25 +07:00
install_command = 'Install-PhpExtension ' + extension;
break;
2019-09-20 09:41:20 +07:00
}
2019-10-11 06:11:25 +07:00
script +=
2019-10-17 03:11:13 +07:00
'\nAdd-Extension ' +
2019-10-11 06:11:25 +07:00
extension +
' "' +
install_command +
'" ' +
2019-10-17 03:11:13 +07:00
(yield utils.getExtensionPrefix(extension));
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-17 03:11:13 +07:00
function addExtensionLinux(extension_csv, version) {
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* () {
extension = extension.toLowerCase();
2019-09-20 09:41:20 +07:00
// add script to enable extension is already installed along with php
let install_command = '';
switch (version + extension) {
case '7.4xdebug':
install_command =
2019-10-27 07:12:49 +07:00
'sh ' +
path.join(__dirname, '../src/scripts/xdebug.sh') +
' >/dev/null 2>&1 && echo "zend_extension=xdebug.so" >> $ini_file';
break;
case '7.4pcov':
install_command =
2019-10-27 07:12:49 +07:00
'sh ' +
path.join(__dirname, '../src/scripts/pcov.sh') +
' >/dev/null 2>&1 && echo "extension=pcov.so" >> $ini_file';
break;
2019-10-13 11:18:29 +07:00
case '7.2phalcon3':
case '7.3phalcon3':
2019-10-27 07:12:49 +07:00
install_command =
'sh ' +
path.join(__dirname, '../src/scripts/phalcon.sh') +
' master ' +
version +
' >/dev/null 2>&1';
2019-10-13 11:18:29 +07:00
break;
case '7.2phalcon4':
case '7.3phalcon4':
2019-10-27 07:12:49 +07:00
case '7.4phalcon4':
install_command =
'sh ' +
path.join(__dirname, '../src/scripts/phalcon.sh') +
' 4.0.x ' +
version +
' >/dev/null 2>&1';
2019-10-13 11:18:29 +07:00
break;
default:
install_command =
2019-10-23 05:05:15 +07:00
'sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y php' +
version +
'-' +
extension +
' >/dev/null 2>&1';
break;
}
2019-09-20 09:41:20 +07:00
script +=
2019-10-17 03:11:13 +07:00
'\nadd_extension ' +
2019-09-20 09:41:20 +07:00
extension +
2019-10-11 06:11:25 +07:00
' "' +
install_command +
2019-10-11 06:11:25 +07:00
'" ' +
2019-10-17 03:11:13 +07:00
(yield utils.getExtensionPrefix(extension));
2019-09-20 09:41:20 +07:00
});
});
return script;
});
}
exports.addExtensionLinux = addExtensionLinux;