veza/apps/web/scripts/storybook-coverage.sh
2026-02-03 09:56:11 +01:00

98 lines
2.6 KiB
Bash
Executable file

#!/bin/bash
# Storybook Coverage Analysis Script
# Compares tsx components to stories and generates a coverage report
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WEB_DIR="$(dirname "$SCRIPT_DIR")"
SRC_DIR="$WEB_DIR/src"
echo "📊 Storybook Coverage Analysis"
echo "=============================="
echo ""
# Count all component files (excluding tests and stories)
COMPONENT_COUNT=$(find "$SRC_DIR" -name "*.tsx" \
! -name "*.stories.tsx" \
! -name "*.test.tsx" \
! -path "*/__tests__/*" \
! -path "*/test-utils/*" \
! -name "main.tsx" \
! -name "index.tsx" \
! -name "routes.tsx" \
! -name "App.tsx" \
| wc -l | tr -d ' ')
# Count story files
STORY_COUNT=$(find "$SRC_DIR" -name "*.stories.tsx" | wc -l | tr -d ' ')
# Calculate coverage percentage
if [ "$COMPONENT_COUNT" -gt 0 ]; then
COVERAGE=$((STORY_COUNT * 100 / COMPONENT_COUNT))
else
COVERAGE=0
fi
echo "📁 Total Components: $COMPONENT_COUNT"
echo "📖 Total Stories: $STORY_COUNT"
echo "📈 Coverage: ${COVERAGE}%"
echo ""
# Find components without stories
echo "🔍 Components WITHOUT stories:"
echo "------------------------------"
# Get list of component basenames
COMPONENTS=$(find "$SRC_DIR" -name "*.tsx" \
! -name "*.stories.tsx" \
! -name "*.test.tsx" \
! -path "*/__tests__/*" \
! -path "*/test-utils/*" \
! -name "main.tsx" \
! -name "index.tsx" \
! -name "routes.tsx" \
! -name "App.tsx" \
-exec basename {} .tsx \; | sort | uniq)
# Get list of story basenames
STORIES=$(find "$SRC_DIR" -name "*.stories.tsx" -exec basename {} .stories.tsx \; | sort | uniq)
# Find components without stories
MISSING=0
for component in $COMPONENTS; do
if ! echo "$STORIES" | grep -qx "$component"; then
# Check if it's likely a component (starts with uppercase)
if [[ "$component" =~ ^[A-Z] ]]; then
echo " - $component"
MISSING=$((MISSING + 1))
fi
fi
done
echo ""
echo "📉 Components missing stories: $MISSING"
echo ""
# Coverage by directory
echo "📂 Coverage by Directory:"
echo "-------------------------"
for dir in components features; do
if [ -d "$SRC_DIR/$dir" ]; then
DIR_COMPONENTS=$(find "$SRC_DIR/$dir" -name "*.tsx" \
! -name "*.stories.tsx" \
! -name "*.test.tsx" \
| wc -l | tr -d ' ')
DIR_STORIES=$(find "$SRC_DIR/$dir" -name "*.stories.tsx" | wc -l | tr -d ' ')
if [ "$DIR_COMPONENTS" -gt 0 ]; then
DIR_COVERAGE=$((DIR_STORIES * 100 / DIR_COMPONENTS))
else
DIR_COVERAGE=0
fi
printf " %-15s %3d/%3d (%d%%)\n" "$dir:" "$DIR_STORIES" "$DIR_COMPONENTS" "$DIR_COVERAGE"
fi
done
echo ""
echo "✅ Analysis complete!"