Files
windmill/cli/windmill-utils-internal/gen_wm_client.sh
centdix 398c0bb34e chore(cli): easier dev on cli (#6336)
* add ts extensions by default

* remove script

* add script to remove ext

* simpler scripts

* add readme

* add revert mode

* nit

* fix

* fix typos

* typo
2025-08-07 15:55:14 +00:00

40 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Set script to exit on any error
set -e
script_dirpath="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
output_dirpath="${script_dirpath}/src/gen"
rm -rf "${output_dirpath}"
npx --yes @hey-api/openapi-ts@0.53.1 --input "${script_dirpath}/../../backend/windmill-api/openapi.yaml" --output "${output_dirpath}" --useOptions --client legacy/fetch --schemas false
cat <<EOF - "${output_dirpath}/core/OpenAPI.ts" > temp_file && mv temp_file "${output_dirpath}/core/OpenAPI.ts"
const getEnv = (key: string) => {
return process.env[key]
};
const baseUrl = getEnv("BASE_INTERNAL_URL") ?? getEnv("BASE_URL") ?? "http://localhost:8000";
const baseUrlApi = (baseUrl ?? '') + "/api";
EOF
echo "Applying sed transformations..."
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "Detected macOS - using GNU sed (gsed)"
if ! command -v gsed &> /dev/null; then
echo "Error: gsed not found"
echo "Run: brew install gnu-sed"
exit 1
fi
gsed -i 's/WITH_CREDENTIALS: false/WITH_CREDENTIALS: true/g' "${output_dirpath}/core/OpenAPI.ts"
gsed -i 's/TOKEN: undefined/TOKEN: getEnv("WM_TOKEN")/g' "${output_dirpath}/core/OpenAPI.ts"
gsed -i "s/BASE: '\\/api'/BASE: baseUrlApi/g" "${output_dirpath}/core/OpenAPI.ts"
else
echo "Detected Linux - using GNU sed"
sed -i 's/WITH_CREDENTIALS: false/WITH_CREDENTIALS: true/g' "${output_dirpath}/core/OpenAPI.ts"
sed -i 's/TOKEN: undefined/TOKEN: getEnv("WM_TOKEN")/g' "${output_dirpath}/core/OpenAPI.ts"
sed -i "s/BASE: '\\/api'/BASE: baseUrlApi/g" "${output_dirpath}/core/OpenAPI.ts"
fi
echo "✓ Client generation completed"