Refine setup process

This commit is contained in:
SaraJane
2026-01-15 11:30:42 +00:00
parent 442cba1908
commit 5a1d5791f4
4 changed files with 94 additions and 72 deletions

View File

@ -49,7 +49,7 @@ VITE_INDEXER_PORT=""
# Web3Auth Configuration
# Get your Client ID from https://dashboard.web3auth.io
# Web3Auth enables social login (Google, GitHub, etc.) that auto-generates Algorand wallets
VITE_WEB3AUTH_CLIENT_ID=
VITE_WEB3AUTH_CLIENT_ID=YOUR_CLIENT_ID_GOES_HERE
# # ======================

View File

@ -18,6 +18,7 @@
"@web3auth/modal": "^9.7.0",
"algosdk": "^3.0.0",
"daisyui": "^4.0.0",
"idb-keyval": "^6.2.2",
"lute-connect": "^1.6.3",
"notistack": "^3.0.1",
"react": "^18.2.0",
@ -8086,9 +8087,7 @@
"version": "6.2.2",
"resolved": "https://registry.npmjs.org/idb-keyval/-/idb-keyval-6.2.2.tgz",
"integrity": "sha512-yjD9nARJ/jb1g+CvD0tlhUHOrJ9Sy0P8T9MF3YaLlHnSRpwPfpTX0XIvpmw3gAJUmEu3FiICLBDPXVwyEvrleg==",
"license": "Apache-2.0",
"optional": true,
"peer": true
"license": "Apache-2.0"
},
"node_modules/ieee754": {
"version": "1.2.1",

View File

@ -45,6 +45,7 @@
"@web3auth/modal": "^9.7.0",
"algosdk": "^3.0.0",
"daisyui": "^4.0.0",
"idb-keyval": "^6.2.2",
"lute-connect": "^1.6.3",
"notistack": "^3.0.1",
"react": "^18.2.0",

154
setup.sh
View File

@ -4,19 +4,15 @@ set -euo pipefail
# ------------------------------------------------------------
# TokenizeRWA Template - One-command setup + run script
#
# Usage (from repo root):
# chmod +x setup.sh
# ./setup.sh
#
# What it does:
# - Ensures AlgoKit CLI is installed (algokit command)
# - Ensures AlgoKit CLI is installed
# - Installs frontend dependencies
# - (Optional) Installs backend deps if Node >= 22
# - Runs frontend dev server (which also runs algokit project link --all)
# - Auto-creates .env files by copying .env.template
# - Runs frontend dev server
# ------------------------------------------------------------
FRONTEND_DIR="projects/TokenizeRWATemplate-frontend"
BACKEND_DIR="smart_contracts"
NFT_MINT_DIR="projects/TokenizeRWATemplate-contracts/NFT_mint_server"
PORT="${PORT:-5173}"
# --- Helpers ---
@ -27,7 +23,6 @@ err() { echo -e "\033[1;31m[error]\033[0m $*"; }
command_exists() { command -v "$1" >/dev/null 2>&1; }
get_node_major() {
# prints major version as integer, or empty
if ! command_exists node; then
echo ""
return
@ -35,7 +30,10 @@ get_node_major() {
node -p "process.versions.node.split('.')[0]" 2>/dev/null || echo ""
}
# --- Sanity checks ---
# ------------------------------------------------------------
# SANITY CHECKS
# ------------------------------------------------------------
log "Starting TokenizeRWA Template setup..."
if [ ! -d "$FRONTEND_DIR" ]; then
@ -45,87 +43,111 @@ if [ ! -d "$FRONTEND_DIR" ]; then
fi
if ! command_exists npm; then
err "npm not found. Please install Node.js (Node >= 20) first."
err "npm not found. Please install Node.js first."
exit 1
fi
NODE_MAJOR="$(get_node_major)"
if [ -z "$NODE_MAJOR" ]; then
err "Node.js not found. Please install Node.js (Node >= 20) first."
if [ -z "$NODE_MAJOR" ] || [ "$NODE_MAJOR" -lt 20 ]; then
err "Node.js >= 20 is required for the frontend."
exit 1
fi
if [ "$NODE_MAJOR" -lt 20 ]; then
err "Node.js version is too old (detected major: $NODE_MAJOR). Frontend requires Node >= 20."
err "Fix: install Node 20+ (recommend nvm) and re-run."
exit 1
fi
log "Node detected: $(node -v) | npm: $(npm -v)"
log "Node detected: v$(node -v) | npm: v$(npm -v)"
# ------------------------------------------------------------
# ALGOKIT CLI
# ------------------------------------------------------------
# --- Ensure AlgoKit CLI exists ---
# In Codespaces, pip installs usually land in ~/.local/bin
export PATH="$HOME/.local/bin:$PATH"
if ! command_exists algokit; then
log "AlgoKit CLI (algokit) not found. Installing via pip..."
log "AlgoKit CLI not found. Installing..."
# Prefer python3 if available, else python
PYTHON_BIN=""
if command_exists python3; then
PYTHON_BIN="python3"
elif command_exists python; then
PYTHON_BIN="python"
fi
if [ -z "$PYTHON_BIN" ]; then
err "Python not found. Python is required to install AlgoKit CLI via pip."
err "Fix: install Python 3 and re-run."
python3 -m pip install --user --upgrade pip algokit >/dev/null
else
err "Python3 is required to install AlgoKit."
exit 1
fi
# Ensure pip exists
if ! $PYTHON_BIN -m pip --version >/dev/null 2>&1; then
err "pip not available for $PYTHON_BIN."
err "Fix: install pip for Python 3 and re-run."
exit 1
fi
$PYTHON_BIN -m pip install --upgrade pip >/dev/null
$PYTHON_BIN -m pip install --user algokit >/dev/null
# Re-apply PATH (some shells need it after install)
export PATH="$HOME/.local/bin:$PATH"
fi
if ! command_exists algokit; then
err "AlgoKit CLI install attempted but 'algokit' is still not on PATH."
err "Try: export PATH=\"\$HOME/.local/bin:\$PATH\""
exit 1
fi
log "AlgoKit CLI ready"
log "AlgoKit CLI ready: $(algokit --version 2>/dev/null || echo 'installed')"
# ------------------------------------------------------------
# FRONTEND DEPENDENCIES
# ------------------------------------------------------------
# --- Optional: backend deps install (only if Node >= 22) ---
if [ -d "$BACKEND_DIR" ]; then
if [ "$NODE_MAJOR" -ge 22 ]; then
log "Backend detected ($BACKEND_DIR) and Node >= 22, installing backend dependencies..."
(cd "$BACKEND_DIR" && npm install)
else
warn "Backend detected ($BACKEND_DIR) but Node is < 22 (you have $NODE_MAJOR)."
warn "Skipping backend npm install to avoid engine mismatch. This does NOT block running the frontend."
warn "If you want backend later: upgrade Node to 22+ and run: (cd $BACKEND_DIR && npm install)"
fi
else
warn "Backend directory not found at '$BACKEND_DIR' (this is okay for frontend-only usage)."
fi
# --- Frontend install + run ---
log "Installing frontend dependencies..."
(cd "$FRONTEND_DIR" && npm install)
(
cd "$FRONTEND_DIR"
npm install
npm install idb-keyval
)
# ------------------------------------------------------------
# ENV FILE HANDLING
# ------------------------------------------------------------
create_env_file() {
local TARGET_DIR="$1"
local NAME="$2"
local ENV_FILE="$TARGET_DIR/.env"
local TEMPLATE_FILE="$TARGET_DIR/.env.template"
if [ -f "$ENV_FILE" ]; then
log "$NAME .env already exists — leaving it untouched."
return
fi
if [ -f "$TEMPLATE_FILE" ]; then
log "Creating $NAME .env from .env.template"
cp "$TEMPLATE_FILE" "$ENV_FILE"
else
warn "$NAME .env.template not found — creating guidance-only .env"
cat <<EOF > "$ENV_FILE"
# Copy the contents from .env.template into this one
EOF
fi
}
# Frontend .env
create_env_file "$FRONTEND_DIR" "Frontend"
# NFT mint server .env
if [ -d "$NFT_MINT_DIR" ]; then
create_env_file "$NFT_MINT_DIR" "NFT mint server"
else
warn "NFT mint server directory not found — skipping .env creation."
fi
# ------------------------------------------------------------
# NFT MINT SERVER DEPENDENCIES
# ------------------------------------------------------------
if [ -d "$NFT_MINT_DIR" ]; then
log "Installing NFT mint server dependencies..."
warn "You may see Node engine warnings — this is expected and safe to ignore."
(
cd "$NFT_MINT_DIR"
npm install
)
log "NFT mint server dependencies installed."
log "Note: Server is NOT started automatically."
log "Edit $NFT_MINT_DIR/.env before running it manually."
fi
# ------------------------------------------------------------
# RUN FRONTEND
# ------------------------------------------------------------
log "Starting frontend dev server on port $PORT..."
log "If you are in Codespaces: forward port $PORT and open in browser."
log "Codespaces users: forward port $PORT"
cd "$FRONTEND_DIR"
npm run dev -- --host 0.0.0.0 --port "$PORT"