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)."
|
||||
@@ -2,6 +2,9 @@
|
||||
# Exit 0 if every submodule has a clean working tree (no modified/untracked files).
|
||||
# Use in CI or after merges: bash scripts/verify/submodules-clean.sh
|
||||
# Set SKIP_EXIT=1 to report dirty submodules without failing.
|
||||
#
|
||||
# Common fix (TypeScript monorepos): compiler output in packages/*/src/*.js — belongs in dist/;
|
||||
# see the-order/.gitignore pattern and SUBMODULE_HYGIENE.md.
|
||||
set -euo pipefail
|
||||
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
||||
cd "$ROOT"
|
||||
@@ -11,6 +14,7 @@ tmp="$(mktemp)"
|
||||
trap 'rm -f "$tmp"' EXIT
|
||||
|
||||
dirty=0
|
||||
dirty_names=()
|
||||
while IFS= read -r subpath; do
|
||||
[[ -z "$subpath" ]] && continue
|
||||
if ! git -C "$ROOT/$subpath" rev-parse --git-dir >/dev/null 2>&1; then
|
||||
@@ -19,12 +23,14 @@ while IFS= read -r subpath; do
|
||||
out="$(git -C "$ROOT/$subpath" status --porcelain 2>/dev/null || true)"
|
||||
if [[ -n "$out" ]]; then
|
||||
dirty=1
|
||||
dirty_names+=("$subpath")
|
||||
printf '%s\n' "=== $subpath ===" >>"$tmp"
|
||||
printf '%s\n' "$out" >>"$tmp"
|
||||
fi
|
||||
done < <(git config --file .gitmodules --get-regexp '^submodule\..*\.path$' | awk '{print $2}' | sort -u)
|
||||
|
||||
if (( dirty )); then
|
||||
echo "submodules-clean: ${#dirty_names[@]} dirty submodule(s): ${dirty_names[*]}" >&2
|
||||
echo "submodules-clean: dirty submodule working trees:" >&2
|
||||
cat "$tmp" >&2
|
||||
if [[ "$SKIP_EXIT" != "1" ]]; then
|
||||
|
||||
Reference in New Issue
Block a user