61 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
set -e
# 📁 Directories
ROOT_DIR="$(dirname "$0")"
SOURCE_DIR="$ROOT_DIR/source"
BUILD_DIR="$ROOT_DIR/build"
cd "$ROOT_DIR"
# 🔐 Load .env
if [ -f .env ]; then
echo "📦 Loading .env..."
export $(grep -v '^#' .env | xargs)
else
echo "⚠️ .env file not found."
fi
# 🧹 Clean build dir
echo "🧹 Cleaning build dir..."
rm -rf "$BUILD_DIR"
mkdir -p "$BUILD_DIR"
# 📁 Copy full source (including src/, tsconfig.json, etc.)
echo "📁 Copying full source to build dir..."
cp -r "$SOURCE_DIR/"* "$BUILD_DIR/"
cp -r "$SOURCE_DIR/src" "$BUILD_DIR/" # ensure src/ structure preserved
# 🩹 Patch tsconfig.json inside build dir to make it build in-place
echo "🛠 Patching tsconfig.json..."
sed -i 's#"rootDir": "./src"#"rootDir": "./src"#' "$BUILD_DIR/tsconfig.json"
sed -i 's#"include": \["src"\]#"include": ["./src"]#' "$BUILD_DIR/tsconfig.json"
# 🔧 Build from inside build dir
cd "$BUILD_DIR"
echo "🧱 Running tsc..."
rm -rf dist
npx --yes tsc
# ✅ Confirm output exists
if [ ! -f dist/index.js ]; then
echo "❌ ERROR: Build failed. dist/index.js not found."
exit 1
fi
# ✍️ Write .npmrc for registry
cat > .npmrc <<EOF
registry=https://git.chipperfluff.at/api/packages/projects/npm/
//git.chipperfluff.at/api/packages/projects/npm/:_authToken=$NPM_TOKEN
always-auth=true
EOF
# 🚀 Publish
echo "🚀 Publishing to Gitea registry..."
npm publish
# 🧽 Cleanup
rm .npmrc
echo "✅ All done! Built and published from build dir."