From cb287308be2f31deb52a1048ea07db940cb03a35 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Mon, 23 Dec 2019 23:19:38 +0530 Subject: [PATCH] Add support for phalcon on windows #128 --- __tests__/extensions.test.ts | 6 ++++-- dist/index.js | 7 +++++-- src/extensions.ts | 7 +++++-- src/scripts/win32.ps1 | 21 +++++++++++++++++++++ 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 5aa82106c..9e2074e41 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -3,20 +3,22 @@ import * as extensions from '../src/extensions'; describe('Extension tests', () => { it('checking addExtensionOnWindows', async () => { let win32: string = await extensions.addExtension( - 'xdebug, pcov, redis', + 'xdebug, pcov, redis, phalcon4', '7.4', 'win32' ); expect(win32).toContain('Add-Extension xdebug'); expect(win32).toContain('Add-Extension pcov'); expect(win32).toContain('Add-Extension redis beta'); + expect(win32).toContain('Add-Phalcon phalcon4'); win32 = await extensions.addExtension( - 'does_not_exist', + 'phalcon3, does_not_exist', '7.2', 'win32', true ); + expect(win32).toContain('Add-Phalcon phalcon3'); expect(win32).toContain('Add-Extension does_not_exist'); win32 = await extensions.addExtension('xdebug', '7.2', 'fedora'); diff --git a/dist/index.js b/dist/index.js index accea60ce..a0a23f074 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2231,10 +2231,13 @@ function addExtensionWindows(extension_csv, version) { 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 - switch (version + extension) { - case '7.4redis': + switch (true) { + case /^7\.4redis$/.test(version + extension): script += '\nAdd-Extension ' + extension + ' beta'; break; + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): + script += '\nAdd-Phalcon ' + extension; + break; default: script += '\nAdd-Extension ' + extension; break; diff --git a/src/extensions.ts b/src/extensions.ts index b10fd33ea..6eb877663 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -53,10 +53,13 @@ export async function addExtensionWindows( let script = '\n'; await utils.asyncForEach(extensions, async function(extension: string) { // add script to enable extension is already installed along with php - switch (version + extension) { - case '7.4redis': + switch (true) { + case /^7\.4redis$/.test(version + extension): script += '\nAdd-Extension ' + extension + ' beta'; break; + case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version + extension): + script += '\nAdd-Phalcon ' + extension; + break; default: script += '\nAdd-Extension ' + extension; break; diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index 7193d900c..a08e8db6a 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -63,6 +63,27 @@ if ($version -eq 'master') { Set-PhpIniKey -Key 'opcache.jit' -Value '1235' -Path $php_dir } +Function Add-Phalcon { + Param ( + [Parameter(Position = 0, Mandatory = $true)] + [ValidateNotNull()] + [ValidateSet('phalcon3', 'phalcon4')] + [string] + $extension + ) + Install-Phpextension psr + $extension_version = $extension.substring($extension.Length - 1) + $domain_uri = "https://github.com" + $uri = Invoke-WebRequest -UseBasicParsing -Uri $domain_uri/phalcon/cphalcon/releases | ` + Select-String -Pattern "href=`"(.*phalcon_${arch}_.*_php${version}_${extension_version}.*[0-9].zip)`"" | ` + ForEach-Object { $_.matches.groups[1].value } | ` + Select-Object -Index 0 + Invoke-WebRequest -UseBasicParsing -Uri $domain_uri/$uri -OutFile $ENV:TEMP\phalcon.zip + Expand-Archive -Path $ENV:TEMP\phalcon.zip -DestinationPath $ENV:TEMP\phalcon -Force + Copy-Item -Path $ENV:TEMP\phalcon\php_phalcon.dll -Destination $ext_dir + Enable-Phpextension phalcon +} + Function Add-Extension { Param ( [Parameter(Position = 0, Mandatory = $true)]