File size: 1,890 Bytes
6a7089a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# Validate docs.json - check JSON syntax and verify all referenced files exist

set -e

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

DOCS_DIR="docs"
DOCS_JSON="$DOCS_DIR/index.json"

# Check if docs.json exists
if [ ! -f "$DOCS_JSON" ]; then
    echo -e "${YELLOW}⚠️  $DOCS_JSON not found - skipping validation${NC}"
    exit 0
fi

# Validate JSON syntax
if command -v jq &> /dev/null; then
    if ! jq empty "$DOCS_JSON" 2>/dev/null; then
        echo -e "${RED}✗ Invalid JSON syntax in $DOCS_JSON${NC}"
        jq empty "$DOCS_JSON"  # Show error
        exit 1
    fi
elif command -v python3 &> /dev/null; then
    if ! python3 -m json.tool "$DOCS_JSON" > /dev/null 2>&1; then
        echo -e "${RED}✗ Invalid JSON syntax in $DOCS_JSON${NC}"
        python3 -m json.tool "$DOCS_JSON"  # Show error
        exit 1
    fi
else
    echo -e "${YELLOW}⚠️  jq or python3 not found - skipping JSON syntax check${NC}"
fi

# Extract all file paths from docs.json
# Looks for patterns like "path/to/file.md"
files=$(grep -oE '"[a-zA-Z0-9/_.-]+\.md"' "$DOCS_JSON" | tr -d '"' | sort -u)

if [ -z "$files" ]; then
    echo -e "${YELLOW}⚠️  No markdown files found in $DOCS_JSON${NC}"
    exit 0
fi

missing_files=()

# Check each file exists
for file in $files; do
    full_path="$DOCS_DIR/$file"

    if [ ! -f "$full_path" ]; then
        missing_files+=("$file")
    fi
done

# Report results
if [ ${#missing_files[@]} -eq 0 ]; then
    count=$(echo "$files" | wc -l)
    echo -e "${GREEN}✓ Documentation index valid${NC} ($count files)"
    exit 0
else
    echo -e "${RED}✗ Missing documentation files referenced in docs.json:${NC}"
    for file in "${missing_files[@]}"; do
        echo -e "${RED}  - $DOCS_DIR/$file${NC}"
    done
    echo ""
    echo -e "${YELLOW}Fix: Create missing files or update docs/docs.json${NC}"
    exit 1
fi