Refine setup process
This commit is contained in:
@ -49,7 +49,7 @@ VITE_INDEXER_PORT=""
|
|||||||
# Web3Auth Configuration
|
# Web3Auth Configuration
|
||||||
# Get your Client ID from https://dashboard.web3auth.io
|
# Get your Client ID from https://dashboard.web3auth.io
|
||||||
# Web3Auth enables social login (Google, GitHub, etc.) that auto-generates Algorand wallets
|
# 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
|
||||||
|
|
||||||
|
|
||||||
# # ======================
|
# # ======================
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
"@web3auth/modal": "^9.7.0",
|
"@web3auth/modal": "^9.7.0",
|
||||||
"algosdk": "^3.0.0",
|
"algosdk": "^3.0.0",
|
||||||
"daisyui": "^4.0.0",
|
"daisyui": "^4.0.0",
|
||||||
|
"idb-keyval": "^6.2.2",
|
||||||
"lute-connect": "^1.6.3",
|
"lute-connect": "^1.6.3",
|
||||||
"notistack": "^3.0.1",
|
"notistack": "^3.0.1",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
@ -8086,9 +8087,7 @@
|
|||||||
"version": "6.2.2",
|
"version": "6.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/idb-keyval/-/idb-keyval-6.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/idb-keyval/-/idb-keyval-6.2.2.tgz",
|
||||||
"integrity": "sha512-yjD9nARJ/jb1g+CvD0tlhUHOrJ9Sy0P8T9MF3YaLlHnSRpwPfpTX0XIvpmw3gAJUmEu3FiICLBDPXVwyEvrleg==",
|
"integrity": "sha512-yjD9nARJ/jb1g+CvD0tlhUHOrJ9Sy0P8T9MF3YaLlHnSRpwPfpTX0XIvpmw3gAJUmEu3FiICLBDPXVwyEvrleg==",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0"
|
||||||
"optional": true,
|
|
||||||
"peer": true
|
|
||||||
},
|
},
|
||||||
"node_modules/ieee754": {
|
"node_modules/ieee754": {
|
||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
|
|||||||
@ -45,6 +45,7 @@
|
|||||||
"@web3auth/modal": "^9.7.0",
|
"@web3auth/modal": "^9.7.0",
|
||||||
"algosdk": "^3.0.0",
|
"algosdk": "^3.0.0",
|
||||||
"daisyui": "^4.0.0",
|
"daisyui": "^4.0.0",
|
||||||
|
"idb-keyval": "^6.2.2",
|
||||||
"lute-connect": "^1.6.3",
|
"lute-connect": "^1.6.3",
|
||||||
"notistack": "^3.0.1",
|
"notistack": "^3.0.1",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
|
|||||||
158
setup.sh
158
setup.sh
@ -4,30 +4,25 @@ set -euo pipefail
|
|||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
# TokenizeRWA Template - One-command setup + run script
|
# TokenizeRWA Template - One-command setup + run script
|
||||||
#
|
#
|
||||||
# Usage (from repo root):
|
|
||||||
# chmod +x setup.sh
|
|
||||||
# ./setup.sh
|
|
||||||
#
|
|
||||||
# What it does:
|
# What it does:
|
||||||
# - Ensures AlgoKit CLI is installed (algokit command)
|
# - Ensures AlgoKit CLI is installed
|
||||||
# - Installs frontend dependencies
|
# - Installs frontend dependencies
|
||||||
# - (Optional) Installs backend deps if Node >= 22
|
# - Auto-creates .env files by copying .env.template
|
||||||
# - Runs frontend dev server (which also runs algokit project link --all)
|
# - Runs frontend dev server
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
FRONTEND_DIR="projects/TokenizeRWATemplate-frontend"
|
FRONTEND_DIR="projects/TokenizeRWATemplate-frontend"
|
||||||
BACKEND_DIR="smart_contracts"
|
NFT_MINT_DIR="projects/TokenizeRWATemplate-contracts/NFT_mint_server"
|
||||||
PORT="${PORT:-5173}"
|
PORT="${PORT:-5173}"
|
||||||
|
|
||||||
# --- Helpers ---
|
# --- Helpers ---
|
||||||
log() { echo -e "\033[1;36m[setup]\033[0m $*"; }
|
log() { echo -e "\033[1;36m[setup]\033[0m $*"; }
|
||||||
warn() { echo -e "\033[1;33m[warn]\033[0m $*"; }
|
warn() { echo -e "\033[1;33m[warn]\033[0m $*"; }
|
||||||
err() { echo -e "\033[1;31m[error]\033[0m $*"; }
|
err() { echo -e "\033[1;31m[error]\033[0m $*"; }
|
||||||
|
|
||||||
command_exists() { command -v "$1" >/dev/null 2>&1; }
|
command_exists() { command -v "$1" >/dev/null 2>&1; }
|
||||||
|
|
||||||
get_node_major() {
|
get_node_major() {
|
||||||
# prints major version as integer, or empty
|
|
||||||
if ! command_exists node; then
|
if ! command_exists node; then
|
||||||
echo ""
|
echo ""
|
||||||
return
|
return
|
||||||
@ -35,7 +30,10 @@ get_node_major() {
|
|||||||
node -p "process.versions.node.split('.')[0]" 2>/dev/null || echo ""
|
node -p "process.versions.node.split('.')[0]" 2>/dev/null || echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Sanity checks ---
|
# ------------------------------------------------------------
|
||||||
|
# SANITY CHECKS
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
log "Starting TokenizeRWA Template setup..."
|
log "Starting TokenizeRWA Template setup..."
|
||||||
|
|
||||||
if [ ! -d "$FRONTEND_DIR" ]; then
|
if [ ! -d "$FRONTEND_DIR" ]; then
|
||||||
@ -45,87 +43,111 @@ if [ ! -d "$FRONTEND_DIR" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if ! command_exists npm; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
NODE_MAJOR="$(get_node_major)"
|
NODE_MAJOR="$(get_node_major)"
|
||||||
if [ -z "$NODE_MAJOR" ]; then
|
if [ -z "$NODE_MAJOR" ] || [ "$NODE_MAJOR" -lt 20 ]; then
|
||||||
err "Node.js not found. Please install Node.js (Node >= 20) first."
|
err "Node.js >= 20 is required for the frontend."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$NODE_MAJOR" -lt 20 ]; then
|
log "Node detected: $(node -v) | npm: $(npm -v)"
|
||||||
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: 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"
|
export PATH="$HOME/.local/bin:$PATH"
|
||||||
|
|
||||||
if ! command_exists algokit; then
|
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
|
if command_exists python3; then
|
||||||
PYTHON_BIN="python3"
|
python3 -m pip install --user --upgrade pip algokit >/dev/null
|
||||||
elif command_exists python; then
|
else
|
||||||
PYTHON_BIN="python"
|
err "Python3 is required to install AlgoKit."
|
||||||
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."
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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"
|
export PATH="$HOME/.local/bin:$PATH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! command_exists algokit; then
|
log "AlgoKit CLI ready"
|
||||||
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: $(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..."
|
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 "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"
|
cd "$FRONTEND_DIR"
|
||||||
npm run dev -- --host 0.0.0.0 --port "$PORT"
|
npm run dev -- --host 0.0.0.0 --port "$PORT"
|
||||||
|
|||||||
Reference in New Issue
Block a user