aboutsummaryrefslogtreecommitdiff
path: root/web/launch.sh
blob: 8b2fd92157fcb6f6ad114bedf312df1dd94d03c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash

# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
YELLOW='\033[0;33m'

echo -e "${BLUE}Starting TyperPunk Web...${NC}"

# Resolve directories
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="${SCRIPT_DIR}/.."

# Ensure wasm-pack is available (auto-install if possible)
if ! command -v wasm-pack &> /dev/null; then
  echo -e "${YELLOW}wasm-pack not found. Attempting to install via cargo...${NC}"
  if command -v cargo &> /dev/null; then
    cargo install wasm-pack || {
      echo -e "${RED}Failed to install wasm-pack automatically. Please install manually: cargo install wasm-pack${NC}"
      exit 1
    }
  else
    echo -e "${RED}Rust cargo is not installed. Please install Rust and then run: cargo install wasm-pack${NC}"
    exit 1
  fi
fi

# Ensure dataset exists by merging packs at repo root (best-effort)
if command -v npm &> /dev/null; then
  echo "Ensuring dataset (texts.json) exists by merging packs..."
  (cd "$ROOT_DIR" && npm install && npm run --silent merge-packs) \
    && echo "Merged packs into texts.json" \
    || echo -e "${YELLOW}Warning:${NC} Could not merge packs; continuing with existing texts.json"
else
  echo -e "${YELLOW}Warning:${NC} npm not found; skipping dataset merge. Ensure texts.json exists at repo root."
fi

# Build the WASM module
echo "Building WASM module..."
cd "$ROOT_DIR/crates/wasm"

# Clean previous build
rm -rf pkg target

# Build with wasm-pack
wasm-pack build --target web --release

# Check if build was successful
if [ $? -ne 0 ]; then
    echo -e "${RED}Failed to build WASM module${NC}"
    exit 1
fi

cd "$SCRIPT_DIR"

# Clean previous build
rm -rf dist node_modules/.vite

# Copy shared texts.json into web/src/data if present
mkdir -p src/data
if [ -f "$ROOT_DIR/texts.json" ]; then
  cp "$ROOT_DIR/texts.json" src/data/texts.json
  echo "Copied shared texts.json into web/src/data/"
else
  echo -e "${YELLOW}Warning:${NC} ../texts.json not found. Using fallback web/src/data/texts.json"
fi

# Install dependencies
echo "Installing dependencies..."
npm install

# Type check
echo "Type checking..."
npm run type-check

# Start the development server
echo -e "${GREEN}Starting development server...${NC}"
echo -e "${GREEN}Website will be available at: http://localhost:3000${NC}"
npm run dev