Skip to content

refactor(scripts): extract shared bash utilities to scripts/lib#88

Merged
PAMulligan merged 1 commit into
mainfrom
51-add-shared-bash-utility-library-to-reduce-script-duplication
May 22, 2026
Merged

refactor(scripts): extract shared bash utilities to scripts/lib#88
PAMulligan merged 1 commit into
mainfrom
51-add-shared-bash-utility-library-to-reduce-script-duplication

Conversation

@PAMulligan
Copy link
Copy Markdown
Collaborator

Closes #51.

Summary

  • Add scripts/lib/common.sh (banner/step output helpers, require_cmd, tracked tempfiles with auto EXIT trap, cross-platform now_ms, csv_contains, build_artifact_exists, common_config_get shell wrapper).
  • Add scripts/lib/colors.sh (ANSI constants honoring NO_COLOR + TTY detection).
  • Add scripts/lib/pipeline-config.js (ESM module + CLI for reading .claude/pipeline.config.json; mtime-cached, boolean/object-aware shell rendering, prints fallback on any error so set -e callers don't break).
  • Migrate 9 high-duplication scripts to source the libs (net -106 lines).

Migrated scripts

Script Wins
check-security.sh Removed 3 inline node -e config reads + manual TMPFILES cleanup
check-dead-code.sh Config helper + tracked tempfile
check-types.sh Banner helper + tracked tempfiles
check-dark-mode.sh 4 inline node -e config reads collapsed
check-responsive.sh Config helper + tracked tempfile
capture-baselines.sh 6 inline node -e config reads collapsed
regression-test.sh 11 inline node -e config reads collapsed
verify-all.sh Extracted csv_contains, now_ms, build_artifact_exists to lib
incremental-build.sh Moved inline ANSI color block to colors.sh

Scope notes

  • ANSI colors only appeared in one script (incremental-build.sh) — colors.sh exists for future adopters and now centralizes that one block.
  • 17 lower-duplication scripts were intentionally left alone for this PR.
  • Output strings were preserved exactly so existing script tests stay green.

Test plan

  • vitest run scripts/__tests__/verify-all.test.js — 13/13 pass
  • vitest run scripts/__tests__/check-security.test.js — 4/4 pass
  • vitest run scripts/__tests__/check-dead-code.test.js — 4/4 pass
  • vitest run scripts/__tests__/check-responsive.test.js — 3/3 pass
  • bash -n syntax check on every migrated script
  • Smoke-tested common_config_get, common_track_tmpfile, common_now_ms, common_csv_contains interactively
  • Full vitest run scripts/__tests__/ clean — one pre-existing knip 60s timeout flakes under concurrent disk load; passes in isolation

🤖 Generated with Claude Code

Consolidates duplicated patterns across shell scripts into three shared
libraries:

- scripts/lib/common.sh — banner/step/pass/fail/skip/warn output helpers,
  require_cmd/have_cmd, tracked tempfiles with auto EXIT trap, cross-platform
  now_ms, csv_contains, build_artifact_exists, project_root resolver, and a
  config_get wrapper that delegates to pipeline-config.js.
- scripts/lib/colors.sh — ANSI color constants honoring NO_COLOR and TTY
  detection.
- scripts/lib/pipeline-config.js — ESM module + CLI for reading
  .claude/pipeline.config.json (mtime-cached, boolean/object-aware
  shell rendering, prints fallback on any error so set -e callers stay safe).

Migrated 9 high-duplication scripts to source the libs:
check-security.sh (eliminated 3 inline node -e config reads + manual
TMPFILES cleanup), check-dead-code.sh, check-types.sh, check-dark-mode.sh,
check-responsive.sh, capture-baselines.sh, regression-test.sh,
verify-all.sh (extracted csv_contains/now_ms/build_artifact_exists), and
incremental-build.sh (moved ANSI color block to colors.sh).

Net -106 lines across the 9 migrated scripts. Output format preserved
exactly so existing script tests (verify-all, check-security, check-dead-code,
check-responsive) continue to pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@PAMulligan PAMulligan linked an issue May 22, 2026 that may be closed by this pull request
5 tasks
@PAMulligan PAMulligan merged commit 571a034 into main May 22, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add shared bash utility library to reduce script duplication

1 participant