|
| 1 | +#!/bin/bash |
| 2 | +# Compare SDK types generated from Hono vs HttpApi specs. |
| 3 | +# Sorts types alphabetically so only meaningful body differences show. |
| 4 | +# |
| 5 | +# Usage: ./scripts/diff-sdk-types.sh # full diff |
| 6 | +# ./scripts/diff-sdk-types.sh --stat # summary only |
| 7 | +set -euo pipefail |
| 8 | + |
| 9 | +DIR="$(cd "$(dirname "$0")/.." && pwd)" |
| 10 | +SDK="$(cd "$DIR/../sdk/js" && pwd)" |
| 11 | + |
| 12 | +normalize() { |
| 13 | + python3 -c " |
| 14 | +import re, sys |
| 15 | +content = open(sys.argv[1]).read() |
| 16 | +blocks = re.split(r'(?=^export (?:type|function|const) )', content, flags=re.MULTILINE) |
| 17 | +header, body = blocks[0], blocks[1:] |
| 18 | +body.sort(key=lambda b: m.group(1) if (m := re.match(r'export \w+ (\w+)', b)) else '') |
| 19 | +sys.stdout.write(header + ''.join(body)) |
| 20 | +" "$1" |
| 21 | +} |
| 22 | + |
| 23 | +echo "Generating Hono SDK..." >&2 |
| 24 | +(cd "$SDK" && bun run script/build.ts >/dev/null 2>&1) |
| 25 | +normalize "$SDK/src/v2/gen/types.gen.ts" > /tmp/sdk-types-hono.ts |
| 26 | +git -C "$SDK" checkout -- src/ 2>/dev/null |
| 27 | + |
| 28 | +echo "Generating HttpApi SDK..." >&2 |
| 29 | +(cd "$SDK" && OPENCODE_SDK_OPENAPI=httpapi bun run script/build.ts >/dev/null 2>&1) |
| 30 | +normalize "$SDK/src/v2/gen/types.gen.ts" > /tmp/sdk-types-httpapi.ts |
| 31 | +git -C "$SDK" checkout -- src/ 2>/dev/null |
| 32 | + |
| 33 | +echo "" >&2 |
| 34 | +if [[ "${1:-}" == "--stat" ]]; then |
| 35 | + diff_output=$(diff /tmp/sdk-types-hono.ts /tmp/sdk-types-httpapi.ts || true) |
| 36 | + honly=$(printf "%s\n" "$diff_output" | grep -c '^< export type' || true) |
| 37 | + aonly=$(printf "%s\n" "$diff_output" | grep -c '^> export type' || true) |
| 38 | + total=$(printf "%s\n" "$diff_output" | wc -l | tr -d ' ') |
| 39 | + echo "Hono-only: $honly types HttpApi-only: $aonly types Diff lines: $total" |
| 40 | + echo "" |
| 41 | + if [[ $honly -gt 0 ]]; then |
| 42 | + echo "=== Hono-only types ===" |
| 43 | + printf "%s\n" "$diff_output" | grep '^< export type' | sed 's/< export type //' | sed 's/[ =].*//' | sed 's/^/ /' |
| 44 | + echo "" |
| 45 | + fi |
| 46 | + if [[ $aonly -gt 0 ]]; then |
| 47 | + echo "=== HttpApi-only types ===" |
| 48 | + printf "%s\n" "$diff_output" | grep '^> export type' | sed 's/> export type //' | sed 's/[ =].*//' | sed 's/^/ /' |
| 49 | + fi |
| 50 | +else |
| 51 | + diff /tmp/sdk-types-hono.ts /tmp/sdk-types-httpapi.ts || true |
| 52 | +fi |
0 commit comments