From 0fae072f07e34d511bd5f4099725a5234247070b Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Fri, 24 Jul 2020 10:28:48 +0530 Subject: [PATCH] Refactor extensions.ts --- __tests__/extensions.test.ts | 14 -- __tests__/utils.test.ts | 19 +++ dist/index.js | 240 +++++++++------------------ src/extensions.ts | 313 +++++++++++++++-------------------- src/utils.ts | 54 ++++++ 5 files changed, 285 insertions(+), 355 deletions(-) diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 92f04c00..50f72a05 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -1,20 +1,6 @@ import * as extensions from '../src/extensions'; describe('Extension tests', () => { - it('checking getXdebugVersion', async () => { - expect(await extensions.getXdebugVersion('5.3')).toContain('2.2.7'); - expect(await extensions.getXdebugVersion('5.4')).toContain('2.4.1'); - expect(await extensions.getXdebugVersion('5.5')).toContain('2.5.5'); - expect(await extensions.getXdebugVersion('5.6')).toContain('2.5.5'); - expect(await extensions.getXdebugVersion('7.0')).toContain('2.7.2'); - expect(await extensions.getXdebugVersion('7.2')).toContain('2.9.6'); - }); - it('checking getUnsupportedLog', async () => { - expect(await extensions.getUnsupportedLog('ext', '5.6', 'linux')).toContain( - 'add_log "$cross" "ext" "ext is not supported on PHP 5.6"' - ); - }); - it('checking addExtensionOnWindows', async () => { let win32: string = await extensions.addExtension( 'Xdebug, pcov, sqlite, :intl, phalcon4, ioncube, oci8, pdo_oci, ast-beta, grpc-1.2.3, inotify-1.2.3alpha2', diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts index 8b0dcc2e..b5048b15 100644 --- a/__tests__/utils.test.ts +++ b/__tests__/utils.test.ts @@ -167,4 +167,23 @@ describe('Utils tests', () => { 'Platform fedora is not supported' ); }); + + it('checking getXdebugVersion', async () => { + expect(await utils.getXdebugVersion('5.3')).toContain('2.2.7'); + expect(await utils.getXdebugVersion('5.4')).toContain('2.4.1'); + expect(await utils.getXdebugVersion('5.5')).toContain('2.5.5'); + expect(await utils.getXdebugVersion('5.6')).toContain('2.5.5'); + expect(await utils.getXdebugVersion('7.0')).toContain('2.7.2'); + expect(await utils.getXdebugVersion('7.2')).toContain('2.9.6'); + }); + + it('checking getUnsupportedLog', async () => { + expect(await utils.getUnsupportedLog('ext', '5.6', 'linux')).toContain( + 'add_log "$cross" "ext" "ext is not supported on PHP 5.6"' + ); + }); + + it('checking joins', async () => { + expect(await utils.joins('a', 'b', 'c')).toBe('a b c'); + }); }); diff --git a/dist/index.js b/dist/index.js index 0c70b88e..94a19c95 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1314,7 +1314,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.suppressOutput = exports.getExtensionPrefix = exports.CSVArray = exports.extensionArray = exports.writeScript = exports.readScript = exports.addLog = exports.stepLog = exports.log = exports.color = exports.asyncForEach = exports.getInput = void 0; +exports.joins = exports.getUnsupportedLog = exports.getXdebugVersion = exports.suppressOutput = exports.getExtensionPrefix = exports.CSVArray = exports.extensionArray = exports.writeScript = exports.readScript = exports.addLog = exports.stepLog = exports.log = exports.color = exports.asyncForEach = exports.getInput = void 0; const fs = __importStar(__webpack_require__(747)); const path = __importStar(__webpack_require__(622)); const core = __importStar(__webpack_require__(470)); @@ -1529,6 +1529,49 @@ async function suppressOutput(os_version) { } } exports.suppressOutput = suppressOutput; +/** + * Function to get Xdebug version compatible with php versions. + * + * @param version + */ +async function getXdebugVersion(version) { + switch (version) { + case '5.3': + return '2.2.7'; + case '5.4': + return '2.4.1'; + case '5.5': + case '5.6': + return '2.5.5'; + case '7.0': + return '2.7.2'; + default: + return '2.9.6'; + } +} +exports.getXdebugVersion = getXdebugVersion; +/** + * Function to get script to log unsupported extensions. + * + * @param extension + * @param version + * @param os_version + */ +async function getUnsupportedLog(extension, version, os_version) { + return ('\n' + + (await addLog('$cross', extension, [extension, 'is not supported on PHP', version].join(' '), os_version)) + + '\n'); +} +exports.getUnsupportedLog = getUnsupportedLog; +/** + * Function to join strings with space + * + * @param str + */ +async function joins(...str) { + return [...str].join(' '); +} +exports.joins = joins; /***/ }), @@ -3568,36 +3611,9 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.addExtension = exports.addExtensionLinux = exports.addExtensionWindows = exports.addExtensionDarwin = exports.getUnsupportedLog = exports.getXdebugVersion = void 0; +exports.addExtension = exports.addExtensionLinux = exports.addExtensionWindows = exports.addExtensionDarwin = void 0; const path = __importStar(__webpack_require__(622)); const utils = __importStar(__webpack_require__(163)); -/** - * Function to get Xdebug version compatible with php versions - * - * @param version - */ -async function getXdebugVersion(version) { - switch (version) { - case '5.3': - return '2.2.7'; - case '5.4': - return '2.4.1'; - case '5.5': - case '5.6': - return '2.5.5'; - case '7.0': - return '2.7.2'; - default: - return '2.9.6'; - } -} -exports.getXdebugVersion = getXdebugVersion; -async function getUnsupportedLog(extension, version, os_version) { - return ('\n' + - (await utils.addLog('$cross', extension, extension + ' is not supported on PHP ' + version, os_version)) + - '\n'); -} -exports.getUnsupportedLog = getUnsupportedLog; /** * Install and enable extensions for darwin * @@ -3623,42 +3639,23 @@ async function addExtensionDarwin(extension_csv, version, pipe) { // match 5.3blackfire...5.6blackfire, 7.0blackfire...7.4blackfire // match 5.3blackfire-1.31.0...5.6blackfire-1.31.0, 7.0blackfire-1.31.0...7.4blackfire-1.31.0 case /^(5\.[3-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test(version_extension): - command = - 'bash ' + - path.join(__dirname, '../src/scripts/ext/blackfire_darwin.sh') + - ' ' + - version + - ' ' + - extension; + command = await utils.joins('\nbash', path.join(__dirname, '../src/scripts/ext/blackfire_darwin.sh'), version, extension); break; // match pre-release versions. For example - xdebug-beta case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): - add_script += - '\nadd_unstable_extension ' + - ext_name + - ' ' + - ext_version + - ' ' + - ext_prefix; + add_script += await utils.joins('\nadd_unstable_extension', ext_name, ext_version, ext_prefix); return; // match semver case /.*-\d+\.\d+\.\d+.*/.test(version_extension): - add_script += - '\nadd_pecl_extension ' + - ext_name + - ' ' + - ext_version + - ' ' + - ext_prefix; + add_script += await utils.joins('\nadd_pecl_extension', ext_name, ext_version, ext_prefix); return; - // match 5.3xdebug...5.5xdebug case /5\.[3-5]xdebug/.test(version_extension): command = - command_prefix + 'xdebug-' + (await getXdebugVersion(version)); + command_prefix + 'xdebug-' + (await utils.getXdebugVersion(version)); break; // match 5.3pcov to 7.0pcov case /(5\.[3-6]|7\.0)pcov/.test(version_extension): - add_script += await getUnsupportedLog('pcov', version, 'darwin'); + add_script += await utils.getUnsupportedLog('pcov', version, 'darwin'); return; // match 5.6xdebug to 8.0xdebug, 5.6swoole to 8.0swoole // match 5.6grpc to 7.4grpc, 5.6protobuf to 7.4protobuf @@ -3674,13 +3671,7 @@ async function addExtensionDarwin(extension_csv, version, pipe) { break; // match imagick case /^imagick$/.test(extension): - command = - 'brew install pkg-config imagemagick' + - pipe + - ' && ' + - command_prefix + - 'imagick' + - pipe; + command = await utils.joins('brew install pkg-config imagemagick' + pipe, '&& ' + command_prefix + 'imagick' + pipe); break; // match sqlite case /^sqlite$/.test(extension): @@ -3689,38 +3680,21 @@ async function addExtensionDarwin(extension_csv, version, pipe) { break; // match pdo_oci and oci8 case /^pdo_oci$|^oci8$/.test(extension): - add_script += - '\nbash ' + - path.join(__dirname, '../src/scripts/ext/oci.sh') + - ' ' + - extension + - ' ' + - version; + add_script += await utils.joins('\nbash ', path.join(__dirname, '../src/scripts/ext/oci.sh'), extension, version); return; // match 5.3ioncube...7.4ioncube, 7.0ioncube...7.4ioncube case /^5\.[3-6]ioncube$|^7\.[0-4]ioncube$/.test(version_extension): - add_script += - '\nbash ' + - path.join(__dirname, '../src/scripts/ext/ioncube.sh') + - ' ' + - version; + add_script += await utils.joins('\nbash ', path.join(__dirname, '../src/scripts/ext/ioncube.sh'), version); return; // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): - add_script += - '\nbash ' + - path.join(__dirname, '../src/scripts/ext/phalcon_darwin.sh') + - ' ' + - extension + - ' ' + - version; + add_script += await utils.joins('\nbash ', path.join(__dirname, '../src/scripts/ext/phalcon_darwin.sh'), extension, version); return; default: command = command_prefix + extension; break; } - add_script += - '\nadd_extension ' + extension + ' "' + command + '" ' + ext_prefix; + add_script += await utils.joins('\nadd_extension', extension, '"' + command + '"', ext_prefix); }); return add_script + remove_script; } @@ -3747,31 +3721,24 @@ async function addExtensionWindows(extension_csv, version) { // match 5.4blackfire...5.6blackfire, 7.0blackfire...7.4blackfire // match 5.4blackfire-1.31.0...5.6blackfire-1.31.0, 7.0blackfire-1.31.0...7.4blackfire-1.31.0 case /^(5\.[4-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test(version_extension): - add_script += - '\n& ' + - path.join(__dirname, '../src/scripts/ext/blackfire.ps1') + - ' ' + - version + - ' ' + - extension; + add_script += await utils.joins('\n& ', path.join(__dirname, '../src/scripts/ext/blackfire.ps1'), version, extension); return; // match pre-release versions. For example - xdebug-beta case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): - add_script += '\nAdd-Extension ' + ext_name + ' ' + ext_version; + add_script += await utils.joins('\nAdd-Extension', ext_name, ext_version); break; // match semver without state case /.*-\d+\.\d+\.\d+$/.test(version_extension): - add_script += '\nAdd-Extension ' + ext_name + ' stable ' + ext_version; + add_script += await utils.joins('\nAdd-Extension', ext_name, 'stable', ext_version); return; // match semver with state case /.*-(\d+\.\d+\.\d)(beta|alpha|devel|snapshot)\d*/.test(version_extension): matches = /.*-(\d+\.\d+\.\d)(beta|alpha|devel|snapshot)\d*/.exec(version_extension); - add_script += - '\nAdd-Extension ' + ext_name + ' ' + matches[2] + ' ' + matches[1]; + add_script += await utils.joins('\nAdd-Extension', ext_name, matches[2], matches[1]); return; // match 5.3pcov to 7.0pcov case /(5\.[3-6]|7\.0)pcov/.test(version_extension): - add_script += await getUnsupportedLog('pcov', version, 'win32'); + add_script += await utils.getUnsupportedLog('pcov', version, 'win32'); break; // match 5.3mysql..5.6mysql // match 5.3mysqli..5.6mysqli @@ -3789,38 +3756,19 @@ async function addExtensionWindows(extension_csv, version) { // match sqlite case /^sqlite$/.test(extension): extension = 'sqlite3'; - add_script += '\nAdd-Extension ' + extension; + add_script += await utils.joins('\nAdd-Extension', extension); break; // match pdo_oci and oci8 case /^pdo_oci$|^oci8$/.test(extension): - add_script += - '\n& ' + - path.join(__dirname, '../src/scripts/ext/oci.ps1') + - ' ' + - extension + - ' ' + - version + - '\n'; + add_script += await utils.joins('\n& ', path.join(__dirname, '../src/scripts/ext/oci.ps1'), extension, version); break; // match 5.3ioncube...7.4ioncube, 7.0ioncube...7.4ioncube case /^5\.[3-6]ioncube$|^7\.[0-4]ioncube$/.test(version_extension): - add_script += - '\n& ' + - path.join(__dirname, '../src/scripts/ext/ioncube.ps1') + - ' ' + - version + - '\n'; + add_script += await utils.joins('\n& ', path.join(__dirname, '../src/scripts/ext/ioncube.ps1'), version); break; // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): - add_script += - '\n& ' + - path.join(__dirname, '../src/scripts/ext/phalcon.ps1') + - ' ' + - extension + - ' ' + - version + - '\n'; + add_script += await utils.joins('\n& ', path.join(__dirname, '../src/scripts/ext/phalcon.ps1'), extension, version); break; default: add_script += '\nAdd-Extension ' + extension; @@ -3855,74 +3803,35 @@ async function addExtensionLinux(extension_csv, version, pipe) { // match 5.3blackfire...5.6blackfire, 7.0blackfire...7.4blackfire // match 5.3blackfire-{semver}...5.6blackfire-{semver}, 7.0blackfire-{semver}...7.4blackfire-{semver} case /^(5\.[3-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test(version_extension): - command = - 'bash ' + - path.join(__dirname, '../src/scripts/ext/blackfire.sh') + - ' ' + - version + - ' ' + - extension; + command = await utils.joins('\nbash', path.join(__dirname, '../src/scripts/ext/blackfire.sh'), version, extension); break; // match pre-release versions. For example - xdebug-beta case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): - add_script += - '\nadd_unstable_extension ' + - ext_name + - ' ' + - ext_version + - ' ' + - ext_prefix; + add_script += await utils.joins('\nadd_unstable_extension', ext_name, ext_version, ext_prefix); return; // match semver versions case /.*-\d+\.\d+\.\d+.*/.test(version_extension): - add_script += - '\nadd_pecl_extension ' + - ext_name + - ' ' + - ext_version + - ' ' + - ext_prefix; + add_script += await utils.joins('\nadd_pecl_extension', ext_name, ext_version, ext_prefix); return; // match 5.3pcov to 7.0pcov case /(5\.[3-6]|7\.0)pcov/.test(version_extension): - add_script += await getUnsupportedLog('pcov', version, 'linux'); + add_script += await utils.getUnsupportedLog('pcov', version, 'linux'); return; // match 5.6gearman..7.4gearman case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension): - command = - '\nbash ' + - path.join(__dirname, '../src/scripts/ext/gearman.sh') + - ' ' + - version + - pipe; + command = await utils.joins('\nbash', path.join(__dirname, '../src/scripts/ext/gearman.sh'), version, pipe); break; // match pdo_oci and oci8 case /^pdo_oci$|^oci8$/.test(extension): - add_script += - '\nbash ' + - path.join(__dirname, '../src/scripts/ext/oci.sh') + - ' ' + - extension + - ' ' + - version; + add_script += await utils.joins('\nbash', path.join(__dirname, '../src/scripts/ext/oci.sh'), extension, version); return; // match 5.3ioncube...7.4ioncube, 7.0ioncube...7.4ioncube case /^5\.[3-6]ioncube$|^7\.[0-4]ioncube$/.test(version_extension): - add_script += - '\nbash ' + - path.join(__dirname, '../src/scripts/ext/ioncube.sh') + - ' ' + - version; + add_script += await utils.joins('\nbash', path.join(__dirname, '../src/scripts/ext/ioncube.sh'), version); return; // match 7.0phalcon3...7.3phalcon3 or 7.2phalcon4...7.4phalcon4 case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): - add_script += - '\nbash ' + - path.join(__dirname, '../src/scripts/ext/phalcon.sh') + - ' ' + - extension + - ' ' + - version; + add_script += await utils.joins('\nbash', path.join(__dirname, '../src/scripts/ext/phalcon.sh'), extension, version); return; // match 7.2xdebug3..7.4xdebug3 case /^7\.[2-4]xdebug3$/.test(version_extension): @@ -3935,7 +3844,7 @@ async function addExtensionLinux(extension_csv, version, pipe) { command = command_prefix + version + '-' + extension + pipe; break; // match pdo extensions - case /.*pdo[_-].*/.test(version_extension): + case /.*pdo[_st-].*/.test(version_extension): extension = extension .replace('pdo_', '') .replace('pdo-', '') @@ -3955,8 +3864,7 @@ async function addExtensionLinux(extension_csv, version, pipe) { command = command_prefix + version + '-' + extension + pipe; break; } - add_script += - '\nadd_extension ' + extension + ' "' + command + '" ' + ext_prefix; + add_script += await utils.joins('\nadd_extension', extension, '"' + command + '"', ext_prefix); }); return add_script + remove_script; } diff --git a/src/extensions.ts b/src/extensions.ts index eb4a7507..b3cfe70c 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -1,44 +1,6 @@ import * as path from 'path'; import * as utils from './utils'; -/** - * Function to get Xdebug version compatible with php versions - * - * @param version - */ -export async function getXdebugVersion(version: string): Promise { - switch (version) { - case '5.3': - return '2.2.7'; - case '5.4': - return '2.4.1'; - case '5.5': - case '5.6': - return '2.5.5'; - case '7.0': - return '2.7.2'; - default: - return '2.9.6'; - } -} - -export async function getUnsupportedLog( - extension: string, - version: string, - os_version: string -): Promise { - return ( - '\n' + - (await utils.addLog( - '$cross', - extension, - extension + ' is not supported on PHP ' + version, - os_version - )) + - '\n' - ); -} - /** * Install and enable extensions for darwin * @@ -70,42 +32,38 @@ export async function addExtensionDarwin( case /^(5\.[3-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test( version_extension ): - command = - 'bash ' + - path.join(__dirname, '../src/scripts/ext/blackfire_darwin.sh') + - ' ' + - version + - ' ' + - extension; + command = await utils.joins( + '\nbash', + path.join(__dirname, '../src/scripts/ext/blackfire_darwin.sh'), + version, + extension + ); break; // match pre-release versions. For example - xdebug-beta case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): - add_script += - '\nadd_unstable_extension ' + - ext_name + - ' ' + - ext_version + - ' ' + - ext_prefix; + add_script += await utils.joins( + '\nadd_unstable_extension', + ext_name, + ext_version, + ext_prefix + ); return; // match semver case /.*-\d+\.\d+\.\d+.*/.test(version_extension): - add_script += - '\nadd_pecl_extension ' + - ext_name + - ' ' + - ext_version + - ' ' + - ext_prefix; + add_script += await utils.joins( + '\nadd_pecl_extension', + ext_name, + ext_version, + ext_prefix + ); return; - // match 5.3xdebug...5.5xdebug case /5\.[3-5]xdebug/.test(version_extension): command = - command_prefix + 'xdebug-' + (await getXdebugVersion(version)); + command_prefix + 'xdebug-' + (await utils.getXdebugVersion(version)); break; // match 5.3pcov to 7.0pcov case /(5\.[3-6]|7\.0)pcov/.test(version_extension): - add_script += await getUnsupportedLog('pcov', version, 'darwin'); + add_script += await utils.getUnsupportedLog('pcov', version, 'darwin'); return; // match 5.6xdebug to 8.0xdebug, 5.6swoole to 8.0swoole // match 5.6grpc to 7.4grpc, 5.6protobuf to 7.4protobuf @@ -121,13 +79,10 @@ export async function addExtensionDarwin( break; // match imagick case /^imagick$/.test(extension): - command = - 'brew install pkg-config imagemagick' + - pipe + - ' && ' + - command_prefix + - 'imagick' + - pipe; + command = await utils.joins( + 'brew install pkg-config imagemagick' + pipe, + '&& ' + command_prefix + 'imagick' + pipe + ); break; // match sqlite case /^sqlite$/.test(extension): @@ -136,38 +91,40 @@ export async function addExtensionDarwin( break; // match pdo_oci and oci8 case /^pdo_oci$|^oci8$/.test(extension): - add_script += - '\nbash ' + - path.join(__dirname, '../src/scripts/ext/oci.sh') + - ' ' + - extension + - ' ' + - version; + add_script += await utils.joins( + '\nbash ', + path.join(__dirname, '../src/scripts/ext/oci.sh'), + extension, + version + ); return; // match 5.3ioncube...7.4ioncube, 7.0ioncube...7.4ioncube case /^5\.[3-6]ioncube$|^7\.[0-4]ioncube$/.test(version_extension): - add_script += - '\nbash ' + - path.join(__dirname, '../src/scripts/ext/ioncube.sh') + - ' ' + - version; + add_script += await utils.joins( + '\nbash ', + path.join(__dirname, '../src/scripts/ext/ioncube.sh'), + version + ); return; // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): - add_script += - '\nbash ' + - path.join(__dirname, '../src/scripts/ext/phalcon_darwin.sh') + - ' ' + - extension + - ' ' + - version; + add_script += await utils.joins( + '\nbash ', + path.join(__dirname, '../src/scripts/ext/phalcon_darwin.sh'), + extension, + version + ); return; default: command = command_prefix + extension; break; } - add_script += - '\nadd_extension ' + extension + ' "' + command + '" ' + ext_prefix; + add_script += await utils.joins( + '\nadd_extension', + extension, + '"' + command + '"', + ext_prefix + ); }); return add_script + remove_script; } @@ -199,21 +156,29 @@ export async function addExtensionWindows( case /^(5\.[4-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test( version_extension ): - add_script += - '\n& ' + - path.join(__dirname, '../src/scripts/ext/blackfire.ps1') + - ' ' + - version + - ' ' + - extension; + add_script += await utils.joins( + '\n& ', + path.join(__dirname, '../src/scripts/ext/blackfire.ps1'), + version, + extension + ); return; // match pre-release versions. For example - xdebug-beta case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): - add_script += '\nAdd-Extension ' + ext_name + ' ' + ext_version; + add_script += await utils.joins( + '\nAdd-Extension', + ext_name, + ext_version + ); break; // match semver without state case /.*-\d+\.\d+\.\d+$/.test(version_extension): - add_script += '\nAdd-Extension ' + ext_name + ' stable ' + ext_version; + add_script += await utils.joins( + '\nAdd-Extension', + ext_name, + 'stable', + ext_version + ); return; // match semver with state case /.*-(\d+\.\d+\.\d)(beta|alpha|devel|snapshot)\d*/.test( @@ -222,12 +187,16 @@ export async function addExtensionWindows( matches = /.*-(\d+\.\d+\.\d)(beta|alpha|devel|snapshot)\d*/.exec( version_extension ) as RegExpExecArray; - add_script += - '\nAdd-Extension ' + ext_name + ' ' + matches[2] + ' ' + matches[1]; + add_script += await utils.joins( + '\nAdd-Extension', + ext_name, + matches[2], + matches[1] + ); return; // match 5.3pcov to 7.0pcov case /(5\.[3-6]|7\.0)pcov/.test(version_extension): - add_script += await getUnsupportedLog('pcov', version, 'win32'); + add_script += await utils.getUnsupportedLog('pcov', version, 'win32'); break; // match 5.3mysql..5.6mysql // match 5.3mysqli..5.6mysqli @@ -245,38 +214,33 @@ export async function addExtensionWindows( // match sqlite case /^sqlite$/.test(extension): extension = 'sqlite3'; - add_script += '\nAdd-Extension ' + extension; + add_script += await utils.joins('\nAdd-Extension', extension); break; // match pdo_oci and oci8 case /^pdo_oci$|^oci8$/.test(extension): - add_script += - '\n& ' + - path.join(__dirname, '../src/scripts/ext/oci.ps1') + - ' ' + - extension + - ' ' + - version + - '\n'; + add_script += await utils.joins( + '\n& ', + path.join(__dirname, '../src/scripts/ext/oci.ps1'), + extension, + version + ); break; // match 5.3ioncube...7.4ioncube, 7.0ioncube...7.4ioncube case /^5\.[3-6]ioncube$|^7\.[0-4]ioncube$/.test(version_extension): - add_script += - '\n& ' + - path.join(__dirname, '../src/scripts/ext/ioncube.ps1') + - ' ' + - version + - '\n'; + add_script += await utils.joins( + '\n& ', + path.join(__dirname, '../src/scripts/ext/ioncube.ps1'), + version + ); break; // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): - add_script += - '\n& ' + - path.join(__dirname, '../src/scripts/ext/phalcon.ps1') + - ' ' + - extension + - ' ' + - version + - '\n'; + add_script += await utils.joins( + '\n& ', + path.join(__dirname, '../src/scripts/ext/phalcon.ps1'), + extension, + version + ); break; default: add_script += '\nAdd-Extension ' + extension; @@ -317,74 +281,69 @@ export async function addExtensionLinux( case /^(5\.[3-6]|7\.[0-4])blackfire(-\d+\.\d+\.\d+)?$/.test( version_extension ): - command = - 'bash ' + - path.join(__dirname, '../src/scripts/ext/blackfire.sh') + - ' ' + - version + - ' ' + - extension; + command = await utils.joins( + '\nbash', + path.join(__dirname, '../src/scripts/ext/blackfire.sh'), + version, + extension + ); break; // match pre-release versions. For example - xdebug-beta case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): - add_script += - '\nadd_unstable_extension ' + - ext_name + - ' ' + - ext_version + - ' ' + - ext_prefix; + add_script += await utils.joins( + '\nadd_unstable_extension', + ext_name, + ext_version, + ext_prefix + ); return; // match semver versions case /.*-\d+\.\d+\.\d+.*/.test(version_extension): - add_script += - '\nadd_pecl_extension ' + - ext_name + - ' ' + - ext_version + - ' ' + - ext_prefix; + add_script += await utils.joins( + '\nadd_pecl_extension', + ext_name, + ext_version, + ext_prefix + ); return; // match 5.3pcov to 7.0pcov case /(5\.[3-6]|7\.0)pcov/.test(version_extension): - add_script += await getUnsupportedLog('pcov', version, 'linux'); + add_script += await utils.getUnsupportedLog('pcov', version, 'linux'); return; // match 5.6gearman..7.4gearman case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension): - command = - '\nbash ' + - path.join(__dirname, '../src/scripts/ext/gearman.sh') + - ' ' + - version + - pipe; + command = await utils.joins( + '\nbash', + path.join(__dirname, '../src/scripts/ext/gearman.sh'), + version, + pipe + ); break; // match pdo_oci and oci8 case /^pdo_oci$|^oci8$/.test(extension): - add_script += - '\nbash ' + - path.join(__dirname, '../src/scripts/ext/oci.sh') + - ' ' + - extension + - ' ' + - version; + add_script += await utils.joins( + '\nbash', + path.join(__dirname, '../src/scripts/ext/oci.sh'), + extension, + version + ); return; // match 5.3ioncube...7.4ioncube, 7.0ioncube...7.4ioncube case /^5\.[3-6]ioncube$|^7\.[0-4]ioncube$/.test(version_extension): - add_script += - '\nbash ' + - path.join(__dirname, '../src/scripts/ext/ioncube.sh') + - ' ' + - version; + add_script += await utils.joins( + '\nbash', + path.join(__dirname, '../src/scripts/ext/ioncube.sh'), + version + ); return; // match 7.0phalcon3...7.3phalcon3 or 7.2phalcon4...7.4phalcon4 case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): - add_script += - '\nbash ' + - path.join(__dirname, '../src/scripts/ext/phalcon.sh') + - ' ' + - extension + - ' ' + - version; + add_script += await utils.joins( + '\nbash', + path.join(__dirname, '../src/scripts/ext/phalcon.sh'), + extension, + version + ); return; // match 7.2xdebug3..7.4xdebug3 case /^7\.[2-4]xdebug3$/.test(version_extension): @@ -397,7 +356,7 @@ export async function addExtensionLinux( command = command_prefix + version + '-' + extension + pipe; break; // match pdo extensions - case /.*pdo[_-].*/.test(version_extension): + case /.*pdo[_st-].*/.test(version_extension): extension = extension .replace('pdo_', '') .replace('pdo-', '') @@ -417,8 +376,12 @@ export async function addExtensionLinux( command = command_prefix + version + '-' + extension + pipe; break; } - add_script += - '\nadd_extension ' + extension + ' "' + command + '" ' + ext_prefix; + add_script += await utils.joins( + '\nadd_extension', + extension, + '"' + command + '"', + ext_prefix + ); }); return add_script + remove_script; } diff --git a/src/utils.ts b/src/utils.ts index f63a3c69..ff53f461 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -259,3 +259,57 @@ export async function suppressOutput(os_version: string): Promise { ); } } + +/** + * Function to get Xdebug version compatible with php versions. + * + * @param version + */ +export async function getXdebugVersion(version: string): Promise { + switch (version) { + case '5.3': + return '2.2.7'; + case '5.4': + return '2.4.1'; + case '5.5': + case '5.6': + return '2.5.5'; + case '7.0': + return '2.7.2'; + default: + return '2.9.6'; + } +} + +/** + * Function to get script to log unsupported extensions. + * + * @param extension + * @param version + * @param os_version + */ +export async function getUnsupportedLog( + extension: string, + version: string, + os_version: string +): Promise { + return ( + '\n' + + (await addLog( + '$cross', + extension, + [extension, 'is not supported on PHP', version].join(' '), + os_version + )) + + '\n' + ); +} + +/** + * Function to join strings with space + * + * @param str + */ +export async function joins(...str: string[]): Promise { + return [...str].join(' '); +}