File size: 2,004 Bytes
3436bdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
set -euo pipefail

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
REGISTRY="$ROOT/configs/source_registry.json"
OUT_JSON="$ROOT/hotgraph/source_hotgraph.json"
OUT_MD="$ROOT/hotgraph/source_hotgraph.md"
TMP_SUMMARY="$(mktemp)"

trap 'rm -f "$TMP_SUMMARY"' EXIT

mkdir -p "$(dirname "$OUT_JSON")"

jq -c '.sources[]' "$REGISTRY" | while IFS= read -r source; do
  id="$(printf '%s' "$source" | jq -r '.id')"
  label="$(printf '%s' "$source" | jq -r '.label')"
  role="$(printf '%s' "$source" | jq -r '.role')"
  priority="$(printf '%s' "$source" | jq -r '.priority')"
  path="$(printf '%s' "$source" | jq -r '.path')"
  exists=false
  package_count=0

  if [ -d "$path" ]; then
    exists=true
    package_count="$(find "$path" -name Cargo.toml -not -path '*/target/*' | wc -l | tr -d ' ')"
  fi

  jq -n \
    --arg id "$id" \
    --arg label "$label" \
    --arg role "$role" \
    --arg priority "$priority" \
    --arg path "$path" \
    --argjson exists "$exists" \
    --argjson package_count "$package_count" \
    '{id:$id,label:$label,role:$role,priority:$priority,path:$path,exists:$exists,package_count:$package_count}' \
    >> "$TMP_SUMMARY"
done

jq -s \
  --arg generated_at "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
  --arg source_registry "$REGISTRY" \
  '{generated_at:$generated_at,source_registry:$source_registry,summary:.}' \
  "$TMP_SUMMARY" > "$OUT_JSON"

{
  echo "# Source Hotgraph"
  echo
  echo "Generated: \`$(jq -r '.generated_at' "$OUT_JSON")\`"
  echo
  echo "| Source | Role | Priority | Exists | Rust packages |"
  echo "| --- | --- | --- | --- | ---: |"
  jq -r '.summary[] | "| \(.label) | \(.role) | \(.priority) | \(.exists) | \(.package_count) |"' "$OUT_JSON"
  echo
  echo "## Read"
  echo
  echo "Clean product one-liner: this hotgraph is the reduced intake surface for deciding where new work should live."
  echo
  echo "Layman version: this is the index card box before the writing desk."
} > "$OUT_MD"

printf '%s\n' "$OUT_JSON"
printf '%s\n' "$OUT_MD"