#!/usr/bin/env bash set -euo pipefail if [ -z "${GH_REPO_TOKEN:-}" ]; then echo "GH_REPO_TOKEN secret missing. Configure it in Hugging Face Space Settings -> Variables and secrets." >&2 exit 1 fi REPO_SLUG="${GH_REPO_SLUG:-shs3131/pulltime}" REPO_REF="${GH_REPO_REF:-main}" APP_SUBDIR="${GH_APP_SUBDIR:-server/storage-service}" APP_DIR="/runtime/app" mkdir -p /runtime rm -rf "$APP_DIR" git clone --depth 1 --branch "$REPO_REF" "https://x-access-token:${GH_REPO_TOKEN}@github.com/${REPO_SLUG}.git" "$APP_DIR" # Resolve app directory safely even if GH_APP_SUBDIR is misconfigured. APP_SUBDIR="${APP_SUBDIR#/}" RESOLVED_SUBDIR="" for candidate in "$APP_SUBDIR" "server/storage-service" "storage-service"; do if [ -f "$APP_DIR/$candidate/package.json" ]; then RESOLVED_SUBDIR="$candidate" break fi done if [ -z "$RESOLVED_SUBDIR" ]; then echo "package.json not found. Checked: $APP_SUBDIR, server/storage-service, storage-service" >&2 exit 1 fi cd "$APP_DIR/$RESOLVED_SUBDIR" echo "Using app subdir: $RESOLVED_SUBDIR" if [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ]; then npm ci --omit=dev else echo "Lockfile not found, falling back to npm install --omit=dev" npm install --omit=dev fi exec npm start