Skip to content

Commit

Permalink
rework gen.sh so it can be run from anywhere, take gen script out of …
Browse files Browse the repository at this point in the history
…openapi-gen
  • Loading branch information
david-crespo committed May 1, 2024
1 parent aafdfda commit 573f19e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
4 changes: 1 addition & 3 deletions packages/openapi-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
"node": ">=18"
},
"scripts": {
"gen": "./tools/gen.sh $(cat ./OMICRON_VERSION) ./packages/api",
"lint": "eslint .",
"postgen": "prettier --parser typescript --write ./packages/api",
"pretest": "npm run gen",
"pretest": "../../tools/gen.sh",
"test": "vitest",
"test:ui": "vitest --ui",
"tsc": "tsc"
Expand Down
19 changes: 5 additions & 14 deletions tools/gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,15 @@
set -o errexit
set -o pipefail

HELP="$(
cat <<EOF
usage: ./gen.sh [spec-file] [out-file]
EOF
)"

if [[ $# != 2 ]]; then
echo "$HELP"
exit 2
fi

OMICRON_SHA="$1"
DEST_DIR="$2"
ROOT_DIR="$(dirname "$0")/.."
OMICRON_SHA=$(cat "$ROOT_DIR/OMICRON_VERSION")
DEST_DIR="$ROOT_DIR/packages/api"

SPEC_URL="https://raw.githubusercontent.com/oxidecomputer/omicron/$OMICRON_SHA/openapi/nexus.json"
SPEC_FILE="./spec.json"

# TODO: we could get rid of this DL if a test didn't rely on it
curl --fail "$SPEC_URL" -o $SPEC_FILE

tsx packages/openapi-gen/index.ts $SPEC_FILE $DEST_DIR
npx tsx "$ROOT_DIR/packages/openapi-gen/index.ts" $SPEC_FILE $DEST_DIR
npx prettier --write --log-level error "$DEST_DIR"

0 comments on commit 573f19e

Please sign in to comment.