Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .goborc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"useTabs": false,
"tabSize": 4,
"verticalStructs": true,
"verticalArrays": true,
"multilineTernary": false,
"blankLineAfterBlocks": false,
"flatExpressions": false,
"explicitUndefined": false,
"multilineArguments": 0
}
17 changes: 0 additions & 17 deletions run_gobo.bat

This file was deleted.

171 changes: 106 additions & 65 deletions run_gobo.ps1
Original file line number Diff line number Diff line change
@@ -1,93 +1,134 @@
# --- CONFIGURATION ---
$Repo = "EttyKitty/Gobo"
$FormatterName = "Gobo"
$Formatter = "gobo.exe"
$ZipFile = "gobo-windows.zip"
$Exclusions = "extensions|.git|.svn|prefabs"
$Extension = "*.gml"

Write-Host "--- Gobo: GML Formatter ---" -ForegroundColor Cyan
Write-Host ""

Write-Host "[INFO] This script will run $FormatterName on all $Extension files in the project" -ForegroundColor Cyan
Write-Host "[INFO] The following patterns will be excluded: $Exclusions" -ForegroundColor Cyan
Write-Host ""

pause
# Detect operating system and set platform-specific variables
if ($IsWindows) {
$Formatter = "gobo.exe"
$PlatformKeyword = "windows"
} elseif ($IsLinux) {
$Formatter = "gobo"
$PlatformKeyword = "linux"
} elseif ($IsMacOS) {
$Formatter = "gobo"
$PlatformKeyword = "mac"
} else {
Write-Error "Unsupported operating system."
exit 1
}

Write-Host ""
Clear-Host
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host " Gobo: GML Formatter " -ForegroundColor White
Write-Host "=========================================" -ForegroundColor Cyan

# --- AUTO-UPDATE ---
if (!(Test-Path $Formatter)) {
Write-Host "[INFO] $Formatter not found. Fetching latest release info..." -ForegroundColor Yellow
Write-Host ""
Write-Host "[INFO] Downloading latest release..." -ForegroundColor Yellow
$ApiUrl = "https://api.github.com/repos/$Repo/releases/latest"
$Assets = (Invoke-RestMethod -Uri $ApiUrl).assets

# Match asset based on platform keyword
$Asset = $Assets | Where-Object { $_.name -like "*$PlatformKeyword*" } | Select-Object -First 1

# Fallback for macOS if asset name uses "osx" instead of "mac"
if (!$Asset -and $IsMacOS) {
$Asset = $Assets | Where-Object { $_.name -like "*osx*" } | Select-Object -First 1
}

try {
$ApiUrl = "https://api.github.com/repos/$Repo/releases/latest"
$ReleaseInfo = Invoke-RestMethod -Uri $ApiUrl -ErrorAction Stop

$Asset = $ReleaseInfo.assets | Where-Object { $_.name -like "*windows*.zip" } | Select-Object -First 1

if ($null -eq $Asset) { throw "Could not find a Windows zip in the latest release." }

$DownloadUrl = $Asset.browser_download_url
Write-Host "[INFO] Found version $($ReleaseInfo.tag_name). Downloading..." -ForegroundColor Gray

Invoke-WebRequest -Uri $DownloadUrl -OutFile $ZipFile -ErrorAction Stop

Write-Host "[INFO] Extracting..." -ForegroundColor Gray
Expand-Archive -Path $ZipFile -DestinationPath "." -Force
Remove-Item $ZipFile

Write-Host "[SUCCESS] Installed $Formatter (Version: $($ReleaseInfo.tag_name))`n" -ForegroundColor Green
} catch {
Write-Host "`n[FATAL ERROR] Could not setup formatter!" -ForegroundColor Red
Write-Host "Reason: $($_.Exception.Message)" -ForegroundColor White
if (!$Asset) {
Write-Error "Could not find a valid release asset for this platform."
exit 1
}

$FileName = $Asset.name
Invoke-WebRequest -Uri $Asset.browser_download_url -OutFile $FileName

# Handle extraction based on file extension
if ($FileName -like "*.zip") {
Expand-Archive -Path $FileName -DestinationPath "." -Force
} elseif ($FileName -like "*.tar.gz" -or $FileName -like "*.tgz") {
tar -xzf $FileName
}

Remove-Item $FileName

# Set execution permissions on Linux and macOS
if (!$IsWindows) {
chmod +x "./$Formatter"
}

Write-Host "[SUCCESS] Formatter ready.`n" -ForegroundColor Green
}

# --- FILE GATHERING ---
Write-Host "[INFO] Gathering files..." -ForegroundColor Cyan
Write-Host ""
Write-Host "[INFO] This script will run $FormatterName on all $Extension files in the project" -ForegroundColor Cyan
Write-Host ""

$Files = Get-ChildItem -Recurse -Filter $Extension | Where-Object { $_.FullName -notmatch $Exclusions }
$Total = $Files.Count
$Count = 0
$Errors = 0
[void](Read-Host "Press Enter to continue")

if ($Total -eq 0) {
Write-Host "[WARN] No $Extension files found!" -ForegroundColor Yellow
pause; exit 0
}
Write-Host ""
Write-Host "[INFO] Formatting project..." -ForegroundColor Cyan

Write-Host "[INFO] Found $Total files" -ForegroundColor Cyan
$Stopwatch = [System.Diagnostics.Stopwatch]::StartNew()

# --- PROCESSING ---
Write-Host "[INFO] Formatting..." -ForegroundColor Cyan
# Run Gobo and capture ALL output (Stdout and Stderr) into an array of strings
$Output = & "./$Formatter" . 2>&1

$Stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
$Stopwatch.Stop()

foreach ($File in $Files) {
$Count++
$Host.UI.RawUI.WindowTitle = "$($File.Name) [$Count / $Total]"

# Run the formatter
& "./$Formatter" $File.FullName | Out-Null

if ($LASTEXITCODE -ne 0) {
Write-Host "[ERROR] Failed on $($File.FullName)" -ForegroundColor Red
# --- PARSE RESULTS ---
$Errors = 0
$Warnings = 0
$FilesProcessed = "Unknown"

foreach ($Line in $Output) {
if ($Line -match "\[Error\]") {
Write-Host $Line -ForegroundColor Red
$Errors++
}
elseif ($Line -match "\[Warn\]") {
Write-Host $Line -ForegroundColor Yellow
$Warnings++
}
else {
Write-Host $Line -ForegroundColor Gray
if ($Line -match "Formatted (\d+) files") {
$FilesProcessed = $Matches[1]
}
}
}

$Stopwatch.Stop()

# --- SUMMARY ---
# --- SUMMARY BLOCK ---
$Time = $Stopwatch.Elapsed.ToString("hh\:mm\:ss\.ff")
Write-Host ""
Write-Host "[INFO] Formatting Complete!" -ForegroundColor Green
Write-Host "[INFO] Total Processed: $Total" -ForegroundColor Cyan
Write-Host "[INFO] Time Elapsed: $Time" -ForegroundColor Cyan
Write-Host "[INFO] Errors: $Errors" -ForegroundColor $(if ($Errors -gt 0) { "Red" } else { "Cyan" })
Write-Host "-----------------------------------------" -ForegroundColor Cyan
Write-Host "[SUMMARY] Formatting Complete" -ForegroundColor Green
Write-Host "-----------------------------------------" -ForegroundColor Cyan
Write-Host "Files Processed: $FilesProcessed" -ForegroundColor White
Write-Host "Time Elapsed: $Time" -ForegroundColor White

if ($Errors -gt 0) {
Write-Host "Errors: $Errors" -ForegroundColor Red
} else {
Write-Host "Errors: 0" -ForegroundColor Green
}

if ($Warnings -gt 0) {
Write-Host "Warnings: $Warnings" -ForegroundColor Yellow
}

Write-Host "=========================================" -ForegroundColor Cyan
Write-Host ""

pause
if ($LASTEXITCODE -ne 0 -or $Errors -gt 0) {
Write-Host "[TERMINATED] Finished with errors." -ForegroundColor Red
[void](Read-Host "Press Enter to exit")
exit 1
} else {
Write-Host "[SUCCESS] Press Enter to close..." -ForegroundColor Green
[void](Read-Host "Press Enter to exit")
exit 0
}
Loading