This change speeds up the development workflow on the GUI when modifying the python api The GUI started from the devshell already hot reloads itself on any change of the typescript codebase. But python api changes were not caught bu the hot reload and required a reload of the devshell which is slow. This change implements a custom vite plugin to also listen to changes coming from the clan-cli python code and re-generate the python-ts api on any change.
21 lines
608 B
Bash
Executable File
21 lines
608 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
script_dir=$(dirname "$(readlink -f "$0")")
|
|
|
|
clan_cli="$script_dir/../../clan-cli"
|
|
|
|
trap 'rm -rf "$tmpdir"' EXIT
|
|
tmpdir=$(mktemp -d)
|
|
|
|
set -x
|
|
python "$clan_cli/api.py" > "$tmpdir/API.json"
|
|
json2ts --input "$tmpdir/API.json" > "$tmpdir/API.ts"
|
|
|
|
# compare sha256 sums of old and new API.ts
|
|
old_api_hash=$(sha256sum "$script_dir/../app/api/API.ts" | cut -d ' ' -f 1)
|
|
new_api_hash=$(sha256sum "$tmpdir/API.ts" | cut -d ' ' -f 1)
|
|
if [ "$old_api_hash" != "$new_api_hash" ]; then
|
|
cp "$tmpdir/API.json" "$script_dir/../app/api/API.json"
|
|
cp "$tmpdir/API.ts" "$script_dir/../app/api/API.ts"
|
|
fi
|