From 273096b82f3d5d06d18203d9ebdccc8f456f0ce6 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Thu, 26 Dec 2019 18:31:18 +0530 Subject: [PATCH] Refactor coverage and extension code --- __tests__/coverage.test.ts | 55 +++------ __tests__/extensions.test.ts | 8 +- __tests__/install.test.ts | 9 +- dist/index.js | 164 ++++++++++--------------- src/{ext => bin}/php_pcov.dll | Bin src/coverage.ts | 93 ++++---------- src/extensions.ts | 76 +++++++----- src/install.ts | 4 +- src/scripts/7.4.sh | 116 ----------------- src/scripts/darwin.sh | 19 +-- src/scripts/{ => ext}/gearman.sh | 0 src/scripts/{ => ext}/pcov.sh | 0 src/scripts/ext/phalcon.ps1 | 27 ++++ src/scripts/{ => ext}/phalcon.sh | 0 src/scripts/ext/phalcon_darwin.sh | 16 +++ src/scripts/{ => ext}/xdebug.sh | 0 src/scripts/{ => ext}/xdebug_darwin.sh | 0 src/scripts/linux.sh | 12 +- src/scripts/win32.ps1 | 139 +++++++++++---------- 19 files changed, 286 insertions(+), 452 deletions(-) rename src/{ext => bin}/php_pcov.dll (100%) delete mode 100644 src/scripts/7.4.sh rename src/scripts/{ => ext}/gearman.sh (100%) rename src/scripts/{ => ext}/pcov.sh (100%) create mode 100644 src/scripts/ext/phalcon.ps1 rename src/scripts/{ => ext}/phalcon.sh (100%) create mode 100644 src/scripts/ext/phalcon_darwin.sh rename src/scripts/{ => ext}/xdebug.sh (100%) rename src/scripts/{ => ext}/xdebug_darwin.sh (100%) diff --git a/__tests__/coverage.test.ts b/__tests__/coverage.test.ts index 121d04c2..b8eaf597 100644 --- a/__tests__/coverage.test.ts +++ b/__tests__/coverage.test.ts @@ -2,20 +2,15 @@ import * as coverage from '../src/coverage'; jest.mock('../src/extensions', () => ({ addExtension: jest.fn().mockImplementation(extension => { - return 'addExtension ' + extension + '\n'; + return 'add_extension ' + extension + '\n'; }) })); describe('Config tests', () => { it('checking addCoverage with PCOV on windows', async () => { let win32: string = await coverage.addCoverage('pcov', '7.4', 'win32'); - expect(win32).toContain('addExtension pcov'); - expect(win32).toContain( - 'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug $php_dir' - ); - expect(win32).toContain( - 'if (Test-Path $ext_dir\\php_xdebug.dll) { Remove-Item $ext_dir\\php_xdebug.dll }' - ); + expect(win32).toContain('add_extension pcov'); + expect(win32).toContain('Remove-Extension xdebug'); win32 = await coverage.addCoverage('pcov', '7.0', 'win32'); expect(win32).toContain('PHP 7.1 or newer is required'); @@ -26,24 +21,19 @@ describe('Config tests', () => { it('checking addCoverage with PCOV on linux', async () => { const linux: string = await coverage.addCoverage('pcov', '7.4', 'linux'); - expect(linux).toContain('addExtension pcov'); - expect(linux).toContain('sudo sed -i "/xdebug/d" "$ini_file"'); - expect(linux).toContain('sudo phpdismod -v 7.4 xdebug'); - expect(linux).toContain( - 'sudo DEBIAN_FRONTEND=noninteractive apt-fast remove php-xdebug' - ); + expect(linux).toContain('add_extension pcov'); + expect(linux).toContain('remove_extension xdebug'); }); it('checking addCoverage with PCOV on darwin', async () => { const darwin: string = await coverage.addCoverage('pcov', '7.4', 'darwin'); - expect(darwin).toContain('addExtension pcov'); - expect(darwin).toContain('sudo sed -i \'\' "/xdebug/d" "$ini_file"'); - expect(darwin).toContain('sudo rm -rf "$ext_dir"/xdebug.so'); + expect(darwin).toContain('add_extension pcov'); + expect(darwin).toContain('remove_extension xdebug'); }); it('checking addCoverage with Xdebug on windows', async () => { const win32: string = await coverage.addCoverage('xdebug', '7.4', 'win32'); - expect(win32).toContain('addExtension xdebug'); + expect(win32).toContain('add_extension xdebug'); }); it('checking addCoverage with Xdebug on windows', async () => { @@ -53,7 +43,7 @@ describe('Config tests', () => { it('checking addCoverage with Xdebug on linux', async () => { const linux: string = await coverage.addCoverage('xdebug', '7.4', 'linux'); - expect(linux).toContain('addExtension xdebug'); + expect(linux).toContain('add_extension xdebug'); }); it('checking addCoverage with Xdebug on linux', async () => { @@ -67,7 +57,7 @@ describe('Config tests', () => { '7.4', 'darwin' ); - expect(darwin).toContain('addExtension xdebug'); + expect(darwin).toContain('add_extension xdebug'); }); it('checking addCoverage with Xdebug on darwin', async () => { @@ -81,33 +71,20 @@ describe('Config tests', () => { it('checking disableCoverage windows', async () => { const win32 = await coverage.addCoverage('none', '7.4', 'win32'); - expect(win32).toContain('Disable-PhpExtension xdebug'); - expect(win32).toContain('Disable-PhpExtension pcov'); - expect(win32).toContain( - 'if (Test-Path $ext_dir\\php_xdebug.dll) { Remove-Item $ext_dir\\php_xdebug.dll }' - ); - expect(win32).toContain( - 'if (Test-Path $ext_dir\\php_pcov.dll) { Remove-Item $ext_dir\\php_pcov.dll }' - ); + expect(win32).toContain('Remove-Extension xdebug'); + expect(win32).toContain('Remove-Extension pcov'); }); it('checking disableCoverage on linux', async () => { const linux: string = await coverage.addCoverage('none', '7.4', 'linux'); - expect(linux).toContain('sudo phpdismod -v 7.4 xdebug'); - expect(linux).toContain('sudo phpdismod -v 7.4 pcov'); - expect(linux).toContain('sudo sed -i "/xdebug/d" "$ini_file"'); - expect(linux).toContain('sudo sed -i "/pcov/d" "$ini_file"'); - expect(linux).toContain( - 'sudo DEBIAN_FRONTEND=noninteractive apt-fast remove php-xdebug php-pcov' - ); + expect(linux).toContain('remove_extension xdebug'); + expect(linux).toContain('remove_extension pcov'); }); it('checking disableCoverage on darwin', async () => { const darwin: string = await coverage.addCoverage('none', '7.4', 'darwin'); - expect(darwin).toContain('sudo sed -i \'\' "/xdebug/d" "$ini_file"'); - expect(darwin).toContain('sudo sed -i \'\' "/pcov/d" "$ini_file"'); - expect(darwin).toContain('sudo rm -rf "$ext_dir"/xdebug.so'); - expect(darwin).toContain('sudo rm -rf "$ext_dir"/pcov.so'); + expect(darwin).toContain('remove_extension xdebug'); + expect(darwin).toContain('remove_extension pcov'); }); it('checking no or invalid coverage driver', async () => { diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 02ae61c0..61c41e2d 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -9,7 +9,7 @@ describe('Extension tests', () => { ); expect(win32).toContain('Add-Extension xdebug'); expect(win32).toContain('Add-Extension pcov'); - expect(win32).toContain('Add-Phalcon phalcon4'); + expect(win32).toContain('phalcon.ps1 phalcon4'); win32 = await extensions.addExtension( 'phalcon3, does_not_exist', @@ -17,7 +17,7 @@ describe('Extension tests', () => { 'win32', true ); - expect(win32).toContain('Add-Phalcon phalcon3'); + expect(win32).toContain('phalcon.ps1 phalcon3'); expect(win32).toContain('Add-Extension does_not_exist'); win32 = await extensions.addExtension('xdebug', '7.2', 'fedora'); @@ -80,10 +80,10 @@ describe('Extension tests', () => { expect(darwin).toContain('sudo pecl install pcov'); darwin = await extensions.addExtension('phalcon3', '7.0', 'darwin'); - expect(darwin).toContain('add_phalcon phalcon3'); + expect(darwin).toContain('phalcon_darwin.sh phalcon3'); darwin = await extensions.addExtension('phalcon4', '7.3', 'darwin'); - expect(darwin).toContain('add_phalcon phalcon4'); + expect(darwin).toContain('phalcon_darwin.sh phalcon4'); darwin = await extensions.addExtension('pcov', '5.6', 'darwin'); expect(darwin).toContain('sudo pecl install pcov'); diff --git a/__tests__/install.test.ts b/__tests__/install.test.ts index b5daa8ae..76616051 100644 --- a/__tests__/install.test.ts +++ b/__tests__/install.test.ts @@ -47,8 +47,7 @@ jest.mock('../src/install', () => ({ } case 'win32': script = await install.build(os_version + '.sh', version, os_version); - script += - 'pwsh script.ps1 -version ' + version + ' -dir ' + __dirname; + script += 'pwsh script.ps1 ' + version + ' ' + __dirname; break; default: script += os_version + ' is not supported'; @@ -90,13 +89,13 @@ describe('Install', () => { // @ts-ignore let script: string = await install.run(); expect(script).toContain('initial script'); - expect(script).toContain('pwsh script.ps1 -version 7.0 -dir ' + __dirname); + expect(script).toContain('pwsh script.ps1 7.0 ' + __dirname); setEnv('7.3', 'win32', '', '', '', ''); // @ts-ignore script = await install.run(); expect(script).toContain('initial script'); - expect(script).toContain('pwsh script.ps1 -version 7.3 -dir ' + __dirname); + expect(script).toContain('pwsh script.ps1 7.3 ' + __dirname); setEnv('7.3', 'win32', 'a, b', 'a=b', 'x', ''); // @ts-ignore @@ -105,7 +104,7 @@ describe('Install', () => { expect(script).toContain('install extensions'); expect(script).toContain('edit php.ini'); expect(script).toContain('set coverage driver'); - expect(script).toContain('pwsh script.ps1 -version 7.3 -dir ' + __dirname); + expect(script).toContain('pwsh script.ps1 7.3 ' + __dirname); }); it('Test install on linux', async () => { diff --git a/dist/index.js b/dist/index.js index 1e140d0a..fdcdabc9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1570,8 +1570,9 @@ const config = __importStar(__webpack_require__(641)); * * @param version * @param os_version + * @param pipe */ -function addCoverageXdebug(version, os_version) { +function addCoverageXdebug(version, os_version, pipe) { return __awaiter(this, void 0, void 0, function* () { switch (version) { case '8.0': @@ -1580,7 +1581,7 @@ function addCoverageXdebug(version, os_version) { case '7.4': default: return ((yield extensions.addExtension('xdebug', version, os_version, true)) + - (yield utils.suppressOutput(os_version)) + + pipe + '\n' + (yield utils.addLog('$tick', 'xdebug', 'Xdebug enabled as coverage driver', os_version))); } @@ -1592,47 +1593,27 @@ exports.addCoverageXdebug = addCoverageXdebug; * * @param version * @param os_version + * @param pipe */ -function addCoveragePCOV(version, os_version) { +function addCoveragePCOV(version, os_version, pipe) { return __awaiter(this, void 0, void 0, function* () { let script = '\n'; switch (version) { default: script += (yield extensions.addExtension('pcov', version, os_version, true)) + - (yield utils.suppressOutput(os_version)) + + pipe + '\n'; script += (yield config.addINIValues('pcov.enabled=1', os_version, true)) + '\n'; // add command to disable xdebug and enable pcov switch (os_version) { case 'linux': - script += - 'if [ -e /etc/php/' + - version + - '/mods-available/xdebug.ini ]; then sudo phpdismod -v ' + - version + - ' xdebug; fi\n'; - script += 'sudo sed -i "/xdebug/d" "$ini_file"\n'; - script += - 'sudo DEBIAN_FRONTEND=noninteractive apt-fast remove php-xdebug -y ' + - (yield utils.suppressOutput('linux')) + - '\n'; - break; case 'darwin': - script += 'sudo sed -i \'\' "/xdebug/d" "$ini_file"\n'; - script += - 'sudo rm -rf "$ext_dir"/xdebug.so ' + - (yield utils.suppressOutput('darwin')) + - '\n'; + script += 'remove_extension xdebug' + pipe + '\n'; break; case 'win32': - script += - 'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug $php_dir }\n'; - script += - 'if (Test-Path $ext_dir\\php_xdebug.dll) { Remove-Item $ext_dir\\php_xdebug.dll }' + - (yield utils.suppressOutput('win32')) + - '\n'; + script += 'Remove-Extension xdebug' + pipe + '\n'; break; } // success @@ -1653,56 +1634,20 @@ exports.addCoveragePCOV = addCoveragePCOV; * * @param version * @param os_version + * @param pipe */ -function disableCoverage(version, os_version) { +function disableCoverage(version, os_version, pipe) { return __awaiter(this, void 0, void 0, function* () { let script = '\n'; switch (os_version) { case 'linux': - script += - 'if [ -e /etc/php/' + - version + - '/mods-available/xdebug.ini ]; then sudo phpdismod -v ' + - version + - ' xdebug; fi\n'; - script += - 'if [ -e /etc/php/' + - version + - '/mods-available/pcov.ini ]; then sudo phpdismod -v ' + - version + - ' pcov; fi\n'; - script += 'sudo sed -i "/xdebug/d" "$ini_file"\n'; - script += 'sudo sed -i "/pcov/d" "$ini_file"\n'; - script += - 'sudo DEBIAN_FRONTEND=noninteractive apt-fast remove php-xdebug php-pcov -y ' + - (yield utils.suppressOutput('linux')) + - '\n'; - break; case 'darwin': - script += 'sudo sed -i \'\' "/xdebug/d" "$ini_file"\n'; - script += 'sudo sed -i \'\' "/pcov/d" "$ini_file"\n'; - script += - 'sudo rm -rf "$ext_dir"/xdebug.so ' + - (yield utils.suppressOutput('darwin')) + - '\n'; - script += - 'sudo rm -rf "$ext_dir"/pcov.so ' + - (yield utils.suppressOutput('darwin')) + - '\n'; + script += 'remove_extension xdebug' + pipe + '\n'; + script += 'remove_extension pcov' + pipe + '\n'; break; case 'win32': - script += - 'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug $php_dir }\n'; - script += - 'if(php -m | findstr -i pcov) { Disable-PhpExtension pcov $php_dir }\n'; - script += - 'if (Test-Path $ext_dir\\php_xdebug.dll) { Remove-Item $ext_dir\\php_xdebug.dll }' + - (yield utils.suppressOutput('win32')) + - '\n'; - script += - 'if (Test-Path $ext_dir\\php_pcov.dll) { Remove-Item $ext_dir\\php_pcov.dll }' + - (yield utils.suppressOutput('win32')) + - '\n'; + script += 'Remove-Extension xdebug' + pipe + '\n'; + script += 'Remove-Extension pcov' + pipe + '\n'; break; } script += yield utils.addLog('$tick', 'none', 'Disabled Xdebug and PCOV', os_version); @@ -1721,13 +1666,14 @@ function addCoverage(coverage_driver, version, os_version) { return __awaiter(this, void 0, void 0, function* () { coverage_driver.toLowerCase(); const script = '\n' + (yield utils.stepLog('Setup Coverage', os_version)); + const pipe = yield utils.suppressOutput(os_version); switch (coverage_driver) { case 'pcov': - return script + (yield addCoveragePCOV(version, os_version)); + return script + (yield addCoveragePCOV(version, os_version, pipe)); case 'xdebug': - return script + (yield addCoverageXdebug(version, os_version)); + return script + (yield addCoverageXdebug(version, os_version, pipe)); case 'none': - return script + (yield disableCoverage(version, os_version)); + return script + (yield disableCoverage(version, os_version, pipe)); default: return ''; } @@ -1922,7 +1868,7 @@ function run() { } case 'win32': script_path = yield build('win32.ps1', version, os_version); - yield exec_1.exec('pwsh ' + script_path + ' -version ' + version + ' -dir ' + __dirname); + yield exec_1.exec('pwsh ' + script_path + ' ' + version + ' ' + __dirname); break; } yield matchers.addMatchers(); @@ -2184,28 +2130,35 @@ const utils = __importStar(__webpack_require__(163)); * * @param extension_csv * @param version + * @param pipe */ -function addExtensionDarwin(extension_csv, version) { +function addExtensionDarwin(extension_csv, version, pipe) { return __awaiter(this, void 0, void 0, function* () { const 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(); + const version_extension = version + extension; // add script to enable extension is already installed along with php let install_command = ''; switch (true) { - case /5\.6xdebug/.test(version + extension): - install_command = 'sudo pecl install xdebug-2.5.5 >/dev/null 2>&1'; + case /5\.6xdebug/.test(version_extension): + install_command = 'sudo pecl install xdebug-2.5.5' + pipe; break; - case /5\.6redis/.test(version + extension): - install_command = 'sudo pecl install redis-2.2.8 >/dev/null 2>&1'; + case /5\.6redis/.test(version_extension): + install_command = 'sudo pecl install redis-2.2.8' + pipe; + break; + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): + install_command = + 'sh ' + + path.join(__dirname, '../src/scripts/ext/phalcon_darwin.sh') + + ' ' + + extension + + pipe; break; - case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): - script += '\nadd_phalcon ' + extension; - return; default: - install_command = 'sudo pecl install ' + extension + ' >/dev/null 2>&1'; + install_command = 'sudo pecl install ' + extension + pipe; break; } script += @@ -2226,18 +2179,27 @@ exports.addExtensionDarwin = addExtensionDarwin; * * @param extension_csv * @param version + * @param pipe */ -function addExtensionWindows(extension_csv, version) { +function addExtensionWindows(extension_csv, version, pipe) { return __awaiter(this, void 0, void 0, function* () { const extensions = yield utils.extensionArray(extension_csv); let script = '\n'; yield utils.asyncForEach(extensions, function (extension) { return __awaiter(this, void 0, void 0, function* () { // add script to enable extension is already installed along with php + const version_extension = version + extension; switch (true) { // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 - case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): - script += '\nAdd-Phalcon ' + extension; + 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'; break; default: script += '\nAdd-Extension ' + extension; @@ -2254,8 +2216,9 @@ exports.addExtensionWindows = addExtensionWindows; * * @param extension_csv * @param version + * @param pipe */ -function addExtensionLinux(extension_csv, version) { +function addExtensionLinux(extension_csv, version, pipe) { return __awaiter(this, void 0, void 0, function* () { const extensions = yield utils.extensionArray(extension_csv); let script = '\n'; @@ -2263,27 +2226,28 @@ 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 + const version_extension = version + extension; let install_command = ''; switch (true) { // match 5.6gearman..7.4gearman - case /^((5\.6)|(7\.[0-4]))gearman$/.test(version + extension): + case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension): install_command = 'sh ' + - path.join(__dirname, '../src/scripts/gearman.sh') + + path.join(__dirname, '../src/scripts/ext/gearman.sh') + ' ' + version + - ' >/dev/null 2>&1'; + pipe; break; // match 7.0phalcon3..7.3phalcon3 and 7.2phalcon4...7.4phalcon4 - case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): install_command = 'sh ' + - path.join(__dirname, '../src/scripts/phalcon.sh') + + path.join(__dirname, '../src/scripts/ext/phalcon.sh') + ' ' + extension + ' ' + version + - ' >/dev/null 2>&1'; + pipe; break; default: install_command = @@ -2291,9 +2255,10 @@ function addExtensionLinux(extension_csv, version) { version + '-' + extension.replace('pdo_', '').replace('pdo-', '') + - ' >/dev/null 2>&1 || sudo pecl install ' + + pipe + + ' || sudo pecl install ' + extension + - ' >/dev/null 2>&1'; + pipe; break; } script += @@ -2319,12 +2284,11 @@ exports.addExtensionLinux = addExtensionLinux; */ function addExtension(extension_csv, version, os_version, no_step = false) { return __awaiter(this, void 0, void 0, function* () { + const pipe = yield utils.suppressOutput(os_version); let script = '\n'; switch (no_step) { case true: - script += - (yield utils.stepLog('Setup Extensions', os_version)) + - (yield utils.suppressOutput(os_version)); + script += (yield utils.stepLog('Setup Extensions', os_version)) + pipe; break; case false: default: @@ -2333,11 +2297,11 @@ function addExtension(extension_csv, version, os_version, no_step = false) { } switch (os_version) { case 'win32': - return script + (yield addExtensionWindows(extension_csv, version)); + return script + (yield addExtensionWindows(extension_csv, version, pipe)); case 'darwin': - return script + (yield addExtensionDarwin(extension_csv, version)); + return script + (yield addExtensionDarwin(extension_csv, version, pipe)); case 'linux': - return script + (yield addExtensionLinux(extension_csv, version)); + return script + (yield addExtensionLinux(extension_csv, version, pipe)); default: return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error'); } diff --git a/src/ext/php_pcov.dll b/src/bin/php_pcov.dll similarity index 100% rename from src/ext/php_pcov.dll rename to src/bin/php_pcov.dll diff --git a/src/coverage.ts b/src/coverage.ts index 4b6e0275..7b2996a3 100644 --- a/src/coverage.ts +++ b/src/coverage.ts @@ -7,10 +7,12 @@ import * as config from './config'; * * @param version * @param os_version + * @param pipe */ export async function addCoverageXdebug( version: string, - os_version: string + os_version: string, + pipe: string ): Promise { switch (version) { case '8.0': @@ -27,7 +29,7 @@ export async function addCoverageXdebug( default: return ( (await extensions.addExtension('xdebug', version, os_version, true)) + - (await utils.suppressOutput(os_version)) + + pipe + '\n' + (await utils.addLog( '$tick', @@ -44,17 +46,19 @@ export async function addCoverageXdebug( * * @param version * @param os_version + * @param pipe */ export async function addCoveragePCOV( version: string, - os_version: string + os_version: string, + pipe: string ): Promise { let script = '\n'; switch (version) { default: script += (await extensions.addExtension('pcov', version, os_version, true)) + - (await utils.suppressOutput(os_version)) + + pipe + '\n'; script += (await config.addINIValues('pcov.enabled=1', os_version, true)) + '\n'; @@ -62,32 +66,11 @@ export async function addCoveragePCOV( // add command to disable xdebug and enable pcov switch (os_version) { case 'linux': - script += - 'if [ -e /etc/php/' + - version + - '/mods-available/xdebug.ini ]; then sudo phpdismod -v ' + - version + - ' xdebug; fi\n'; - script += 'sudo sed -i "/xdebug/d" "$ini_file"\n'; - script += - 'sudo DEBIAN_FRONTEND=noninteractive apt-fast remove php-xdebug -y ' + - (await utils.suppressOutput('linux')) + - '\n'; - break; case 'darwin': - script += 'sudo sed -i \'\' "/xdebug/d" "$ini_file"\n'; - script += - 'sudo rm -rf "$ext_dir"/xdebug.so ' + - (await utils.suppressOutput('darwin')) + - '\n'; + script += 'remove_extension xdebug' + pipe + '\n'; break; case 'win32': - script += - 'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug $php_dir }\n'; - script += - 'if (Test-Path $ext_dir\\php_xdebug.dll) { Remove-Item $ext_dir\\php_xdebug.dll }' + - (await utils.suppressOutput('win32')) + - '\n'; + script += 'Remove-Extension xdebug' + pipe + '\n'; break; } @@ -119,58 +102,23 @@ export async function addCoveragePCOV( * * @param version * @param os_version + * @param pipe */ export async function disableCoverage( version: string, - os_version: string + os_version: string, + pipe: string ): Promise { let script = '\n'; switch (os_version) { case 'linux': - script += - 'if [ -e /etc/php/' + - version + - '/mods-available/xdebug.ini ]; then sudo phpdismod -v ' + - version + - ' xdebug; fi\n'; - script += - 'if [ -e /etc/php/' + - version + - '/mods-available/pcov.ini ]; then sudo phpdismod -v ' + - version + - ' pcov; fi\n'; - script += 'sudo sed -i "/xdebug/d" "$ini_file"\n'; - script += 'sudo sed -i "/pcov/d" "$ini_file"\n'; - script += - 'sudo DEBIAN_FRONTEND=noninteractive apt-fast remove php-xdebug php-pcov -y ' + - (await utils.suppressOutput('linux')) + - '\n'; - break; case 'darwin': - script += 'sudo sed -i \'\' "/xdebug/d" "$ini_file"\n'; - script += 'sudo sed -i \'\' "/pcov/d" "$ini_file"\n'; - script += - 'sudo rm -rf "$ext_dir"/xdebug.so ' + - (await utils.suppressOutput('darwin')) + - '\n'; - script += - 'sudo rm -rf "$ext_dir"/pcov.so ' + - (await utils.suppressOutput('darwin')) + - '\n'; + script += 'remove_extension xdebug' + pipe + '\n'; + script += 'remove_extension pcov' + pipe + '\n'; break; case 'win32': - script += - 'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug $php_dir }\n'; - script += - 'if(php -m | findstr -i pcov) { Disable-PhpExtension pcov $php_dir }\n'; - script += - 'if (Test-Path $ext_dir\\php_xdebug.dll) { Remove-Item $ext_dir\\php_xdebug.dll }' + - (await utils.suppressOutput('win32')) + - '\n'; - script += - 'if (Test-Path $ext_dir\\php_pcov.dll) { Remove-Item $ext_dir\\php_pcov.dll }' + - (await utils.suppressOutput('win32')) + - '\n'; + script += 'Remove-Extension xdebug' + pipe + '\n'; + script += 'Remove-Extension pcov' + pipe + '\n'; break; } script += await utils.addLog( @@ -198,13 +146,14 @@ export async function addCoverage( coverage_driver.toLowerCase(); const script: string = '\n' + (await utils.stepLog('Setup Coverage', os_version)); + const pipe: string = await utils.suppressOutput(os_version); switch (coverage_driver) { case 'pcov': - return script + (await addCoveragePCOV(version, os_version)); + return script + (await addCoveragePCOV(version, os_version, pipe)); case 'xdebug': - return script + (await addCoverageXdebug(version, os_version)); + return script + (await addCoverageXdebug(version, os_version, pipe)); case 'none': - return script + (await disableCoverage(version, os_version)); + return script + (await disableCoverage(version, os_version, pipe)); default: return ''; } diff --git a/src/extensions.ts b/src/extensions.ts index 3f76d86a..36583669 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -6,29 +6,37 @@ import * as utils from './utils'; * * @param extension_csv * @param version + * @param pipe */ export async function addExtensionDarwin( extension_csv: string, - version: string + version: string, + pipe: string ): Promise { const extensions: Array = await utils.extensionArray(extension_csv); let script = '\n'; await utils.asyncForEach(extensions, async function(extension: string) { extension = extension.toLowerCase(); + const version_extension: string = version + extension; // add script to enable extension is already installed along with php let install_command = ''; switch (true) { - case /5\.6xdebug/.test(version + extension): - install_command = 'sudo pecl install xdebug-2.5.5 >/dev/null 2>&1'; + case /5\.6xdebug/.test(version_extension): + install_command = 'sudo pecl install xdebug-2.5.5' + pipe; break; - case /5\.6redis/.test(version + extension): - install_command = 'sudo pecl install redis-2.2.8 >/dev/null 2>&1'; + case /5\.6redis/.test(version_extension): + install_command = 'sudo pecl install redis-2.2.8' + pipe; + break; + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): + install_command = + 'sh ' + + path.join(__dirname, '../src/scripts/ext/phalcon_darwin.sh') + + ' ' + + extension + + pipe; break; - case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): - script += '\nadd_phalcon ' + extension; - return; default: - install_command = 'sudo pecl install ' + extension + ' >/dev/null 2>&1'; + install_command = 'sudo pecl install ' + extension + pipe; break; } script += @@ -47,19 +55,29 @@ export async function addExtensionDarwin( * * @param extension_csv * @param version + * @param pipe */ export async function addExtensionWindows( extension_csv: string, - version: string + version: string, + pipe: string ): Promise { const extensions: Array = await utils.extensionArray(extension_csv); let script = '\n'; await utils.asyncForEach(extensions, async function(extension: string) { // add script to enable extension is already installed along with php + const version_extension: string = version + extension; switch (true) { // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 - case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): - script += '\nAdd-Phalcon ' + extension; + 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'; break; default: script += '\nAdd-Extension ' + extension; @@ -74,38 +92,40 @@ export async function addExtensionWindows( * * @param extension_csv * @param version + * @param pipe */ export async function addExtensionLinux( extension_csv: string, - version: string + version: string, + pipe: string ): Promise { const extensions: Array = await utils.extensionArray(extension_csv); let script = '\n'; await utils.asyncForEach(extensions, async function(extension: string) { extension = extension.toLowerCase(); // add script to enable extension is already installed along with php - + const version_extension: string = version + extension; let install_command = ''; switch (true) { // match 5.6gearman..7.4gearman - case /^((5\.6)|(7\.[0-4]))gearman$/.test(version + extension): + case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension): install_command = 'sh ' + - path.join(__dirname, '../src/scripts/gearman.sh') + + path.join(__dirname, '../src/scripts/ext/gearman.sh') + ' ' + version + - ' >/dev/null 2>&1'; + pipe; break; // match 7.0phalcon3..7.3phalcon3 and 7.2phalcon4...7.4phalcon4 - case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): install_command = 'sh ' + - path.join(__dirname, '../src/scripts/phalcon.sh') + + path.join(__dirname, '../src/scripts/ext/phalcon.sh') + ' ' + extension + ' ' + version + - ' >/dev/null 2>&1'; + pipe; break; default: install_command = @@ -113,9 +133,10 @@ export async function addExtensionLinux( version + '-' + extension.replace('pdo_', '').replace('pdo-', '') + - ' >/dev/null 2>&1 || sudo pecl install ' + + pipe + + ' || sudo pecl install ' + extension + - ' >/dev/null 2>&1'; + pipe; break; } script += @@ -143,12 +164,11 @@ export async function addExtension( os_version: string, no_step = false ): Promise { + const pipe: string = await utils.suppressOutput(os_version); let script = '\n'; switch (no_step) { case true: - script += - (await utils.stepLog('Setup Extensions', os_version)) + - (await utils.suppressOutput(os_version)); + script += (await utils.stepLog('Setup Extensions', os_version)) + pipe; break; case false: default: @@ -158,11 +178,11 @@ export async function addExtension( switch (os_version) { case 'win32': - return script + (await addExtensionWindows(extension_csv, version)); + return script + (await addExtensionWindows(extension_csv, version, pipe)); case 'darwin': - return script + (await addExtensionDarwin(extension_csv, version)); + return script + (await addExtensionDarwin(extension_csv, version, pipe)); case 'linux': - return script + (await addExtensionLinux(extension_csv, version)); + return script + (await addExtensionLinux(extension_csv, version, pipe)); default: return await utils.log( 'Platform ' + os_version + ' is not supported', diff --git a/src/install.ts b/src/install.ts index 1d7fd741..c0b8f97f 100644 --- a/src/install.ts +++ b/src/install.ts @@ -65,9 +65,7 @@ export async function run(): Promise { } case 'win32': script_path = await build('win32.ps1', version, os_version); - await exec( - 'pwsh ' + script_path + ' -version ' + version + ' -dir ' + __dirname - ); + await exec('pwsh ' + script_path + ' ' + version + ' ' + __dirname); break; } await matchers.addMatchers(); diff --git a/src/scripts/7.4.sh b/src/scripts/7.4.sh deleted file mode 100644 index 723dcaac..00000000 --- a/src/scripts/7.4.sh +++ /dev/null @@ -1,116 +0,0 @@ -tick="✓" -cross="✗" - -step_log() { - message=$1 - printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message" -} - -add_log() { - mark=$1 - subject=$2 - message=$3 - if [ "$mark" = "$tick" ]; then - printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message" - else - printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message" - fi -} -version='7.4.0' -step_log "Setup dependencies" -for package in pkg-config autoconf bison re2c openssl@1.1 krb5 enchant libffi freetype intltool icu4c libiconv t1lib gd libzip gmp tidyp libxml2 libxslt postgresql curl; -do - brew install "$package" >/dev/null 2>&1 - add_log "$tick" "$package" "Installed" -done -brew link icu4c gettext --force >/dev/null 2>&1 - -for package in gettext gmp krb5 icu4c bison openssl@1.1 libxml2 libffi libxslt libiconv pkgconfig enchant krb5 readline libedit freetype; -do - caps_package=$(echo "$package" | tr '[:lower:]' '[:upper:]') - { - echo 'export PATH="/usr/local/opt/'"$package"'/bin:$PATH"' - echo 'export PKG_CONFIG_PATH="/usr/local/opt/'$package'/lib/pkgconfig:$PKG_CONFIG_PATH"' - echo 'export '"$caps_package"'_LIBS="-L/usr/local/opt/'$package'/lib"' - echo 'export '"$caps_package"'_CFLAGS="-I/usr/local/opt/'$package'/include"' - } >> ~/.bash_profile; -done -{ -echo 'export ICONV_LIBS="-L/usr/local/opt/libiconv/lib"' -echo 'export ICONV_CFLAGS="-I/usr/local/opt/libiconv/include"' -echo 'export LIBXML_LIBS="-L/usr/local/opt/libxml2/lib"' -echo 'export LIBXML_CFLAGS="-I/usr/local/opt/libxml2/include"' -echo 'export ICU_LIBS="-L/usr/local/opt/icu4c/lib"' -echo 'export ICU_CFLAGS="-I/usr/local/opt/icu4c/include"' -echo 'export OPENSSL_LIBS="-L/usr/local/opt/openssl@1.1/lib -lcrypto"' -echo 'export OPENSSL_CFLAGS="-I/usr/local/opt/openssl@1.1/include"' -echo 'export OPENSSL_ROOT_DIR="/usr/local/opt/openssl@1.1/"' -echo 'export OPENSSL_LIB_DIR="/usr/local/opt/openssl@1.1/lib"' -echo 'export OPENSSL_INCLUDE_DIR="/usr/local/opt/openssl@1.1/include"' -echo 'export PKG_CONFIG="/usr/local/opt/pkgconfig/bin/pkg-config"' -echo 'export EXTRA_LIBS="/usr/local/opt/readline/lib/libhistory.dylib -/usr/local/opt/readline/lib/libreadline.dylib -/usr/local/opt/openssl@1.1/lib/libssl.dylib -/usr/local/opt/openssl@1.1/lib/libcrypto.dylib -/usr/local/opt/icu4c/lib/libicudata.dylib -/usr/local/opt/icu4c/lib/libicui18n.dylib -/usr/local/opt/icu4c/lib/libicuio.dylib -/usr/local/opt/icu4c/lib/libicutu.dylib -/usr/local/opt/icu4c/lib/libicuuc.dylib"' -} >> ~/.bash_profile -config_file=$2/../src/configs/config.yaml - -step_log "Setup PHPBrew" -curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew >/dev/null 2>&1 -chmod +x ./phpbrew -sudo mv phpbrew /usr/local/bin/phpbrew -sudo mkdir -p /opt/phpbrew -sudo mkdir -p /usr/local/lib -sudo mkdir -p /usr/local/bin -sudo phpbrew init --root=/opt/phpbrew --config="$config_file" >/dev/null 2>&1 -sudo chmod -R 777 /opt/phpbrew -export PHPBREW_ROOT=/opt/phpbrew -export PHPBREW_HOME=/opt/phpbrew -echo "[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc" >> ~/.bashrc -add_log "$tick" "PHPBrew" "Installed" - -source ~/.bash_profile >/dev/null 2>&1 -source ~/.bashrc >/dev/null 2>&1 - -step_log "Setup PHP and Composer" -phpbrew install -j 6 github:php/php-src@PHP-$version as php-$version +dev >/dev/null 2>&1 -phpbrew switch $version -sudo ln -sf /opt/phpbrew/php/php-$version/bin/* /usr/local/bin/ -sudo ln -sf /opt/phpbrew/php/php-$version/etc/php.ini /etc/php.ini -ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") -ext_dir=$(php -i | grep "extension_dir => /opt" | sed -e "s|.*=> s*||") -pecl config-set php_ini "$ini_file" >/dev/null 2>&1 -pear config-set php_ini "$ini_file" >/dev/null 2>&1 -sudo chmod 777 "$ini_file" -brew install composer >/dev/null 2>&1 - -add_log "$tick" "PHP" "Installed PHP$version" -add_log "$tick" "Composer" "Installed" - -add_extension() { - extension=$1 - install_command=$2 - prefix=$3 - if ! php -m | grep -i -q "$extension" && [ -e "$ext_dir/$extension.so" ]; then - echo "$prefix=$extension" >>"$ini_file" && add_log "$tick" "$extension" "Enabled" - elif php -m | grep -i -q "$extension"; then - add_log "$tick" "$extension" "Enabled" - elif ! php -m | grep -i -q "$extension"; then - exists=$(curl -sL https://pecl.php.net/json.php?package="$extension" -w "%{http_code}" -o /dev/null) - if [ "$exists" = "200" ]; then - ( - eval "$install_command" && \ - add_log "$tick" "$extension" "Installed and enabled" - ) || add_log "$cross" "$extension" "Could not install $extension on PHP$version" - else - if ! php -m | grep -i -q "$extension"; then - add_log "$cross" "$extension" "Could not find $extension for PHP$version on PECL" - fi - fi - fi -} \ No newline at end of file diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index e4d68bba..b3a78a36 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -27,7 +27,7 @@ add_extension() { add_log "$tick" "$extension" "Enabled" elif ! php -m | grep -i -q -w "$extension"; then exists=$(curl -sL https://pecl.php.net/json.php?package="$extension" -w "%{http_code}" -o /dev/null) - if [ "$exists" = "200" ]; then + if [ "$exists" = "200" ] || [[ "$extension" == "phalcon"* ]]; then ( eval "$install_command" && \ add_log "$tick" "$extension" "Installed and enabled" @@ -40,20 +40,11 @@ add_extension() { fi } -add_phalcon() { +# Function to remove extensions +remove_extension() { extension=$1 - sudo pecl install psr >/dev/null 2>&1 - brew install autoconf automake libtool >/dev/null 2>&1 - git clone https://github.com/phalcon/cphalcon.git >/dev/null 2>&1 - cd cphalcon || echo "could not cd" - git checkout "$(git branch -r | grep -E "origin/${extension: -1}\.\d\.x" | sort -r | head -n 1 | sed "s/ //g")" >/dev/null 2>&1 - sed -i '' 's/zend_ulong/ulong/' build/php7/64bits/phalcon.zep.c - sed -i '' 's/ulong/zend_ulong/' build/php7/64bits/phalcon.zep.c - cd build/php7/64bits && sudo phpize >/dev/null 2>&1 - sudo ./configure --with-php-config=/usr/local/bin/php-config --enable-phalcon >/dev/null 2>&1 - sudo glibtoolize --force >/dev/null 2>&1 && sudo autoreconf >/dev/null 2>&1 - sudo make -i -j2 >/dev/null 2>&1 && sudo make install >/dev/null 2>&1 - echo "extension=phalcon.so" >>"$ini_file" && add_log "$tick" "$extension" "Installed and enabled" + sudo sed -i '' "/$1/d" "$ini_file" + sudo rm -rf "$ext_dir"/"$1".so >/dev/null 2>&1 } # Function to setup PHP and composer diff --git a/src/scripts/gearman.sh b/src/scripts/ext/gearman.sh similarity index 100% rename from src/scripts/gearman.sh rename to src/scripts/ext/gearman.sh diff --git a/src/scripts/pcov.sh b/src/scripts/ext/pcov.sh similarity index 100% rename from src/scripts/pcov.sh rename to src/scripts/ext/pcov.sh diff --git a/src/scripts/ext/phalcon.ps1 b/src/scripts/ext/phalcon.ps1 new file mode 100644 index 00000000..977a7005 --- /dev/null +++ b/src/scripts/ext/phalcon.ps1 @@ -0,0 +1,27 @@ +Param ( + [Parameter(Position = 0, Mandatory = $true)] + [ValidateNotNull()] + [ValidateSet('phalcon3', 'phalcon4')] + [string] + $extension, + [Parameter(Position = 1, Mandatory = $true)] + [ValidateNotNull()] + [ValidateLength(1, [int]::MaxValue)] + [string] + $version +) +$tick = ([char]8730) +$domain = 'https://github.com' +$php_dir = 'C:\tools\php' +$ext_dir = $php_dir + '\ext' +$installed = Get-Php -Path $php_dir +$extension_version = $extension.substring($extension.Length - 1) +$nts = if(! $installed.ThreadSafe ) { "_nts" } else { "" } +$match = Invoke-WebRequest -UseBasicParsing -Uri $domain/phalcon/cphalcon/releases | Select-String -Pattern "href=`"(.*phalcon_x64_.*_php${version}_${extension_version}.*[0-9]${nts}.zip)`"" +$zip_file = $match.Matches[0].Groups[1].Value +Invoke-WebRequest -UseBasicParsing -Uri $domain/$zip_file -OutFile $ENV:RUNNER_TOOL_CACHE\phalcon.zip >$null 2>&1 +Expand-Archive -Path $ENV:RUNNER_TOOL_CACHE\phalcon.zip -DestinationPath $ENV:RUNNER_TOOL_CACHE\phalcon -Force >$null 2>&1 +New-Item -ItemType SymbolicLink -Path $ext_dir\php_phalcon.dll -Target $ENV:RUNNER_TOOL_CACHE\phalcon\php_phalcon.dll >$null 2>&1 +Install-Phpextension psr -MinimumStability stable -Path $php_dir +Enable-PhpExtension -Extension phalcon -Path $php_dir +printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "32" $tick $extension "Installed and enabled" \ No newline at end of file diff --git a/src/scripts/phalcon.sh b/src/scripts/ext/phalcon.sh similarity index 100% rename from src/scripts/phalcon.sh rename to src/scripts/ext/phalcon.sh diff --git a/src/scripts/ext/phalcon_darwin.sh b/src/scripts/ext/phalcon_darwin.sh new file mode 100644 index 00000000..bdd17d8e --- /dev/null +++ b/src/scripts/ext/phalcon_darwin.sh @@ -0,0 +1,16 @@ +extension=$1 +ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") +sudo pecl install psr +brew install autoconf automake libtool +git clone https://github.com/phalcon/cphalcon.git +cd cphalcon || echo "could not cd" +git checkout "$(git branch -r | grep -E "origin/${extension: -1}\.\d\.x" | sort -r | head -n 1 | sed "s/ //g")" +sed -i '' 's/zend_ulong/ulong/' build/php7/64bits/phalcon.zep.c +sed -i '' 's/ulong/zend_ulong/' build/php7/64bits/phalcon.zep.c +cd build/php7/64bits && sudo phpize +sudo ./configure --with-php-config=/usr/local/bin/php-config --enable-phalcon +sudo glibtoolize --force +sudo autoreconf +sudo make -i -j6 +sudo make install +echo "extension=phalcon.so" >>"$ini_file" \ No newline at end of file diff --git a/src/scripts/xdebug.sh b/src/scripts/ext/xdebug.sh similarity index 100% rename from src/scripts/xdebug.sh rename to src/scripts/ext/xdebug.sh diff --git a/src/scripts/xdebug_darwin.sh b/src/scripts/ext/xdebug_darwin.sh similarity index 100% rename from src/scripts/xdebug_darwin.sh rename to src/scripts/ext/xdebug_darwin.sh diff --git a/src/scripts/linux.sh b/src/scripts/linux.sh index b18346c8..d22c3259 100644 --- a/src/scripts/linux.sh +++ b/src/scripts/linux.sh @@ -24,7 +24,7 @@ update_ppa() { fi } -# Function to setup extension +# Function to setup extensions add_extension() { extension=$1 install_command=$2 @@ -40,6 +40,16 @@ add_extension() { fi } +# Function to remove extensions +remove_extension() { + extension=$1 + if [ -e /etc/php/"$version"/mods-available/$1.ini ]; then + sudo phpdismod -v "$version" $1 + fi + sudo sed -i "/$1/d" "$ini_file" + sudo DEBIAN_FRONTEND=noninteractive apt-get remove php-$1 -y >/dev/null 2>&1 +} + # Function to setup the nightly build from master branch setup_master() { tar_file=php_"$version"%2Bubuntu"$(lsb_release -r -s)".tar.xz diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index 5d67c86d..66e5849c 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -1,16 +1,16 @@ param ( - [Parameter(Mandatory = $true)][string]$version = "7.4", - [Parameter(Mandatory=$true)][string]$dir + [Parameter(Position = 0, Mandatory = $true)] + [ValidateNotNull()] + [ValidateLength(1, [int]::MaxValue)] + [string] + $version = '7.4', + [Parameter(Position = 1, Mandatory = $true)] + [ValidateNotNull()] + [ValidateLength(1, [int]::MaxValue)] + [string] + $dir ) -$tick = ([char]8730) -$cross = ([char]10007) -$php_dir = 'C:\tools\php' -$ext_dir = $php_dir + '\ext' -$ProgressPreference = 'SilentlyContinue' -$master_version = '8.0' -$arch='x64' - Function Step-Log($message) { printf "\n\033[90;1m==> \033[0m\033[37;1m%s \033[0m\n" $message } @@ -20,49 +20,6 @@ Function Add-Log($mark, $subject, $message) { printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" $code $mark $subject $message } -Step-Log "Setup PhpManager" -Install-Module -Name PhpManager -Force -Scope CurrentUser -Add-Log $tick "PhpManager" "Installed" - -$installed = $null -if (Test-Path -LiteralPath $php_dir -PathType Container) { - try { - $installed = Get-Php -Path $php_dir - } - catch { - } -} -Step-Log "Setup PHP and Composer" -if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.')))) { - if ($version -lt '7.0') { - Install-Module -Name VcRedist -Force - $arch='x86' - } - if ($version -eq $master_version) { - $version = 'master' - } - - Install-Php -Version $version -Architecture $arch -ThreadSafe $true -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1 - $installed = Get-Php -Path $php_dir - $status = "Installed PHP $($installed.FullVersion)" -} -else { - $status = "PHP $($installed.FullVersion) Found" -} - -Set-PhpIniKey -Key 'date.timezone' -Value 'UTC' -Path $php_dir -Enable-PhpExtension -Extension openssl, curl, opcache -Path $php_dir -Update-PhpCAInfo -Path $php_dir -Source CurrentUser -Add-Log $tick "PHP" $status - -Install-Composer -Scope System -Path $php_dir -PhpPath $php_dir -Add-Log $tick "Composer" "Installed" -if ($version -eq 'master') { - Copy-Item $dir"\..\src\ext\php_pcov.dll" -Destination $ext_dir"\php_pcov.dll" - Set-PhpIniKey -Key 'opcache.jit_buffer_size' -Value '256M' -Path $php_dir - Set-PhpIniKey -Key 'opcache.jit' -Value '1235' -Path $php_dir -} - Function Add-Extension { Param ( [Parameter(Position = 0, Mandatory = $true)] @@ -102,28 +59,70 @@ Function Add-Extension { } } -Function Add-Phalcon { +Function Remove-Extension() { Param ( [Parameter(Position = 0, Mandatory = $true)] [ValidateNotNull()] - [ValidateSet('phalcon3', 'phalcon4')] + [ValidateLength(1, [int]::MaxValue)] [string] $extension ) - $extension_version = $extension.substring($extension.Length - 1) - $nts = if(! $installed.ThreadSafe ) { "_nts" } else { "" } - $domain = "https://github.com" - Install-Phpextension psr - try - { - $match = Invoke-WebRequest -UseBasicParsing -Uri $domain/phalcon/cphalcon/releases | Select-String -Pattern "href=`"(.*phalcon_${arch}_.*_php${version}_${extension_version}.*[0-9]${nts}.zip)`"" - $zip_file = $match.Matches[0].Groups[1].Value - Invoke-WebRequest -UseBasicParsing -Uri $domain/$zip_file -OutFile $PSScriptRoot\phalcon.zip - Expand-Archive -Path $PSScriptRoot\phalcon.zip -DestinationPath $PSScriptRoot\phalcon -Force > $null 2>&1 - New-Item -ItemType SymbolicLink -Path $ext_dir\php_phalcon.dll -Target $PSScriptRoot\phalcon\php_phalcon.dll > $null 2>&1 - Enable-PhpExtension -Extension phalcon -Path $php_dir - Add-Log $tick $extension "Installed and enabled" - } catch { - Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)" + if(php -m | findstr -i $extension) { + Disable-PhpExtension $extension $php_dir + } + if (Test-Path $ext_dir\php_$extension.dll) { + Remove-Item $ext_dir\php_$extension.dll } } + +# Variables +$tick = ([char]8730) +$cross = ([char]10007) +$php_dir = 'C:\tools\php' +$ext_dir = $php_dir + '\ext' +$ProgressPreference = 'SilentlyContinue' +$master_version = '8.0' +$arch='x64' + +Step-Log "Setup PhpManager" +Install-Module -Name PhpManager -Force -Scope CurrentUser +Add-Log $tick "PhpManager" "Installed" + +$installed = $null +if (Test-Path -LiteralPath $php_dir -PathType Container) { + try { + $installed = Get-Php -Path $php_dir + } + catch { + } +} +Step-Log "Setup PHP and Composer" +if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.')))) { + if ($version -lt '7.0') { + Install-Module -Name VcRedist -Force + $arch='x86' + } + if ($version -eq $master_version) { + $version = 'master' + } + + Install-Php -Version $version -Architecture $arch -ThreadSafe $true -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1 + $installed = Get-Php -Path $php_dir + $status = "Installed PHP $($installed.FullVersion)" +} +else { + $status = "PHP $($installed.FullVersion) Found" +} + +Set-PhpIniKey -Key 'date.timezone' -Value 'UTC' -Path $php_dir +Enable-PhpExtension -Extension openssl, curl, opcache -Path $php_dir +Update-PhpCAInfo -Path $php_dir -Source CurrentUser +if ($version -eq 'master') { + Copy-Item $dir"\..\src\bin\php_pcov.dll" -Destination $ext_dir"\php_pcov.dll" + Set-PhpIniKey -Key 'opcache.jit_buffer_size' -Value '256M' -Path $php_dir + Set-PhpIniKey -Key 'opcache.jit' -Value '1235' -Path $php_dir +} +Add-Log $tick "PHP" $status + +Install-Composer -Scope System -Path $php_dir -PhpPath $php_dir +Add-Log $tick "Composer" "Installed"