openapi-generator/bin/ts-typecheck-all.sh
Joscha Feth dc3718cd5c
fix(typescript): typecheck generated samples + fixes (#19903)
* fix(typescript): typecheck generated samples + fixes

* wip(today's fortune): The sum of the Universe is zero.

* Update .github/workflows/samples-typescript-typecheck.yaml

* Update modules/openapi-generator/src/main/resources/typescript/tsconfig.mustache

* chore: regenerate samples
2024-10-18 09:57:43 +02:00

50 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
log() {
echo "$@" >&2
}
npm_install() {
# --ignore-scripts because we don't want to run any pre- or postinstall scripts
# --no-package-lock because we don't want to update or create the package-lock.json
# --no-fund because we don't want to check for funding
# --no-audit because we don't want to run an audit
# --suppress-warnings because we don't want to see any warnings whilst type checking
npm i \
--suppress-warnings \
--ignore-scripts \
--no-package-lock \
--no-fund \
--no-audit \
"$@"
}
main() {
local root_dir
root_dir=$(git rev-parse --show-toplevel)
local dir
for dir in $(git ls-files samples | grep 'tsconfig.json$' | xargs -n1 dirname | sort -u); do
if [[ ! -f "${root_dir}/${dir}/.openapi-generator-ignore" ]]; then
# This is not a generated sample; skip it
continue
fi
if [[ ! -f "${root_dir}/${dir}/package.json" ]]; then
# we can't really guarantee that all dependencies are there to do a typecheck...
continue
fi
log "${dir}"
pushd "${root_dir}/${dir}" > /dev/null
npm_install \
|| npm_install --force # --force because we have some incompatible peer-dependencies that can't be fixed
npm exec --package=typescript@5.6.3 --yes -- tsc --noEmit
log "${dir}"
log
popd > /dev/null
done
}
main "$@"