#!/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 <