chore(submodules): record the-order + smom artifact hygiene; add surgical clean helper
- Bump the-order to drop tracked tsc output under packages/*/src (dist is canonical). - Bump smom-dbis-138 to gitignore/untrack Foundry artifacts/. - submodules-clean: print dirty count and names first. - scripts/maintenance/surgical-clean-submodule-artifacts.sh for repeat idempotent cleanup. Made-with: Cursor
This commit is contained in:
85
scripts/maintenance/surgical-clean-submodule-artifacts.sh
Executable file
85
scripts/maintenance/surgical-clean-submodule-artifacts.sh
Executable file
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env bash
|
||||
# Surgical cleanup: remove *generated* files wrongly tracked in known submodules.
|
||||
# Does not discard intentional source edits (.ts, .go, .md WIP stays dirty until you commit/stash).
|
||||
#
|
||||
# Applies:
|
||||
# the-order — gitignore + untrack tsc emit under packages/*/src (outDir is dist/)
|
||||
# smom-dbis-138 — gitignore + untrack Foundry artifacts/
|
||||
#
|
||||
# Idempotent: safe to re-run after commits already landed (no-op if nothing tracked).
|
||||
#
|
||||
# Usage:
|
||||
# bash scripts/maintenance/surgical-clean-submodule-artifacts.sh [--dry-run]
|
||||
#
|
||||
# After this script, commit *inside* each submodule, then update the parent pointer:
|
||||
# cd the-order && git add .gitignore && git status && git commit -m "chore: …"
|
||||
# cd ../smom-dbis-138 && git commit -am "chore: …" # if only .gitignore+artifacts
|
||||
# cd .. && git add the-order smom-dbis-138 && git commit -m "chore(submodules): artifact hygiene"
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
DRY=false
|
||||
[[ "${1:-}" == "--dry-run" ]] && DRY=true
|
||||
|
||||
log() { echo "[surgical-clean] $*"; }
|
||||
|
||||
clean_the_order() {
|
||||
local sub="$ROOT/the-order"
|
||||
[[ -d "$sub/.git" ]] || return 0
|
||||
log "the-order: ensure .gitignore rules for packages/**/src emit"
|
||||
if $DRY; then
|
||||
grep -q 'packages/\*\*/src/\*\*' "$sub/.gitignore" 2>/dev/null && log " (gitignore already has package src emit rules)"
|
||||
return 0
|
||||
fi
|
||||
# Rules are committed in submodule; re-apply only if file missing patterns
|
||||
if ! grep -q 'packages/\*\*/src/\*\*/\*\.js$' "$sub/.gitignore" 2>/dev/null; then
|
||||
log " WARN: the-order/.gitignore missing expected emit rules — merge from main or run prior hygiene commit"
|
||||
fi
|
||||
local cnt
|
||||
cnt=$(git -C "$sub" ls-files 2>/dev/null | grep -E '^packages/[^/]+/src/.*\.(js|js\.map|d\.ts\.map)$' | grep -v 'base58-universal' | wc -l) || cnt=0
|
||||
cnt=$(echo "$cnt" | tr -d ' ')
|
||||
if [[ "${cnt:-0}" -eq 0 ]]; then
|
||||
cnt=$(git -C "$sub" ls-files 2>/dev/null | grep -E '^packages/[^/]+/src/.*\.d\.ts$' | grep -v 'base58-universal' | wc -l) || cnt=0
|
||||
cnt=$(echo "$cnt" | tr -d ' ')
|
||||
fi
|
||||
if [[ "${cnt:-0}" -eq 0 ]]; then
|
||||
log "the-order: no stray tracked emit under packages/*/src (OK)"
|
||||
return 0
|
||||
fi
|
||||
log "the-order: removing $cnt tracked emit file(s) from index"
|
||||
git -C "$sub" ls-files | grep -E '^packages/[^/]+/src/.*\.(js|js\.map|d\.ts\.map)$' | grep -v 'base58-universal' | xargs -r git -C "$sub" rm -f --cached
|
||||
git -C "$sub" ls-files | grep -E '^packages/[^/]+/src/.*\.d\.ts$' | grep -v 'packages/auth/src/types/base58-universal\.d\.ts$' | xargs -r git -C "$sub" rm -f --cached
|
||||
}
|
||||
|
||||
clean_smom() {
|
||||
local sub="$ROOT/smom-dbis-138"
|
||||
[[ -d "$sub/.git" ]] || return 0
|
||||
local n
|
||||
n=$(git -C "$sub" ls-files 2>/dev/null | grep -c '^artifacts/' || true)
|
||||
if [[ "${n:-0}" -eq 0 ]]; then
|
||||
log "smom-dbis-138: no tracked artifacts/ (OK)"
|
||||
return 0
|
||||
fi
|
||||
if $DRY; then
|
||||
log "smom-dbis-138: would git rm -r --cached artifacts/ ($n files)"
|
||||
return 0
|
||||
fi
|
||||
log "smom-dbis-138: git rm -r --cached artifacts/ ($n files)"
|
||||
git -C "$sub" rm -r -f --cached artifacts/ 2>/dev/null || true
|
||||
if [[ -d "$sub/artifacts" ]]; then
|
||||
rm -rf "$sub/artifacts"
|
||||
fi
|
||||
}
|
||||
|
||||
if ! grep -q '^artifacts/' "$ROOT/smom-dbis-138/.gitignore" 2>/dev/null; then
|
||||
log "WARN: smom-dbis-138/.gitignore should contain 'artifacts/' (add before next commit)"
|
||||
fi
|
||||
|
||||
clean_the_order
|
||||
clean_smom
|
||||
|
||||
log "Done. Run: bash scripts/verify/submodules-clean.sh"
|
||||
log "Other submodules with only source/config edits need manual commit or stash (not touched here)."
|
||||
Reference in New Issue
Block a user