bun-mariadb/publish.sh
2026-07-14 09:13:07 +01:00

53 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
cd "$(dirname "$0")"
if [ -z "${1:-}" ]; then
msg="Updates"
else
msg="$1"
fi
# Always use the project's TypeScript (global `tsc` may not emit)
export PATH="$(pwd)/node_modules/.bin:$PATH"
if [ ! -x "./node_modules/.bin/tsc" ]; then
echo "Installing dependencies..."
bun install
fi
echo "Typechecking..."
tsc -p tsconfig.json --noEmit
echo "Compiling..."
# Clear emit output AND incremental cache. Otherwise a prior --noEmit run leaves
# tsbuildinfo "up to date" and tsc emits nothing after `rm -rf dist`.
rm -rf dist tsconfig.tsbuildinfo
tsc -p tsconfig.json
if [ ! -f dist/commands/index.js ]; then
echo "ERROR: compile failed — dist/commands/index.js was not produced"
exit 1
fi
# Ensure CLI shebang survived compile
if ! head -1 dist/commands/index.js | grep -q '^#!/usr/bin/env bun'; then
echo "Restoring bun shebang on dist/commands/index.js"
printf '%s\n' '#!/usr/bin/env bun' | cat - dist/commands/index.js > dist/commands/index.js.tmp
mv dist/commands/index.js.tmp dist/commands/index.js
fi
chmod +x dist/commands/index.js
echo "Build OK: $(head -1 dist/commands/index.js)"
echo "Publishing package..."
git add -A
git commit -m "$msg" || true
git push || true
bun publish
echo "Done."