diff --git a/scripts/clean_shit_up.ps1 b/scripts/clean_shit_up.ps1 index f5aa8ff..c27a559 100644 --- a/scripts/clean_shit_up.ps1 +++ b/scripts/clean_shit_up.ps1 @@ -13,8 +13,11 @@ $path_project = Join-Path $path_root 'Project' $path_content = Join-Path $path_project 'Content' # Function to remove Content directory from Git history -function Remove-ContentFromGitHistory { - param([string]$path_repo) +function Remove-ContentFromGitHistory +{ + param( + [string]$path_repo + ) # Git commands and flags $cgit_filter_branch = 'filter-branch' @@ -55,7 +58,8 @@ function Remove-ContentFromGitHistory { # Navigate to repository root Push-Location $path_repo - try { + try + { Write-Verbose "Current directory: $(Get-Location)" # Check if we're in a git repository @@ -75,26 +79,30 @@ function Remove-ContentFromGitHistory { Write-Verbose "Removing Content directory from Git history..." # Construct and execute filter-branch command - $filter_command = "git rm -r --cached --ignore-unmatch `"$path_content_relative`"" + $filter_command = "git rm -r --cached --ignore-unmatch `"$path_content_relative`"" $filter_branch_cmd = "git $cgit_filter_branch $fgit_force $fgit_index_filter '$filter_command' $fgit_prune_empty $fgit_tag_name_filter $fgit_filter_concat $fgit_filter_separate $fgit_all" Write-Verbose "Executing command: $filter_branch_cmd" + $output = Invoke-Expression $filter_branch_cmd 2>&1 $output | ForEach-Object { if ($_ -match "WARNING:") { Write-Warning $_ - } elseif ($_ -match "fatal:") { + } + elseif ($_ -match "fatal:") { throw $_ - } else { + } + else { Write-Verbose $_ } } Write-Verbose "Cleaning up refs..." - # Clean up refs using git directly $refs = & git show-ref --heads | ForEach-Object { $_.Split()[1] } - foreach ($ref in $refs) { + foreach ($ref in $refs) + { $originalRef = "$original_refs/$ref" - if (& git show-ref --verify --quiet $originalRef) { + if (& git show-ref --verify --quiet $originalRef) + { Write-Verbose "Deleting ref: $originalRef" & git update-ref -d $originalRef } @@ -102,7 +110,8 @@ function Remove-ContentFromGitHistory { # Remove any remaining refs/original directory $originalRefsPath = Join-Path $path_repo ".git\$original_refs" - if (Test-Path $originalRefsPath) { + if (Test-Path $originalRefsPath) + { Write-Verbose "Removing refs/original directory" Remove-Item -Recurse -Force $originalRefsPath } diff --git a/scripts/helpers/misc.ps1 b/scripts/helpers/misc.ps1 new file mode 100644 index 0000000..f3b0817 --- /dev/null +++ b/scripts/helpers/misc.ps1 @@ -0,0 +1,142 @@ +function clone-gitrepo { param( [string] $path, [string] $url ) + if (test-path $path) { + # git -C $path pull + } + else { + Write-Host "Cloning $url ..." + git clone $url $path + } +} +function Get-IniContent { param( [string] $path_file ) + $ini = @{} + $currentSection = $null + switch -regex -file $path_file + { + "^\[(.+)\]$" { + $currentSection = $matches[1].Trim() + $ini[ $currentSection ] = @{} + } + "^(.+?)\s*=\s*(.*)" { + $key, $value = $matches[1].Trim(), $matches[2].Trim() + if ($null -ne $currentSection) { + $ini[ $currentSection ][ $key ] = $value + } + } + } + return $ini +} + +function Invoke-WithColorCodedOutput { param( [scriptblock] $command ) + & $command 2>&1 | ForEach-Object { + # Write-Host "Type: $($_.GetType().FullName)" # Add this line for debugging + $color = 'White' # Default text color + switch ($_) { + { $_ -imatch "error" } { $color = 'Red'; break } + { $_ -imatch "warning" } { $color = 'Yellow'; break } + } + Write-Host "`t$_" -ForegroundColor $color + } +} + +function New-GodotProjectShortcut { + param ( + [Parameter(Mandatory=$true)] + [string]$shortcut_name, + + [Parameter(Mandatory=$true)] + [string]$godot_path, + + [Parameter(Mandatory=$true)] + [string]$project_path, + + [Parameter(Mandatory=$false)] + [string]$shortcut_folder = [Environment]::GetFolderPath("Desktop"), + + [Parameter(Mandatory=$false)] + [string]$icon_path + ) + + $WshShell = New-Object -ComObject WScript.Shell + + # Construct the full path for the shortcut + $path_shortcut = Join-Path $shortcut_folder "$shortcut_name.lnk" + + # Create the shortcut + $Shortcut = $WshShell.CreateShortcut($path_shortcut) + $Shortcut.TargetPath = $godot_path + $Shortcut.Arguments = "-e `"$ProjectPath`"" + $Shortcut.WorkingDirectory = Split-Path -Parent $project_path + $Shortcut.Description = "Open Godot project: $shortcut_name" + + # Set custom icon if provided, otherwise use the Godot executable's icon + if ($icon_path) { + $Shortcut.IconLocation = $icon_path + } + else { + $Shortcut.IconLocation = "$godot_path,0" + } + + $Shortcut.Save() + + Write-Host "Shortcut created successfully at $path_shortcut" +} + +function Update-GitRepo +{ + param( [string] $path, [string] $url, [string] $build_command ) + + if ( $build_command -eq $null ) { + write-host "Attempted to call Update-GitRepo without build_command specified" + return + } + + $repo_name = $url.Split('/')[-1].Replace('.git', '') + + $last_built_commit = join-path $path_build "last_built_commit_$repo_name.txt" + if ( -not(test-path -Path $path)) + { + write-host "Cloining repo from $url to $path" + git clone $url $path + + write-host "Building $url" + push-location $path + & "$build_command" + pop-location + + git -C $path rev-parse HEAD | out-file $last_built_commit + $script:binaries_dirty = $true + write-host + return + } + + git -C $path fetch + $latest_commit_hash = git -C $path rev-parse '@{u}' + $last_built_hash = if (Test-Path $last_built_commit) { Get-Content $last_built_commit } else { "" } + + if ( $latest_commit_hash -eq $last_built_hash ) { + write-host + return + } + + write-host "Build out of date for: $path, updating" + write-host 'Pulling...' + git -C $path pull + + write-host "Building $url" + push-location $path + & $build_command + pop-location + + $latest_commit_hash | out-file $last_built_commit + $script:binaries_dirty = $true + write-host +} + +function verify-path { param( $path ) + if (test-path $path) {return $true} + + new-item -ItemType Directory -Path $path + return $false +} + + diff --git a/scripts/setup_content.ps1 b/scripts/setup_content.ps1 index 0475e88..5958a00 100644 --- a/scripts/setup_content.ps1 +++ b/scripts/setup_content.ps1 @@ -1,4 +1,15 @@ clear-host +$misc = join-path $PSScriptRoot 'helpers/misc.ps1' +. $misc +# Path setup +$path_scripts = $PSScriptRoot +$path_helpers = Join-Path $path_scripts 'helpers' +$path_root = Split-Path -Parent -Path $path_scripts +$path_project = Join-Path $path_root 'Project' +$path_content = Join-Path $path_project 'Content' +$url_gasathon_content = 'https://git.cozyair.dev/ed/GASATHON_Content.git' + +clone-gitrepo $path_content $url_gasathon_content