#!/bin/bash set -e # generates nginx.d.ts from the latest version of njs-types published on npm test -d nginx/types && rm -r nginx/types mkdir nginx/types test -f nginx/nginx.d.ts && rm nginx/nginx.d.ts doc=$(curl https://registry.npmjs.org/njs-types) ver=$(echo "$doc" | jq -r '."dist-tags".latest') echo "downloading $ver" url=$(echo "$doc" | jq -r .versions.'"'"$ver"'"'.dist.tarball) curl "$url" | tar xzC nginx/types --strip-components=1 echo concatenating for file in nginx/types/*.d.ts nginx/types/**/*.d.ts; do name="${file#nginx/types/}" [ "$name" = "index.d.ts" ] && continue # index.d.ts is just references. lame! { echo -e "// $name\n" sed 's|^/// > nginx/nginx.d.ts done rm -r nginx/types if command -v prettier >/dev/null; then echo formatting prettier --write nginx/nginx.d.ts fi