#!/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/ # metamask-integration — root .gitignore dist/ + git rm --cached dist/ (tsc outDir) # miracles_in_motion — api/deploy-package tsc copy target: ignore + untrack *.js/*.map/*.d.ts (keep host.json, package.json) # # 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" [[ -e "$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/\*\*' "$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" [[ -e "$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 } clean_metamask_integration() { local sub="$ROOT/metamask-integration" [[ -e "$sub/.git" ]] || return 0 log "metamask-integration: ensure root .gitignore has dist/" if ! $DRY && [[ -f "$sub/.gitignore" ]] && ! grep -qE '^dist/?$' "$sub/.gitignore" 2>/dev/null; then log " WARN: add dist/ to metamask-integration/.gitignore (tsc outDir)" fi local n n=$(git -C "$sub" ls-files 2>/dev/null | grep -c '^dist/' || true) if [[ "${n:-0}" -eq 0 ]]; then log "metamask-integration: no tracked dist/ (OK)" return 0 fi if $DRY; then log "metamask-integration: would git rm -r --cached dist/ ($n files)" return 0 fi log "metamask-integration: git rm -r --cached dist/ ($n files)" git -C "$sub" rm -r -f --cached dist/ 2>/dev/null || true } clean_miracles_in_motion() { local sub="$ROOT/miracles_in_motion" [[ -e "$sub/.git" ]] || return 0 local files files=$(git -C "$sub" ls-files 2>/dev/null | grep '^api/deploy-package/' | grep -vE '(host\.json|package\.json)$' || true) if [[ -z "${files// }" ]]; then log "miracles_in_motion: no tracked deploy-package emit (OK)" return 0 fi n=$(echo "$files" | grep -c . || true) if $DRY; then log "miracles_in_motion: would git rm --cached deploy-package emit ($n files)" return 0 fi log "miracles_in_motion: git rm --cached deploy-package emit ($n files)" echo "$files" | xargs -r git -C "$sub" rm -f --cached } 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 clean_metamask_integration clean_miracles_in_motion 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)."