J94's picture
Initial Space upload
3436bdd verified
#!/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"