52 lines
906 B
Bash
Executable File
52 lines
906 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
README="$1"
|
|
SCHEMA="$2"
|
|
|
|
if [[ ! -f "$README" || ! -f "$SCHEMA" ]]; then
|
|
echo "Usage: $0 README.md schema.json"
|
|
exit 1
|
|
fi
|
|
|
|
tmpfile=$(mktemp)
|
|
|
|
awk -v schema_file="$SCHEMA" '
|
|
BEGIN {
|
|
in_json_block = 0
|
|
in_schema_section = 0
|
|
}
|
|
|
|
/^##[[:space:]]+JSON[[:space:]]+Schema/ {
|
|
in_schema_section = 1
|
|
print
|
|
next
|
|
}
|
|
|
|
/^##[[:space:]]+/ && in_schema_section {
|
|
# Another section starts, end the schema section
|
|
in_schema_section = 0
|
|
}
|
|
|
|
in_schema_section && /^```json/ {
|
|
print "```json"
|
|
while ((getline line < schema_file) > 0) print line
|
|
close(schema_file)
|
|
in_json_block = 1
|
|
next
|
|
}
|
|
|
|
in_json_block && /^```$/ {
|
|
print "```"
|
|
in_json_block = 0
|
|
next
|
|
}
|
|
|
|
!(in_schema_section && in_json_block) {
|
|
print
|
|
}
|
|
' "$README" > "$tmpfile"
|
|
|
|
mv "$tmpfile" "$README"
|
|
echo "✅ Updated JSON schema block in $README"
|