From cf5f7788fcd648aaf4c38527e7b1dfe69ff74bac Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 28 Dec 2025 23:46:07 -0600 Subject: [PATCH] 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. --- syncback.ps1 | 36 ++++++++++++++++++++++++++++++++++-- syncback.sh | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/syncback.ps1 b/syncback.ps1 index d5ea1b23..7275766c 100644 --- a/syncback.ps1 +++ b/syncback.ps1 @@ -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 . } diff --git a/syncback.sh b/syncback.sh index 50280af0..86ea6e1f 100644 --- a/syncback.sh +++ b/syncback.sh @@ -4,6 +4,17 @@ set -e ProjectRbxl="Project.rbxl" ProjectJsonFile="default.project.json" +# Check for clean flag and filter it out +DoClean=false +FilteredArgs="" +for Arg in "$@"; do + if [ "$Arg" = "clean" ]; then + DoClean=true + else + FilteredArgs="$FilteredArgs $Arg" + fi +done + # Load .env file (auto-export all variables) if [ -f ".env" ]; then set -a @@ -20,8 +31,28 @@ Url="https://assetdelivery.roblox.com/v1/asset/?id=$PlaceId" echo "Downloading $Url..." curl -fSL --compressed -o "$ProjectRbxl" -H "Cookie: .ROBLOSECURITY=${ROBLOSECURITY}" "$Url" -if [ $# -eq 0 ]; then +# Delete src/ completely and recreate directory structure if --clean specified +if [ "$DoClean" = true ]; then + echo "Cleaning src/ directory..." + rm -rf src + mkdir -p src/ReplicatedFirst + mkdir -p src/ReplicatedStorage + mkdir -p src/ServerScriptService + mkdir -p src/ServerStorage + mkdir -p src/StarterPlayer/StarterCharacterScripts + mkdir -p src/StarterPlayer/StarterPlayerScripts + mkdir -p src/Workspace +fi + +if [ -z "$FilteredArgs" ]; then rojo syncback --non-interactive --input "$ProjectRbxl" "$ProjectJsonFile" else - rojo syncback "$@" --input "$ProjectRbxl" "$ProjectJsonFile" + # shellcheck disable=SC2086 + rojo syncback --non-interactive $FilteredArgs --input "$ProjectRbxl" "$ProjectJsonFile" +fi + +# Stage all changes +if [ "$DoClean" = true ]; then + echo "Running git add..." + git add . fi