Open History to see the last commit
1#!/bin/bash
2β
3# Script to check for missing API references and examples in docs/config.json
4# Colors for output
5RED='\033[0;31m'
6GREEN='\033[0;32m'
7YELLOW='\033[1;33m'
8NC='\033[0m' # No Color
9β
10echo -e "${GREEN}π Checking for missing API references and examples in config.json${NC}"
11echo "=================================================================="
12β
13# Function to extract hook names from TypeScript files
14extract_hooks_from_package() {
15 local package_path="$1"
16 local prefix="$2"
18 if [ ! -d "$package_path" ]; then
19 return
20 fi
22 # Find all TypeScript files that start with the prefix and extract hook names
23 find "$package_path" -name "${prefix}*.ts" -type f | while read -r file; do
24 basename "$file" .ts
25 done | sort
26}
27β
28# Function to extract examples from examples directory
29extract_examples_from_framework() {
30 local framework="$1"
31 local examples_path="examples/$framework"
33 if [ ! -d "$examples_path" ]; then
34 return
35 fi
37 # List all directories in examples/framework
38 find "$examples_path" -maxdepth 1 -type d | while read -r dir; do
39 if [ "$dir" != "$examples_path" ]; then
40 basename "$dir"
41 fi
42 done | sort
43}
44β
45# Function to extract API references from config.json
46extract_api_refs_from_config() {
47 local framework="$1"
48 local section="$2"
50 # Extract API references for a specific framework and section
51 jq -r "
52 .sections[] |
53 select(.label == \"$section\") |
54 .frameworks[]? |
55 select(.label == \"$framework\") |
56 .children[]? |
57 .label
58 " docs/config.json 2>/dev/null | sort
59}
60β
61# Function to extract examples from config.json
62extract_examples_from_config() {
63 local framework="$1"
64 local section="$2"
66 # Extract examples for a specific framework and section
67 jq -r "
68 .sections[] |
69 select(.label == \"$section\") |
70 .frameworks[]? |
71 select(.label == \"$framework\") |
72 .children[]? |
73 .label
74 " docs/config.json 2>/dev/null | sort
75}
76β
77# Function to find items in first list that are not in second list
78find_missing() {
79 local actual_file="$1"
80 local expected_file="$2"
82 # Use comm to find items in actual that are not in expected
83 comm -23 <(sort "$actual_file") <(sort "$expected_file") 2>/dev/null
84}
85β
86# Function to check framework
87check_framework() {
88 local framework="$1"
89 local hook_prefix="$2"
91 echo -e "\n${YELLOW}π Checking $framework framework${NC}"
92 echo "----------------------------------------"
94 # Get actual hooks from packages
95 local package_path="packages/$framework-ai/src"
97 # Create temporary files
98 local temp_dir=$(mktemp -d)
99 local actual_hooks_file="$temp_dir/actual_hooks"
100 local actual_examples_file="$temp_dir/actual_examples"
101 local config_apis_file="$temp_dir/config_apis"
102 local config_examples_file="$temp_dir/config_examples"
104 # Collect all hooks
105 {
106 extract_hooks_from_package "$package_path" "$hook_prefix"
107 } | sort -u > "$actual_hooks_file"
109 # Get actual examples
110 extract_examples_from_framework "$framework" > "$actual_examples_file"
112 # Check API references for each major section
113 local api_sections=(
114 "Debouncer API Reference"
115 "Throttler API Reference"
116 "Rate Limiter API Reference"
117 "Queue API Reference"
118 "Batcher API Reference"
119 )
121 {
122 for section in "${api_sections[@]}"; do
123 extract_api_refs_from_config "$framework" "$section"
124 done
125 } | sort -u > "$config_apis_file"
127 # Check examples for each major section
128 local example_sections=(
129 "Debouncer Examples"
130 "Throttler Examples"
131 "Rate Limiter Examples"
132 "Queue Examples"
133 "Batcher Examples"
134 )
136 {
137 for section in "${example_sections[@]}"; do
138 extract_examples_from_config "$framework" "$section"
139 done
140 } | sort -u > "$config_examples_file"
142 # Count items
143 local actual_hooks_count=$(wc -l < "$actual_hooks_file")
144 local config_apis_count=$(wc -l < "$config_apis_file")
145 local actual_examples_count=$(wc -l < "$actual_examples_file")
146 local config_examples_count=$(wc -l < "$config_examples_file")
148 echo "π Found $actual_hooks_count hooks, $config_apis_count API refs in config"
149 echo "π Found $actual_examples_count examples, $config_examples_count example refs in config"
151 # Find missing API references
152 local missing_apis_file="$temp_dir/missing_apis"
153 find_missing "$actual_hooks_file" "$config_apis_file" > "$missing_apis_file"
155 # Find missing examples
156 local missing_examples_file="$temp_dir/missing_examples"
157 find_missing "$actual_examples_file" "$config_examples_file" > "$missing_examples_file"
159 # Report results
160 if [ -s "$missing_apis_file" ]; then
161 echo -e "\n${RED}β Missing API References:${NC}"
162 cat "$missing_apis_file"
163 else
164 echo -e "\n${GREEN}β
All API references are documented${NC}"
165 fi
167 if [ -s "$missing_examples_file" ]; then
168 echo -e "\n${RED}β Missing Examples:${NC}"
169 cat "$missing_examples_file"
170 else
171 echo -e "\n${GREEN}β
All examples are documented${NC}"
172 fi
174 # Report extra items in config (might be outdated)
175 local extra_apis_file="$temp_dir/extra_apis"
176 find_missing "$config_apis_file" "$actual_hooks_file" > "$extra_apis_file"
178 local extra_examples_file="$temp_dir/extra_examples"
179 find_missing "$config_examples_file" "$actual_examples_file" > "$extra_examples_file"
181 if [ -s "$extra_apis_file" ]; then
182 echo -e "\n${YELLOW}β οΈ Extra API References in config (may be outdated):${NC}"
183 cat "$extra_apis_file"
184 fi
186 if [ -s "$extra_examples_file" ]; then
187 echo -e "\n${YELLOW}β οΈ Extra Examples in config (may be outdated):${NC}"
188 cat "$extra_examples_file"
189 fi
191 # Cleanup
192 rm -rf "$temp_dir"
193}
194β
195# Check if jq is available
196if ! command -v jq &> /dev/null; then
197 echo -e "${RED}β jq is required but not installed. Please install jq to run this script.${NC}"
198 exit 1
199fi
200β
201# Check if config.json exists
202if [ ! -f "docs/config.json" ]; then
203 echo -e "${RED}β docs/config.json not found. Please run this script from the project root.${NC}"
204 exit 1
205fi
206β
207# Check React framework
208check_framework "react" "use"
209β
210# Check Solid framework
211check_framework "solid" "create"
212β
213echo -e "\n${GREEN}π Documentation check complete!${NC}"