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 .
}

View file

@ -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