/ scripts / check-doc-coverage.sh
check-doc-coverage.sh
 1  #!/usr/bin/env bash
 2  # check-doc-coverage.sh — Verify every adapter in clis/ has a doc page.
 3  #
 4  # Exit codes:
 5  #   0 — all adapters have docs
 6  #   1 — at least one adapter is missing documentation
 7  #
 8  # Usage:
 9  #   bash scripts/check-doc-coverage.sh          # report only
10  #   bash scripts/check-doc-coverage.sh --strict  # exit 1 on missing docs
11  
12  set -euo pipefail
13  
14  STRICT=false
15  if [[ "${1:-}" == "--strict" ]]; then
16    STRICT=true
17  fi
18  
19  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
20  ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
21  
22  SRC_DIR="$ROOT_DIR/clis"
23  DOCS_DIR="$ROOT_DIR/docs/adapters"
24  
25  missing=()
26  covered=0
27  total=0
28  
29  for adapter_dir in "$SRC_DIR"/*/; do
30    adapter_name="$(basename "$adapter_dir")"
31    # Skip internal directories (e.g., _shared)
32    [[ "$adapter_name" == _* ]] && continue
33    # Skip directories that only contain utility files (prefixed with _)
34    has_commands=false
35    for f in "$adapter_dir"*; do
36      fname="$(basename "$f")"
37      [[ "$fname" == _* ]] && continue
38      [[ "$fname" == *.test.* ]] && continue
39      has_commands=true
40      break
41    done
42    [[ "$has_commands" == false ]] && continue
43    total=$((total + 1))
44  
45    # Check if doc exists in browser/ or desktop/ subdirectories
46    if [[ -f "$DOCS_DIR/browser/$adapter_name.md" ]] || \
47       [[ -f "$DOCS_DIR/desktop/$adapter_name.md" ]]; then
48      covered=$((covered + 1))
49    else
50      # Handle directory name mismatches (e.g., discord-app -> discord)
51      alt_name="${adapter_name%-app}"
52      if [[ "$alt_name" != "$adapter_name" ]] && \
53         { [[ -f "$DOCS_DIR/browser/$alt_name.md" ]] || \
54           [[ -f "$DOCS_DIR/desktop/$alt_name.md" ]]; }; then
55        covered=$((covered + 1))
56      else
57        missing+=("$adapter_name")
58      fi
59    fi
60  done
61  
62  echo "📊 Doc Coverage: $covered/$total adapters documented"
63  echo ""
64  
65  if [[ ${#missing[@]} -gt 0 ]]; then
66    echo "⚠️  Missing docs for ${#missing[@]} adapter(s):"
67    for name in "${missing[@]}"; do
68      echo "   - $name  →  create docs/adapters/browser/$name.md or docs/adapters/desktop/$name.md"
69    done
70    echo ""
71    if $STRICT; then
72      echo "❌ Doc check failed (--strict mode)."
73      exit 1
74    else
75      echo "💡 Run with --strict to fail CI on missing docs."
76      exit 0
77    fi
78  else
79    echo "✅ All adapters have documentation."
80    exit 0
81  fi