Add support for symfony in tools input

This commit is contained in:
Shivam Mathur 2020-01-26 11:11:36 +05:30
parent 8e5cc09df9
commit c844c7b6e4
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
4 changed files with 127 additions and 17 deletions

View File

@ -206,6 +206,30 @@ describe('Tools tests', () => {
).toStrictEqual(['composer', 'a', 'b']);
});
it('checking getSymfonyUri', async () => {
expect(await tools.getSymfonyUri('latest', 'linux')).toContain(
'releases/latest/download/symfony_linux_amd64'
);
expect(await tools.getSymfonyUri('1.2.3', 'linux')).toContain(
'releases/download/v1.2.3/symfony_linux_amd64'
);
expect(await tools.getSymfonyUri('latest', 'darwin')).toContain(
'releases/latest/download/symfony_darwin_amd64'
);
expect(await tools.getSymfonyUri('1.2.3', 'darwin')).toContain(
'releases/download/v1.2.3/symfony_darwin_amd64'
);
expect(await tools.getSymfonyUri('latest', 'win32')).toContain(
'releases/latest/download/symfony_windows_amd64'
);
expect(await tools.getSymfonyUri('1.2.3', 'win32')).toContain(
'releases/download/v1.2.3/symfony_windows_amd64'
);
expect(await tools.getSymfonyUri('1.2.3', 'fedora')).toContain(
'Platform fedora is not supported'
);
});
it('checking getCleanedToolsList', async () => {
const tools_list: string[] = await tools.getCleanedToolsList(
'tool, composer:1.2.3, robmorgan/phinx, hirak/prestissimo, narrowspark/automatic-composer-prefetcher'
@ -301,7 +325,7 @@ describe('Tools tests', () => {
it('checking addTools on linux', async () => {
const script: string = await tools.addTools(
'php-cs-fixer, phpstan, phpunit, pecl, phinx, phinx:1.2.3, phive, php-config, phpize',
'php-cs-fixer, phpstan, phpunit, pecl, phinx, phinx:1.2.3, phive, php-config, phpize, symfony',
'7.4',
'linux'
);
@ -320,6 +344,9 @@ describe('Tools tests', () => {
expect(script).toContain(
'add_tool https://phar.phpunit.de/phpunit.phar phpunit'
);
expect(script).toContain(
'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_linux_amd64 symfony'
);
expect(script).toContain('add_pecl');
expect(script).toContain('add_composer_tool phinx phinx robmorgan/');
expect(script).toContain('add_composer_tool phinx phinx:1.2.3 robmorgan/');
@ -329,7 +356,7 @@ describe('Tools tests', () => {
});
it('checking addTools on darwin', async () => {
const script: string = await tools.addTools(
'phpcs, phpcbf, phpcpd, phpmd, psalm, phinx, phive:1.2.3, composer-prefetcher:1.2.3, phpize, php-config',
'phpcs, phpcbf, phpcpd, phpmd, psalm, phinx, phive:1.2.3, composer-prefetcher:1.2.3, phpize, php-config, symfony, symfony:1.2.3',
'7.4',
'darwin'
);
@ -358,12 +385,18 @@ describe('Tools tests', () => {
expect(script).toContain(
'add_composer_tool composer-prefetcher composer-prefetcher:1.2.3 narrowspark/automatic-'
);
expect(script).toContain(
'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_darwin_amd64 symfony'
);
expect(script).toContain(
'add_tool https://github.com/symfony/cli/releases/download/v1.2.3/symfony_darwin_amd64 symfony'
);
expect(script).toContain('add_log "$tick" "phpize" "Added"');
expect(script).toContain('add_log "$tick" "php-config" "Added"');
});
it('checking addTools on windows', async () => {
const script: string = await tools.addTools(
'codeception, deployer, prestissimo, phpmd, phinx, phive:0.13.2, php-config, phpize, does_not_exit',
'codeception, deployer, prestissimo, phpmd, phinx, phive:0.13.2, php-config, phpize, symfony, does_not_exit',
'7.4',
'win32'
);
@ -383,6 +416,9 @@ describe('Tools tests', () => {
expect(script).toContain(
'Add-Tool https://github.com/phar-io/phive/releases/download/0.13.2/phive-0.13.2.phar phive'
);
expect(script).toContain(
'Add-Tool https://github.com/symfony/cli/releases/latest/download/symfony_windows_amd64.exe symfony'
);
expect(script).toContain('phpize is not a windows tool');
expect(script).toContain('php-config is not a windows tool');
expect(script).toContain('Tool does_not_exit is not supported');

35
dist/index.js vendored
View File

@ -1790,6 +1790,35 @@ function getDeployerUrl(version) {
});
}
exports.getDeployerUrl = getDeployerUrl;
/**
* Function to get the Deployer url
*
* @param version
* @param os_version
*/
function getSymfonyUri(version, os_version) {
return __awaiter(this, void 0, void 0, function* () {
let filename = '';
switch (os_version) {
case 'linux':
case 'darwin':
filename = 'symfony_' + os_version + '_amd64';
break;
case 'win32':
filename = 'symfony_windows_amd64.exe';
break;
default:
return yield utils.log('Platform ' + os_version + ' is not supported', os_version, 'error');
}
switch (version) {
case 'latest':
return 'releases/latest/download/' + filename;
default:
return 'releases/download/v' + version + '/' + filename;
}
});
}
exports.getSymfonyUri = getSymfonyUri;
/**
* Function to add/move composer in the tools list
*
@ -1964,6 +1993,12 @@ function addTools(tools_csv, php_version, os_version) {
case 'phpize':
script += yield addDevTools(tool, os_version);
break;
case 'symfony':
case 'symfony-cli':
uri = yield getSymfonyUri(version, os_version);
url = github + 'symfony/cli/' + uri;
script += yield addArchive('symfony', version, url, os_version);
break;
default:
script += yield utils.addLog('$cross', tool, 'Tool ' + tool + ' is not supported', os_version);
break;

View File

@ -79,7 +79,6 @@ Function Remove-Extension() {
}
}
# Function to setup a remote tool
Function Add-Tool() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
@ -93,14 +92,16 @@ Function Add-Tool() {
[string]
$tool
)
if($tool -eq "composer") {
if (Test-Path $php_dir\$tool) {
Remove-Item $php_dir\$tool
}
if ($tool -eq "composer") {
Install-Composer -Scope System -Path $php_dir -PhpPath $php_dir
composer -q global config process-timeout 0
Add-Log $tick $tool "Added"
} elseif ($tool -eq "symfony") {
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool.exe
Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $php_dir\$tool.exe" > $null 2>&1
} else {
if (Test-Path $php_dir\$tool) {
Remove-Item $php_dir\$tool
}
try {
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool
$bat_content = @()
@ -110,20 +111,18 @@ Function Add-Tool() {
$bat_content += "php %BIN_TARGET% %*"
Set-Content -Path $php_dir\$tool.bat -Value $bat_content
Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $php_dir\$tool.bat" > $null 2>&1
if (Test-Path $php_dir\$tool) {
Add-Log $tick $tool "Added"
} else {
Add-Log $cross $tool "Could not add $tool"
}
} catch {
Add-Log $cross $tool "Could not add $tool"
}
} catch { }
}
if($tool -eq "phive") {
Add-Extension curl >$null 2>&1
Add-Extension mbstring >$null 2>&1
Add-Extension xml >$null 2>&1
}
if (Test-Path $php_dir\$tool) {
Add-Log $tick $tool "Added"
} else {
Add-Log $cross $tool "Could not add $tool"
}
}
Function Add-Composer-Tool() {

View File

@ -243,6 +243,40 @@ export async function getDeployerUrl(version: string): Promise<string> {
}
}
/**
* Function to get the Deployer url
*
* @param version
* @param os_version
*/
export async function getSymfonyUri(
version: string,
os_version: string
): Promise<string> {
let filename = '';
switch (os_version) {
case 'linux':
case 'darwin':
filename = 'symfony_' + os_version + '_amd64';
break;
case 'win32':
filename = 'symfony_windows_amd64.exe';
break;
default:
return await utils.log(
'Platform ' + os_version + ' is not supported',
os_version,
'error'
);
}
switch (version) {
case 'latest':
return 'releases/latest/download/' + filename;
default:
return 'releases/download/v' + version + '/' + filename;
}
}
/**
* Function to add/move composer in the tools list
*
@ -440,6 +474,12 @@ export async function addTools(
case 'phpize':
script += await addDevTools(tool, os_version);
break;
case 'symfony':
case 'symfony-cli':
uri = await getSymfonyUri(version, os_version);
url = github + 'symfony/cli/' + uri;
script += await addArchive('symfony', version, url, os_version);
break;
default:
script += await utils.addLog(
'$cross',