Files
strata-compile/scripts/upgrade.sh
Carlos Gutierrez 9e451469f5 git commit -m "feat: initial release of Strata framework v0.1.0
- Static compiler with STRC pattern (Static Template Resolution with
   Compartmentalized Layers)
   - Template syntax: { } interpolation, { s-for }, { s-if/s-elif/s-else
    }
   - File types: .strata, .compiler.sts, .service.sts, .api.sts, .sts,
   .scss
   - CLI tools: strata dev, strata build, strata g (generators)
   - create-strata scaffolding CLI with Pokemon API example
   - Dev server with WebSocket HMR (Hot Module Replacement)
   - Documentation: README, ARCHITECTURE, CHANGELOG, CONTRIBUTING,
   LICENSE
2026-01-16 09:01:29 -05:00

190 lines
5.3 KiB
Bash
Executable File

#!/bin/bash
# Strata Framework - Upgrade Script
# Usage: ./scripts/upgrade.sh [options]
# --check Only check for updates, don't install
# --force Force reinstall even if up-to-date
# --help Show this help message
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
BOLD='\033[1m'
# Directories
STRATA_HOME="${STRATA_HOME:-$HOME/.strata}"
STRATA_CONFIG="$STRATA_HOME/config"
# Script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$(dirname "$SCRIPT_DIR")"
# Options
CHECK_ONLY=false
FORCE=false
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--check)
CHECK_ONLY=true
shift
;;
--force|-f)
FORCE=true
shift
;;
--help|-h)
echo "Strata Framework - Upgrade Script"
echo ""
echo "Usage: ./scripts/upgrade.sh [options]"
echo ""
echo "Options:"
echo " --check Only check for updates"
echo " --force Force reinstall even if up-to-date"
echo " --help Show this help message"
exit 0
;;
*)
echo -e "${RED}Unknown option: $1${NC}"
exit 1
;;
esac
done
print_step() {
echo -e "${BLUE}${NC} $1"
}
print_success() {
echo -e "${GREEN}${NC} $1"
}
print_warning() {
echo -e "${YELLOW}${NC} $1"
}
print_error() {
echo -e "${RED}${NC} $1"
}
# Get current installed version
get_installed_version() {
if [ -f "$STRATA_CONFIG/strata.json" ]; then
grep '"version"' "$STRATA_CONFIG/strata.json" | cut -d'"' -f4
elif [ -x "$STRATA_HOME/bin/strata" ]; then
"$STRATA_HOME/bin/strata" version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || echo "unknown"
else
echo "not installed"
fi
}
# Get repo version from package.json
get_repo_version() {
if [ -f "$REPO_DIR/package.json" ]; then
grep '"version"' "$REPO_DIR/package.json" | head -1 | cut -d'"' -f4
else
echo "unknown"
fi
}
# Compare versions (returns 0 if $1 < $2)
version_lt() {
[ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1)" = "$1" ] && [ "$1" != "$2" ]
}
echo ""
echo -e "${CYAN}╔═══════════════════════════════════════════════════════╗${NC}"
echo -e "${CYAN}║ Strata Framework - Upgrade Check ║${NC}"
echo -e "${CYAN}╚═══════════════════════════════════════════════════════╝${NC}"
echo ""
# Check versions
print_step "Checking versions..."
INSTALLED_VERSION=$(get_installed_version)
REPO_VERSION=$(get_repo_version)
echo " Installed: $INSTALLED_VERSION"
echo " Available: $REPO_VERSION"
echo ""
# Determine if upgrade is needed
if [ "$INSTALLED_VERSION" = "not installed" ]; then
print_warning "Strata is not installed"
echo ""
echo " Run the installer:"
echo -e " ${CYAN}./scripts/install.sh${NC}"
exit 0
fi
NEEDS_UPGRADE=false
if [ "$INSTALLED_VERSION" = "unknown" ] || [ "$REPO_VERSION" = "unknown" ]; then
print_warning "Unable to determine version comparison"
NEEDS_UPGRADE=true
elif version_lt "$INSTALLED_VERSION" "$REPO_VERSION"; then
NEEDS_UPGRADE=true
fi
if [ "$NEEDS_UPGRADE" = false ] && [ "$FORCE" = false ]; then
print_success "Strata is up-to-date!"
exit 0
fi
if [ "$NEEDS_UPGRADE" = true ]; then
echo -e "${YELLOW}Update available: $INSTALLED_VERSION$REPO_VERSION${NC}"
else
echo "Forcing reinstall of version $REPO_VERSION"
fi
echo ""
if [ "$CHECK_ONLY" = true ]; then
echo "Run without --check to install the update."
exit 0
fi
# Perform upgrade
print_step "Pulling latest changes..."
cd "$REPO_DIR"
if [ -d ".git" ]; then
git pull --rebase 2>/dev/null || print_warning "Could not pull (not a git repo or no remote)"
fi
print_step "Rebuilding compiler..."
cd "$REPO_DIR/compiler"
go mod download
go build -ldflags="-s -w" -o "$REPO_DIR/bin/strata" ./cmd/strata
cp "$REPO_DIR/bin/strata" "$STRATA_HOME/bin/strata"
chmod +x "$STRATA_HOME/bin/strata"
print_step "Updating npm dependencies..."
cd "$REPO_DIR"
npm install --silent
print_step "Updating configuration..."
# Update version in config
if [ -f "$STRATA_CONFIG/strata.json" ]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "s/\"version\": \".*\"/\"version\": \"$REPO_VERSION\"/" "$STRATA_CONFIG/strata.json"
else
sed -i "s/\"version\": \".*\"/\"version\": \"$REPO_VERSION\"/" "$STRATA_CONFIG/strata.json"
fi
fi
echo ""
echo -e "${GREEN}════════════════════════════════════════════════════════${NC}"
echo -e "${GREEN} Upgrade Complete! ${NC}"
echo -e "${GREEN}════════════════════════════════════════════════════════${NC}"
echo ""
echo " Strata has been upgraded to version $REPO_VERSION"
echo ""
echo " Run 'strata version' to verify."
echo ""