🗝
summary refs log tree commit diff
path: root/nginx/types.sh
diff options
context:
space:
mode:
Diffstat (limited to 'nginx/types.sh')
-rwxr-xr-xnginx/types.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/nginx/types.sh b/nginx/types.sh
new file mode 100755
index 0000000..b670fdb
--- /dev/null
+++ b/nginx/types.sh
@@ -0,0 +1,32 @@
+#!/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|^/// <reference .*$||' "$file" # filter out xml references
+        echo
+    } >> 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