1#!/usr/bin/env bash
 2
 3set -euo pipefail
 4
 5cd "$(dirname "$0")/.." || exit 1
 6cd crates/languages/src/json/schemas
 7files=(
 8    "tsconfig.json"
 9    "package.json"
10)
11for file in "${files[@]}"; do
12    curl -sL -o "$file" "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/$file"
13done
14
15HASH="$(curl -s 'https://api.github.com/repos/SchemaStore/schemastore/commits/HEAD' | jq -r '.sha')"
16SHORT_HASH="${HASH:0:7}"
17DATE="$(curl -s 'https://api.github.com/repos/SchemaStore/schemastore/commits/HEAD' |jq -r .commit.author.date | cut -c1-10)"
18echo
19echo "Updated JSON schemas to [SchemaStore/schemastore@$SHORT_HASH](https://github.com/SchemaStore/schemastore/tree/$HASH) ($DATE)"
20echo
21for file in "${files[@]}"; do
22    echo "- [$file](https://github.com/SchemaStore/schemastore/commits/master/src/schemas/json/$file)" \
23        "@ [$SHORT_HASH](https://raw.githubusercontent.com/SchemaStore/schemastore/$HASH/src/schemas/json/$file)"
24done
25echo