# Check meta.title values across a set of story files for hierarchy hygiene:
# consistent "/"-separated Category/Subcategory/Name casing, and no title that
# looks like it was copy-pasted from a filesystem path (backslashes, drive
# letters, leading "./").
# Usage: check_hierarchy.sh <dir-or-glob-of-stories-files>
files=$(find "$TARGET" -name '*.stories.tsx' 2>/dev/null)
if [[ -z "$files" ]]; then
echo "⚠️ no *.stories.tsx files found under $TARGET"
title=$(grep -oE "title:[[:space:]]*['\"][^'\"]+['\"]" "$f" | head -1 | sed -E "s/title:[[:space:]]*.(.*).$/\1/")
if [[ -z "$title" ]]; then
echo "❌ $f: no meta.title found"
if [[ "$title" == *"\\"* || "$title" == ./* || "$title" =~ ^[A-Za-z]: ]]; then
echo "❌ $f: title '$title' looks like a filesystem path, not a hierarchy label"
elif [[ "$title" != */* ]]; then
echo "⚠️ $f: title '$title' has no Category/Name segment — confirm this is intentional (top-level only)"
echo "✅ $f: title '$title'"