Skip to content

Commit

Permalink
refactor: Build scripts for multiple schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Jul 16, 2024
1 parent f1d51c6 commit a858bfd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

branch="$(git rev-parse --abbrev-ref HEAD)"
if [ "$branch" != "main" ]; then
pnpm build-json-examples && pnpm build-schema:dev
pnpm build
fi

pnpm check && pnpm fix
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
"description": "Digital Planning Data schemas",
"main": "schema/schema.json",
"scripts": {
"build": "pnpm build-schema:dist && pnpm build-json-examples",
"build": "pnpm build-schema && pnpm build-json-examples",
"build-json-examples": "pnpm ts-node scripts/build-json-examples.ts",
"build-schema:dev": "pnpm ts-json-schema-generator --path 'types/**/*.ts' --out 'schemas/digitalPlanningApplication.json' --type DigitalPlanningApplication --id @next --no-top-ref",
"build-schema:dist": "pnpm ts-json-schema-generator --path 'types/**/*.ts' --out 'schemas/digitalPlanningApplication.json' --type DigitalPlanningApplication --id \"${VERSION:-@next}\" --no-top-ref",
"build-schema": "./scripts/build-schema.sh",
"lint": "gts lint",
"check": "tsc --noEmit",
"fix": "gts fix",
"test": "pnpm build-schema:dev && vitest",
"test": "pnpm build-schema && vitest",
"prepare": "husky install"
},
"keywords": [],
Expand Down
20 changes: 20 additions & 0 deletions scripts/build-schema.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

echo "Running build-schema script..."

# Use environment variable VERSION, defaulting to "@next" if not set
version="${VERSION:-@next}"

echo "Version set to $version"

dirs=("digitalPlanningApplication")
types=("DigitalPlanningApplication")

for i in "${!dirs[@]}"; do
dir=${dirs[$i]}
type=${types[$i]}

echo "Building schema for $type from directory /$dir"

pnpm ts-json-schema-generator --path "types/schemas/${dir}/*.ts" --out "schemas/${dir}.json" --type "$type" --id "$version" --no-top-ref
done

0 comments on commit a858bfd

Please sign in to comment.