Add clean flag functionality to syncback scripts for directory management. Implemented logic to delete and recreate the 'src/' directory structure when the 'clean' argument is provided, while filtering out the clean flag from other arguments passed to the syncback command.

This commit is contained in:
Joe 2025-12-28 23:46:07 -06:00
parent 978dd41047
commit cf5f7788fc
2 changed files with 67 additions and 4 deletions

View file

@ -3,6 +3,17 @@
$ProjectRbxl = "Project.rbxl"
$ProjectJsonFile = "default.project.json"
# Check for clean flag and filter it out
$DoClean = $false
$FilteredArgs = @()
foreach ($Arg in $args) {
if ($Arg -eq "clean") {
$DoClean = $true
} else {
$FilteredArgs += $Arg
}
}
# Load .env file
Get-Content ".env" | ForEach-Object {
if ($_ -match "^\s*([^#][^=]+)=(.*)$") {
@ -23,8 +34,29 @@ $Session.Cookies.Add($Cookie)
Write-Host "Downloading $Url..."
Invoke-WebRequest -Uri $Url -WebSession $Session -OutFile $ProjectRbxl
if ($args.Count -eq 0) {
# Delete src/ completely and recreate directory structure if --clean specified
if ($DoClean) {
Write-Host "Cleaning src/ directory..."
if (Test-Path "src") {
Remove-Item -Path "src" -Recurse -Force
}
New-Item -ItemType Directory -Path "src/ReplicatedFirst" -Force | Out-Null
New-Item -ItemType Directory -Path "src/ReplicatedStorage" -Force | Out-Null
New-Item -ItemType Directory -Path "src/ServerScriptService" -Force | Out-Null
New-Item -ItemType Directory -Path "src/ServerStorage" -Force | Out-Null
New-Item -ItemType Directory -Path "src/StarterPlayer/StarterCharacterScripts" -Force | Out-Null
New-Item -ItemType Directory -Path "src/StarterPlayer/StarterPlayerScripts" -Force | Out-Null
New-Item -ItemType Directory -Path "src/Workspace" -Force | Out-Null
}
if ($FilteredArgs.Count -eq 0) {
rojo syncback --non-interactive --input $ProjectRbxl $ProjectJsonFile
} else {
rojo syncback @args --input $ProjectRbxl $ProjectJsonFile
rojo syncback --non-interactive @FilteredArgs --input $ProjectRbxl $ProjectJsonFile
}
# Stage all changes
if ($DoClean) {
Write-Host "Running git add..."
git add .
}