Last active
March 14, 2024 02:36
-
-
Save terremoth/a494dfdb8a29fba8749ffa086608776b to your computer and use it in GitHub Desktop.
Zeus Package Manager for Athena (PS2 - JS) first draft made in powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Write-Output "Zeus Package Manager for AthenaEnv PS2 libraries and Modules" | |
Write-Output "Made by github.com/terremoth" | |
$command = $args[0] | |
$library = $args[1] | |
$modulesDir = "athena_libs" | |
$libPath = "https://api.github.com/repos/terremoth/athenaenv-libs/contents/"+$library | |
$packageManagerFunction = "install", "update", "remove", "search" | |
$actualPath = $pwd | |
if ($packageManagerFunction -notcontains $command) { | |
Write-Output "Wrong command. Available: " $packageMangageFunction | |
Exit | |
} | |
# Will download everything from the URLs that came from JSON response which the object "type" prop is "dir" | |
function Get-DownloadFilesFromDirRecursive { | |
param ($url) | |
Write-Output $url | |
try { | |
$response = Invoke-WebRequest -Uri $url | |
} catch { | |
Write-Output $_.Exception | |
if ($_.Exception.Response.StatusCode -eq "404") { | |
Write-Host "Error: This Library or Module does not exist." -ForegroundColor red -BackgroundColor black | |
} else { | |
Write-Host "Error: The Request to get this Library or Module could not be processed. Check your internet connection" -ForegroundColor red -BackgroundColor black | |
} | |
Exit | |
} | |
$jsonObj = ConvertFrom-Json $([String]::new($Response.Content)) | |
#Write-Output $jsonObj | |
for ($i=0; $i -lt $jsonObj.Length; $i++) { | |
$realPathFile = $thisPath+"\"+$jsonObj[$i].path -replace "/", "\" | |
if ($jsonObj[$i].type -eq "dir") { | |
New-Item -ItemType Directory -Path $realPathFile > $null | |
#Write-Output $jsonObj[$i].url | |
Get-DownloadFilesFromDirRecursive $jsonObj[$i].url | |
} else { | |
#$realPathFile = $thisPath+"\"+$jsonObj[$i].path -replace "/", "\" | |
Write-Output "Vou baixar de :" $jsonObj[$i].download_url "e salvar em: "$(Join-Path $actualPath $jsonObj[$i].path) | |
Invoke-WebRequest -URI $jsonObj[$i].download_url -OutFile $jsonObj[$i].path | |
} | |
} | |
} | |
if ($command -eq "install" -or $command -eq "update") { | |
if (! (Test-Path -Path $modulesDir) ) { | |
New-Item -ItemType Directory -Path $modulesDir > $null | |
} | |
Get-DownloadFilesFromDirRecursive $libPath | |
} | |
$dirs = @( ) | |
$files = @( ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment