Skip to content

Check

FieldValue
TypeSkill Resource
Source~/.copilot/skills/frontend/scripts/check.sh
DescriptionNot specified

Source Content

#!/usr/bin/env bash
# check.sh — frontend skill's single dispatcher entrypoint.
#
# Inspects a target path, detects what kind of frontend surface is present,
# and runs the relevant checks from this skill's scripts/ directory. Missing
# tools degrade individual checks to a warning — this dispatcher itself
# never crashes because one sub-check's dependency is absent.
#
# Usage: check.sh <TARGET_PATH>
# TARGET_PATH defaults to "."
#
# Detection rules (each runs only if the matching files are present):
# *.stories.tsx -> check_csf3.sh, check_controls.sh, check_hierarchy.sh
# src/routes/** or *.routes.tsx -> check_routes.sh
# src/components/ui/** or patterns/** -> lint_ds_component.sh (per component file)
# packages/contracts/** or *Schema.ts -> check_schema_boundary.sh
# *.astro or astro.config.* -> check_astro.sh
# *.tsx / *.ts (general) -> check_frontend.sh
#
# Exit code: non-zero if any required sub-check fails.
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TARGET="${1:-.}"
if [[ ! -e "$TARGET" ]]; then
echo "check.sh: '$TARGET' does not exist" >&2
exit 2
fi
overall=0
ran_any=0
section() { printf '\n== %s ==\n' "$1"; }
run() {
# run <label> <cmd...> — tracks non-zero exit without stopping the dispatcher
local label="$1"; shift
echo "-> $label: $*"
if "$@"; then
:
else
echo " (non-zero exit from: $label)"
overall=1
fi
ran_any=1
}
# --- Storybook stories -------------------------------------------------------
mapfile -t stories < <(find "$TARGET" -type f -name "*.stories.tsx" 2>/dev/null)
if [[ "${#stories[@]}" -gt 0 ]]; then
section "Storybook (${#stories[@]} story file(s))"
for f in "${stories[@]}"; do
run "CSF3 shape ($f)" bash "$SCRIPT_DIR/check_csf3.sh" "$f"
run "hierarchy title ($f)" bash "$SCRIPT_DIR/check_hierarchy.sh" "$(dirname "$f")"
component="${f%.stories.tsx}.tsx"
if [[ -f "$component" ]]; then
run "controls/argTypes ($f)" bash "$SCRIPT_DIR/check_controls.sh" "$component" "$f"
fi
done
fi
# --- TanStack Router routes ---------------------------------------------------
if find "$TARGET" -type d -name "routes" 2>/dev/null | grep -q .; then
section "TanStack Router routes"
while IFS= read -r routes_dir; do
run "routes ($routes_dir)" bash "$SCRIPT_DIR/check_routes.sh" "$routes_dir"
done < <(find "$TARGET" -type d -name "routes" 2>/dev/null)
fi
# --- Design-system components -------------------------------------------------
mapfile -t ds_components < <(find "$TARGET" -type f \( -path "*/components/ui/*.tsx" -o -path "*/components/patterns/*.tsx" \) ! -name "*.stories.tsx" ! -name "*.test.tsx" 2>/dev/null)
if [[ "${#ds_components[@]}" -gt 0 ]]; then
section "Design-system components (${#ds_components[@]})"
for f in "${ds_components[@]}"; do
run "ds-component ($f)" bash "$SCRIPT_DIR/lint_ds_component.sh" "$f"
done
fi
# --- Zod schema boundaries ----------------------------------------------------
if find "$TARGET" -type d -path "*packages/contracts*" 2>/dev/null | grep -q . || find "$TARGET" -type f -iname "*schema*.ts" 2>/dev/null | grep -q .; then
section "Zod schema boundaries"
schema_dir="$TARGET"
if [[ -d "$TARGET/packages/contracts/src" ]]; then
schema_dir="$TARGET/packages/contracts/src"
fi
run "schema boundary ($schema_dir)" bash "$SCRIPT_DIR/check_schema_boundary.sh" "$schema_dir"
fi
# --- Astro -------------------------------------------------------------------
if find "$TARGET" -type f \( -name "*.astro" -o -name "astro.config.*" \) 2>/dev/null | grep -q .; then
section "Astro"
run "astro check" bash "$SCRIPT_DIR/check_astro.sh" "$TARGET"
fi
# --- General frontend (TS/TSX lint + typecheck) -------------------------------
if find "$TARGET" -type f \( -name "*.tsx" -o -name "*.ts" \) ! -name "*.stories.tsx" ! -name "*.test.ts" ! -name "*.test.tsx" 2>/dev/null | grep -q .; then
section "General frontend (oxlint/eslint + tsc)"
run "frontend lint + typecheck" bash "$SCRIPT_DIR/check_frontend.sh" "$TARGET"
fi
if [[ "$ran_any" -eq 0 ]]; then
echo "check.sh: no recognizable frontend surface found under '$TARGET' (no .stories.tsx, routes/, .astro, or .ts/.tsx files)"
fi
exit "$overall"
</content>