Improve composer support

This commit is contained in:
Shivam Mathur 2020-05-13 21:13:58 +05:30
parent 533e0949a8
commit 4ce413f558
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
3 changed files with 20 additions and 11 deletions

View File

@ -107,7 +107,13 @@ add_tool() {
status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" -L "$url") status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" -L "$url")
if [ "$status_code" = "200" ]; then if [ "$status_code" = "200" ]; then
sudo chmod a+x "$tool_path" sudo chmod a+x "$tool_path"
if [ "$tool" = "phive" ]; then if [ "$tool" = "composer" ]; then
composer -q global config process-timeout 0
echo "::add-path::/Users/$USER/.composer/vendor/bin"
if [ -n "$COMPOSER_TOKEN" ]; then
composer -q global config github-oauth.github.com "$COMPOSER_TOKEN"
fi
elif [ "$tool" = "phive" ]; then
add_extension curl "sudo pecl install -f curl" extension >/dev/null 2>&1 add_extension curl "sudo pecl install -f curl" extension >/dev/null 2>&1
add_extension mbstring "sudo pecl install -f mbstring" extension >/dev/null 2>&1 add_extension mbstring "sudo pecl install -f mbstring" extension >/dev/null 2>&1
add_extension xml "sudo pecl install -f xml" extension >/dev/null 2>&1 add_extension xml "sudo pecl install -f xml" extension >/dev/null 2>&1
@ -129,7 +135,6 @@ add_composertool() {
prefix=$3 prefix=$3
( (
composer global require "$prefix$release" >/dev/null 2>&1 && composer global require "$prefix$release" >/dev/null 2>&1 &&
sudo ln -sf "$(composer -q global config home)"/vendor/bin/"$tool" /usr/local/bin/"$tool" &&
add_log "$tick" "$tool" "Added" add_log "$tick" "$tool" "Added"
) || add_log "$cross" "$tool" "Could not setup $tool" ) || add_log "$cross" "$tool" "Could not setup $tool"
} }

View File

@ -153,6 +153,10 @@ add_tool() {
sudo chmod a+x "$tool_path" sudo chmod a+x "$tool_path"
if [ "$tool" = "composer" ]; then if [ "$tool" = "composer" ]; then
composer -q global config process-timeout 0 composer -q global config process-timeout 0
echo "::add-path::/home/$USER/.composer/vendor/bin"
if [ -n "$COMPOSER_TOKEN" ]; then
composer -q global config github-oauth.github.com "$COMPOSER_TOKEN"
fi
elif [ "$tool" = "cs2pr" ]; then elif [ "$tool" = "cs2pr" ]; then
sudo sed -i 's/\r$//; s/exit(9)/exit(0)/' "$tool_path" sudo sed -i 's/\r$//; s/exit(9)/exit(0)/' "$tool_path"
elif [ "$tool" = "phive" ]; then elif [ "$tool" = "phive" ]; then
@ -173,7 +177,6 @@ add_composertool() {
prefix=$3 prefix=$3
( (
composer global require "$prefix$release" >/dev/null 2>&1 && composer global require "$prefix$release" >/dev/null 2>&1 &&
sudo ln -sf "$(composer -q global config home)"/vendor/bin/"$tool" /usr/local/bin/"$tool" &&
add_log "$tick" "$tool" "Added" add_log "$tick" "$tool" "Added"
) || add_log "$cross" "$tool" "Could not setup $tool" ) || add_log "$cross" "$tool" "Could not setup $tool"
} }

View File

@ -103,10 +103,7 @@ Function Add-Tool() {
if (Test-Path $php_dir\$tool) { if (Test-Path $php_dir\$tool) {
Remove-Item $php_dir\$tool Remove-Item $php_dir\$tool
} }
if ($tool -eq "composer") { if ($tool -eq "symfony") {
Install-Composer -Scope System -Path $php_dir -PhpPath $php_dir
composer -q global config process-timeout 0
} elseif ($tool -eq "symfony") {
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool.exe 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 Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $php_dir\$tool.exe" > $null 2>&1
} else { } else {
@ -125,10 +122,16 @@ Function Add-Tool() {
Add-Extension curl >$null 2>&1 Add-Extension curl >$null 2>&1
Add-Extension mbstring >$null 2>&1 Add-Extension mbstring >$null 2>&1
Add-Extension xml >$null 2>&1 Add-Extension xml >$null 2>&1
} } elseif($tool -eq "cs2pr") {
if($tool -eq "cs2pr") {
(Get-Content $php_dir/cs2pr).replace('exit(9)', 'exit(0)') | Set-Content $php_dir/cs2pr (Get-Content $php_dir/cs2pr).replace('exit(9)', 'exit(0)') | Set-Content $php_dir/cs2pr
} elseif($tool -eq "composer") {
composer -q global config process-timeout 0
Write-Output "::add-path::$env:APPDATA\Composer\vendor\bin"
if (Test-Path env:COMPOSER_TOKEN) {
composer -q global config github-oauth.github.com $env:COMPOSER_TOKEN
}
} }
if (((Get-ChildItem -Path $php_dir/* | Where-Object Name -Match "^$tool(.exe|.phar)*$").Count -gt 0)) { if (((Get-ChildItem -Path $php_dir/* | Where-Object Name -Match "^$tool(.exe|.phar)*$").Count -gt 0)) {
Add-Log $tick $tool "Added" Add-Log $tick $tool "Added"
} else { } else {
@ -156,8 +159,6 @@ Function Add-Composertool() {
) )
composer -q global require $prefix$release 2>&1 | out-null composer -q global require $prefix$release 2>&1 | out-null
if($?) { if($?) {
$composer_dir = composer -q global config home | ForEach-Object { $_ -replace "/", "\" }
Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $composer_dir\vendor\bin\$tool.bat"
Add-Log $tick $tool "Added" Add-Log $tick $tool "Added"
} else { } else {
Add-Log $cross $tool "Could not setup $tool" Add-Log $cross $tool "Could not setup $tool"