Files
setup-php/src/extensions.ts

253 lines
7.5 KiB
TypeScript
Raw Normal View History

2019-10-27 05:42:49 +05:30
import * as path from 'path';
2019-09-20 08:11:20 +05:30
import * as utils from './utils';
/**
* Install and enable extensions for darwin
*
* @param extension_csv
* @param version
2019-12-26 18:31:18 +05:30
* @param pipe
2019-09-20 08:11:20 +05:30
*/
export async function addExtensionDarwin(
extension_csv: string,
2019-12-26 18:31:18 +05:30
version: string,
pipe: string
2019-09-20 08:11:20 +05:30
): Promise<string> {
2019-11-24 02:04:12 +05:30
const extensions: Array<string> = await utils.extensionArray(extension_csv);
let script = '\n';
2020-05-13 22:00:42 +05:30
await utils.asyncForEach(extensions, async function (extension: string) {
2019-12-26 18:31:18 +05:30
const version_extension: string = version + extension;
2020-01-30 12:03:30 +05:30
const [extension_name, stability]: string[] = extension.split('-');
2020-03-14 07:42:02 +05:30
const ext_prefix = await utils.getExtensionPrefix(extension_name);
2020-08-03 14:24:54 +05:30
const command_prefix = 'pecl_install ';
2020-03-14 07:42:02 +05:30
let command = '';
switch (true) {
// match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
2020-01-30 12:03:30 +05:30
script +=
'\nadd_unstable_extension ' +
extension_name +
' ' +
stability +
' ' +
2020-03-14 07:42:02 +05:30
ext_prefix;
2020-01-30 12:03:30 +05:30
return;
// match 5.6xdebug to 8.0xdebug, 5.6swoole to 8.0swoole
// match 5.6grpc to 7.4grpc, 5.6protobuf to 7.4protobuf
// match 7.1pcov to 8.0pcov
2020-07-26 06:03:08 +05:30
case /(5\.6|7\.[0-4]|8\.[0-9])xdebug/.test(version_extension):
case /(5\.6|7\.[0-4])(grpc|protobuf|swoole)/.test(version_extension):
2020-06-19 04:09:13 +05:30
case /(7\.[1-4]|8\.[0-9])pcov/.test(version_extension):
command = 'add_brew_extension ' + extension_name;
2020-01-17 05:51:46 +05:30
break;
2020-03-14 07:42:02 +05:30
// match 5.6redis
2019-12-26 18:31:18 +05:30
case /5\.6redis/.test(version_extension):
2020-06-19 04:09:13 +05:30
command = command_prefix + 'redis-2.2.8';
2019-12-26 18:31:18 +05:30
break;
2020-03-14 07:42:02 +05:30
// match imagick
2020-03-16 06:38:50 +05:30
case /^imagick$/.test(extension):
2020-03-14 07:42:02 +05:30
command =
2020-01-21 01:06:31 +05:30
'brew install pkg-config imagemagick' +
pipe +
2020-03-14 07:42:02 +05:30
' && ' +
command_prefix +
'imagick' +
2020-01-21 01:06:31 +05:30
pipe;
break;
2020-03-14 07:42:02 +05:30
// match sqlite
2020-03-16 06:38:50 +05:30
case /^sqlite$/.test(extension):
2020-03-14 07:42:02 +05:30
extension = 'sqlite3';
2020-06-19 04:09:13 +05:30
command = command_prefix + extension;
2020-03-14 07:42:02 +05:30
break;
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
2019-12-26 18:31:18 +05:30
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
2020-02-17 03:46:26 +05:30
script +=
2020-05-13 21:48:11 +05:30
'\nbash ' +
2019-12-26 18:31:18 +05:30
path.join(__dirname, '../src/scripts/ext/phalcon_darwin.sh') +
' ' +
extension +
' ' +
2020-02-17 03:46:26 +05:30
version;
return;
default:
2020-06-19 04:09:13 +05:30
command = command_prefix + extension;
break;
2019-09-20 08:11:20 +05:30
}
2019-10-11 04:41:25 +05:30
script +=
2019-10-17 01:41:13 +05:30
'\nadd_extension ' +
2019-10-11 04:41:25 +05:30
extension +
' "' +
2020-03-14 07:42:02 +05:30
command +
2019-10-11 04:41:25 +05:30
'" ' +
2019-10-17 01:41:13 +05:30
(await utils.getExtensionPrefix(extension));
2019-09-20 08:11:20 +05:30
});
return script;
}
/**
* Install and enable extensions for windows
*
* @param extension_csv
* @param version
*/
export async function addExtensionWindows(
extension_csv: string,
2020-03-14 07:53:43 +05:30
version: string
2019-09-20 08:11:20 +05:30
): Promise<string> {
2019-11-24 02:04:12 +05:30
const extensions: Array<string> = await utils.extensionArray(extension_csv);
let script = '\n';
2020-05-13 22:00:42 +05:30
await utils.asyncForEach(extensions, async function (extension: string) {
const [extension_name, stability]: string[] = extension.split('-');
2019-12-26 18:31:18 +05:30
const version_extension: string = version + extension;
switch (true) {
// match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
script += '\nAdd-Extension ' + extension_name + ' ' + stability;
break;
2020-03-16 06:38:50 +05:30
// match 5.6mysql, 5.6mysqli, 5.6mysqlnd
case /^5\.6(mysql|mysqli|mysqlnd)$/.test(version_extension):
script +=
'\nAdd-Extension mysql\nAdd-Extension mysqli\nAdd-Extension mysqlnd';
break;
// match 7.0mysql..8.0mysql
// match 7.0mysqli..8.0mysqli
// match 7.0mysqlnd..8.0mysqlnd
case /[7-8]\.\d(mysql|mysqli|mysqlnd)$/.test(version_extension):
script += '\nAdd-Extension mysqli\nAdd-Extension mysqlnd';
break;
2020-03-14 07:42:02 +05:30
// match sqlite
2020-03-16 06:38:50 +05:30
case /^sqlite$/.test(extension):
2020-03-14 07:42:02 +05:30
extension = 'sqlite3';
script += '\nAdd-Extension ' + extension;
break;
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
2019-12-26 18:31:18 +05:30
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
script +=
'\n& ' +
path.join(__dirname, '../src/scripts/ext/phalcon.ps1') +
' ' +
extension +
' ' +
version +
'\n';
2019-12-02 20:43:45 +05:30
break;
default:
script += '\nAdd-Extension ' + extension;
break;
}
2019-09-20 08:11:20 +05:30
});
return script;
}
/**
* Install and enable extensions for linux
*
* @param extension_csv
* @param version
2019-12-26 18:31:18 +05:30
* @param pipe
2019-09-20 08:11:20 +05:30
*/
export async function addExtensionLinux(
extension_csv: string,
2019-12-26 18:31:18 +05:30
version: string,
pipe: string
2019-09-20 08:11:20 +05:30
): Promise<string> {
2019-11-24 02:04:12 +05:30
const extensions: Array<string> = await utils.extensionArray(extension_csv);
let script = '\n';
2020-05-13 22:00:42 +05:30
await utils.asyncForEach(extensions, async function (extension: string) {
2019-12-26 18:31:18 +05:30
const version_extension: string = version + extension;
2020-01-30 12:03:30 +05:30
const [extension_name, stability]: string[] = extension.split('-');
2020-03-14 07:42:02 +05:30
const ext_prefix = await utils.getExtensionPrefix(extension_name);
const command_prefix = 'sudo $debconf_fix apt-get install -y php';
let command = '';
switch (true) {
// match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
2020-01-30 12:03:30 +05:30
script +=
'\nadd_unstable_extension ' +
extension_name +
' ' +
stability +
' ' +
2020-03-14 07:42:02 +05:30
ext_prefix;
2020-01-30 12:03:30 +05:30
return;
// match 5.6gearman..7.4gearman
2019-12-26 18:31:18 +05:30
case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension):
2020-03-14 07:42:02 +05:30
command =
2020-05-13 21:48:11 +05:30
'\nbash ' +
2019-12-26 18:31:18 +05:30
path.join(__dirname, '../src/scripts/ext/gearman.sh') +
' ' +
2019-10-27 05:42:49 +05:30
version +
2019-12-26 18:31:18 +05:30
pipe;
2019-10-13 09:48:29 +05:30
break;
2020-01-22 01:00:13 +05:30
// match 7.0phalcon3...7.3phalcon3 or 7.2phalcon4...7.4phalcon4
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
script +=
2020-05-13 21:48:11 +05:30
'\nbash ' +
path.join(__dirname, '../src/scripts/ext/phalcon.sh') +
' ' +
extension +
' ' +
version;
return;
2020-03-16 06:38:50 +05:30
// match sqlite
case /^sqlite$/.test(extension):
2020-03-14 07:42:02 +05:30
extension = 'sqlite3';
command = command_prefix + version + '-' + extension + pipe;
break;
default:
2020-03-14 07:42:02 +05:30
command =
command_prefix +
version +
'-' +
2019-11-13 06:29:58 +05:30
extension.replace('pdo_', '').replace('pdo-', '') +
2019-12-26 18:31:18 +05:30
pipe;
break;
}
2019-09-20 08:11:20 +05:30
script +=
2020-03-14 07:42:02 +05:30
'\nadd_extension ' + extension + ' "' + command + '" ' + ext_prefix;
2019-09-20 08:11:20 +05:30
});
return script;
}
2019-11-24 02:04:12 +05:30
/**
* Install and enable extensions
*
* @param extension_csv
* @param version
* @param os_version
2020-03-14 07:42:02 +05:30
* @param no_step
2019-11-24 02:04:12 +05:30
*/
export async function addExtension(
extension_csv: string,
version: string,
os_version: string,
no_step = false
): Promise<string> {
2019-12-26 18:31:18 +05:30
const pipe: string = await utils.suppressOutput(os_version);
2019-11-24 02:04:12 +05:30
let script = '\n';
switch (no_step) {
case true:
2019-12-26 18:31:18 +05:30
script += (await utils.stepLog('Setup Extensions', os_version)) + pipe;
2019-11-24 02:04:12 +05:30
break;
case false:
default:
script += await utils.stepLog('Setup Extensions', os_version);
break;
}
switch (os_version) {
case 'win32':
2020-03-14 07:53:43 +05:30
return script + (await addExtensionWindows(extension_csv, version));
2019-11-24 02:04:12 +05:30
case 'darwin':
2019-12-26 18:31:18 +05:30
return script + (await addExtensionDarwin(extension_csv, version, pipe));
2019-11-24 02:04:12 +05:30
case 'linux':
2019-12-26 18:31:18 +05:30
return script + (await addExtensionLinux(extension_csv, version, pipe));
2019-11-24 02:04:12 +05:30
default:
return await utils.log(
'Platform ' + os_version + ' is not supported',
os_version,
'error'
);
}
}