Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
New interactive installer (#13261)
Damian Legawiecb047731a67b6
diff --git a/.gitignore b/.gitignoreindex 6671a5f86a..a5825594fc 100644--- a/.gitignore+++ b/.gitignore@@ -32,6 +32,7 @@ public/attachmentspublic/blank_iframe.htmlpublic/ckeditorasandbox/*+spree/*spree_devspree_testtestappdiff --git a/admin/lib/generators/spree/admin/devise/devise_generator.rb b/admin/lib/generators/spree/admin/devise/devise_generator.rbnew file mode 100644index 0000000000..42210fa572--- /dev/null+++ b/admin/lib/generators/spree/admin/devise/devise_generator.rb@@ -0,0 +1,33 @@+require 'rails/generators'++module Spree+ module Admin+ module Generators+ class DeviseGenerator < Rails::Generators::Base+ desc 'Installs Spree Admin Devise controllers'++ def install+ # add devise routes+ insert_into_file 'config/routes.rb', after: "Rails.application.routes.draw do\n" do+ <<-ROUTES.strip_heredoc.indent!(2)+ Spree::Core::Engine.add_routes do+ # Admin authentication+ devise_for(+ Spree.admin_user_class.model_name.singular_route_key,+ class_name: Spree.admin_user_class.to_s,+ controllers: {+ sessions: 'spree/admin/user_sessions',+ passwords: 'spree/admin/user_passwords'+ },+ skip: :registrations,+ path: :admin_user,+ router_name: :spree+ )+ end+ ROUTES+ end+ end+ end+ end+ end+enddiff --git a/bin/sandbox.sh b/bin/sandbox.shindex 7ee016a501..f5a25e9773 100755--- a/bin/sandbox.sh+++ b/bin/sandbox.sh@@ -1,125 +1,12 @@-#!/bin/sh-# Used in the sandbox rake task in Rakefile+#!/bin/bash+# Used to create a sandbox Rails application for testing Spree locallyset -e-case "$DB" in-mysql)- RAILSDB="mysql"- ;;-postgres)- RAILSDB="postgresql"- ;;-sqlite|'')- RAILSDB="sqlite3"- ;;-*)- echo "Invalid DB specified: $DB"- exit 1- ;;-esac+# Change to the spree root directory if we're not already there+cd "$(dirname "$0")/.."-rm -rf ./sandbox+echo "Creating Spree sandbox application..."-mkdir -p sandbox/app/assets/config-cat <<MANIFEST > sandbox/app/assets/config/manifest.js-//= link_tree ../images-//= link_directory ../stylesheets .css-MANIFEST--bundle exec rails new sandbox --database="$RAILSDB" \- --skip-bundle \- --skip-git \- --skip-keeps \- --skip-rc \- --skip-test \- --skip-docker \- --skip-rubocop \- --skip-brakeman \- --skip-ci \- --skip-kamal \- --skip-devcontainer \- --skip-solid \--if [ ! -d "sandbox" ]; then- echo 'sandbox rails application failed'- exit 1-fi--cd ./sandbox--cat <<RUBY >> Gemfile-gem 'redis'-gem 'devise'-gem 'spree', path: '..'-gem 'spree_emails', path: '../emails'-gem 'spree_sample', path: '../sample'-gem 'spree_admin', path: '../admin'-gem 'spree_storefront', path: '../storefront'-gem 'spree_stripe', github: 'spree/spree_stripe', branch: 'main'-gem 'spree_google_analytics', github: 'spree/spree_google_analytics', branch: 'main'-gem 'spree_klaviyo', github: 'spree/spree_klaviyo', branch: 'main'-gem 'spree_paypal_checkout', github: 'spree/spree_paypal_checkout', branch: 'main'-gem 'spree_i18n', github: 'spree-contrib/spree_i18n', branch: 'main'--group :test, :development do- gem 'bullet'- gem 'pry-byebug'- gem 'awesome_print'- gem 'letter_opener'- gem 'listen'-end-RUBY--touch config/initializers/bullet.rb--cat <<RUBY >> config/initializers/bullet.rb-if Rails.env.development? && defined?(Bullet)- Bullet.enable = true- Bullet.rails_logger = true- Bullet.stacktrace_includes = [ 'spree_core', 'spree_storefront', 'spree_api', 'spree_admin', 'spree_emails' ]-end-RUBY--# configure actioncable to use redis-rm -rf config/cable.yml-touch config/cable.yml-cat <<RUBY >> config/cable.yml-development:- adapter: redis- url: redis://localhost:6379/0-RUBY--bundle update-bundle install --gemfile Gemfile --path ../vendor/bundle--bin/rails importmap:install turbo:install stimulus:install--bin/rails db:drop || true-bin/rails db:create--# setup devise-bin/rails g devise:install-bin/rails g devise Spree::User--# setup spree-bin/rails g spree:install --auto-accept --user_class=Spree::User --authentication=devise --install_storefront=true --install_admin=true --sample=true-bin/rails g spree_stripe:install-bin/rails g spree_google_analytics:install-bin/rails g spree_klaviyo:install-bin/rails g spree_paypal_checkout:install-# setup letter_opener & listen gem-# https://github.com/rails/propshaft?tab=readme-ov-file#improving-performance-in-development-cat <<RUBY >> config/environments/development.rb-Rails.application.config.action_mailer.delivery_method = :letter_opener-Rails.application.config.action_mailer.perform_deliveries = true-Rails.application.config.file_watcher = ActiveSupport::EventedFileUpdateChecker-RUBY--# add web to Procfile.dev-echo "\nweb: bin/rails s -p 3000" >> Procfile.dev--# add root to config/routes.rb-sed -i '' -e '$i\- root "spree/home#index"\-' config/routes.rb+./install.sh --app-name=sandbox --verbose --auto-accept --local --force+rm -rf sandbox/.gitdiff --git a/core/app/services/spree/seeds/admin_user.rb b/core/app/services/spree/seeds/admin_user.rbindex 68684e4dc6..71d39c6987 100644--- a/core/app/services/spree/seeds/admin_user.rb+++ b/core/app/services/spree/seeds/admin_user.rb@@ -6,11 +6,11 @@ module Spreedef callif Spree.admin_user_class.present? && Spree.admin_user_class.count.zero?user = Spree.admin_user_class.create!(- email: '[email protected]',- password: 'spree123',- password_confirmation: 'spree123',- first_name: 'Spree',- last_name: 'Admin'+ email: ENV.fetch('ADMIN_EMAIL', '[email protected]'),+ password: ENV.fetch('ADMIN_PASSWORD', 'spree123'),+ password_confirmation: ENV.fetch('ADMIN_PASSWORD', 'spree123'),+ first_name: ENV.fetch('ADMIN_FIRST_NAME', 'Spree'),+ last_name: ENV.fetch('ADMIN_LAST_NAME', 'Admin'))user.save!diff --git a/core/lib/generators/spree/authentication/devise/devise_generator.rb b/core/lib/generators/spree/authentication/devise/devise_generator.rbindex 1607da39b7..2308621275 100644--- a/core/lib/generators/spree/authentication/devise/devise_generator.rb+++ b/core/lib/generators/spree/authentication/devise/devise_generator.rb@@ -48,6 +48,30 @@ module Spreesay "Please replace < ApplicationRecord with < Spree.base_class in #{user_class_file}"end+ if Spree.admin_user_class != Spree.user_class+ admin_user_class_file = Rails.root.join('app', 'models', "#{Spree.admin_user_class.name.underscore}.rb")++ if File.exist?(admin_user_class_file)+ inject_into_file admin_user_class_file, after: "class #{Spree.admin_user_class.name} < ApplicationRecord\n" do+ <<-RUBY+ # Spree modules+ include Spree::UserMethods+ RUBY+ end+ gsub_file admin_user_class_file, "< ApplicationRecord", "< Spree.base_class"++ say "Successfully added Spree admin user modules into #{admin_user_class_file}"+ else+ say "Could not locate admin user model file at #{admin_user_class_file}. Please add these lines manually:", :red+ say <<~RUBY+ # Spree modules+ include Spree::UserMethods+ RUBY++ say "Please replace < ApplicationRecord with < Spree.base_class in #{admin_user_class_file}"+ end+ end+append_file 'config/initializers/spree.rb' do%Q{if defined?(Devise) && Devise.respond_to?(:parent_controller)diff --git a/core/lib/generators/spree/install/install_generator.rb b/core/lib/generators/spree/install/install_generator.rbindex 77b6b92d45..495bf7fc1f 100644--- a/core/lib/generators/spree/install/install_generator.rb+++ b/core/lib/generators/spree/install/install_generator.rb@@ -14,6 +14,7 @@ module Spreeclass_option :install_admin, type: :boolean, default: false, banner: 'installs default rails admin'class_option :auto_accept, type: :booleanclass_option :user_class, type: :string+ class_option :admin_user_class, type: :stringclass_option :admin_email, type: :stringclass_option :admin_password, type: :stringclass_option :lib_name, type: :string, default: 'spree'@@ -69,6 +70,11 @@ module Spreedef install_adminif @install_admin && Spree::Core::Engine.admin_available?generate 'spree:admin:install'++ # generate devise controllers if authentication is devise+ if @authentication == 'devise'+ generate 'spree:admin:devise'+ endendend@@ -95,7 +101,6 @@ module Spreeappend_file 'db/seeds.rb', <<-SEEDS.strip_heredocSpree::Core::Engine.load_seed if defined?(Spree::Core)- Spree::Auth::Engine.load_seed if defined?(Spree::Auth)SEEDSend@@ -133,7 +138,7 @@ module Spreecmd.callendelse- say_status :skipping, 'seed data (you can always run rake db:seed)'+ say_status :skipping, 'seed data (you can always run bin/rails db:seed)'endenddiff --git a/core/lib/generators/spree/install/templates/config/initializers/spree.rb b/core/lib/generators/spree/install/templates/config/initializers/spree.rbindex 2f48ae0a18..ecac69781a 100644--- a/core/lib/generators/spree/install/templates/config/initializers/spree.rb+++ b/core/lib/generators/spree/install/templates/config/initializers/spree.rb@@ -91,5 +91,4 @@ Rails.application.config.after_initialize doendSpree.user_class = <%= (options[:user_class].blank? ? 'Spree::LegacyUser' : options[:user_class]).inspect %>-# Use a different class for admin users-# Spree.admin_user_class = 'AdminUser'+Spree.admin_user_class = <%= (options[:admin_user_class].blank? ? (options[:user_class].blank? ? 'Spree::LegacyUser' : options[:user_class]) : options[:admin_user_class]).inspect %>diff --git a/docs/developer/contributing/developing-spree.mdx b/docs/developer/contributing/developing-spree.mdxindex 002a01e1ee..caa8bf2671 100644--- a/docs/developer/contributing/developing-spree.mdx+++ b/docs/developer/contributing/developing-spree.mdx@@ -21,65 +21,21 @@ Go to [Spree GitHub repository](https://github.com/spree/spree) and click the **## Local setup-1. Clone your fork repository+Clone your fork repository```bashgit clone git://github.com/your_github_username/spree.git && cd spree```-2. [Install ruby](https://www.ruby-lang.org/en/documentation/installation/)+## Create a sandbox application- On MacOS, we recommend using [rbenv](https://github.com/rbenv/rbenv) to install Ruby.-- Firstly, install rbenv itself:-- ```bash- curl -fsSL https://rbenv.org/install.sh | bash- ```-- Then, install Ruby:-- ```bash- rbenv init && rbenv install && rbenv global 3.3.0- ```--3. Install required libraries-- You will need SQLite (or PostgreSQL or MySQL) and libvips installed on your system. You can install them using the following commands:-- ```bash- brew install vips- ```-- If you are using Ubuntu or Windows Linux Subsystem, you can install libvips using the following command:-- ```bash- sudo apt-get install libvips- ```-- Please refer to the [libvips installation guide](https://libvips.github.io/libvips/install.html) for more information.--4. Install the gem dependencies+Bellow command will setup a Rails application with Spree pre-installed with some data seeded:```bash- bundle install+ bin/sandbox.sh```-## Creating Sandbox application--Bellow command will setup a Rails application with Spree pre-installed with some data seeded:--```bash-bin/sandbox.sh-```--By default, Sandbox uses the **SQLite** database. But you can switch to **PostgreSQL** or **MySQL**:--```bash-DB=postgres DB_PASSWORD=password DB_USERNAME=postgres DB_HOST=localhost bin/sandbox.sh-```--We recommend sticking to SQLite for development purposes as it doesn't require any additional setup.+This script will automatically install the necessary dependencies such as Ruby, libvips and Rails.## Running the applicationdiff --git a/install.sh b/install.shnew file mode 100755index 0000000000..4fab9cd12e--- /dev/null+++ b/install.sh@@ -0,0 +1,621 @@+#!/bin/bash++# Spree Commerce Guided Installer+# Usage: bash -c "$(curl -fsSL https://raw.githubusercontent.com/spree/spree/main/install.sh)"+# Usage with options: bash install.sh --verbose --local --app-name=my_store --auto-accept --force+# Options:+# --verbose, -v Show detailed output+# --local, -l Use local Spree gems from parent directory+# --app-name=NAME Set application name (skips prompt)+# --auto-accept, -y Use default values for all prompts (non-interactive mode)+# --force, -f Remove existing directory if it exists++set -e++# Colors for output+RED='\033[0;31m'+GREEN='\033[0;32m'+YELLOW='\033[1;33m'+BLUE='\033[0;34m'+BOLD='\033[1m'+NC='\033[0m' # No Color++# Configuration+RUBY_VERSION="3.3.0"+RAILS_VERSION="8.0.4"+APP_NAME=""+LOAD_SAMPLE_DATA="false"+TEMPLATE_URL="https://raw.githubusercontent.com/spree/spree/main/template.rb"+VERBOSE=false+USE_LOCAL_SPREE=false+AUTO_ACCEPT=false+FORCE_REMOVE=false++# Parse arguments+for arg in "$@"; do+ case $arg in+ --verbose|-v)+ VERBOSE=true+ shift+ ;;+ --local|-l)+ USE_LOCAL_SPREE=true+ shift+ ;;+ --app-name=*)+ APP_NAME="${arg#*=}"+ shift+ ;;+ --auto-accept|-y)+ AUTO_ACCEPT=true+ shift+ ;;+ --force|-f)+ FORCE_REMOVE=true+ shift+ ;;+ esac+done++# Helper functions+print_header() {+ echo -e "\n${BOLD}${BLUE}===================================================${NC}"+ echo -e "${BOLD}${BLUE} Spree Commerce Guided Installer${NC}"+ echo -e "${BOLD}${BLUE}===================================================${NC}\n"+}++print_step() {+ echo -e "\n${BOLD}${GREEN}➜${NC} ${BOLD}$1${NC}"+}++print_info() {+ 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"+}++command_exists() {+ command -v "$1" >/dev/null 2>&1+}++press_any_key() {+ echo -e "\n${BOLD}Press any key to continue...${NC}"+ read -n 1 -s+}++run_quiet() {+ if [ "$VERBOSE" = true ]; then+ "$@"+ else+ "$@" >/dev/null 2>&1+ fi+}++run_with_status() {+ local description="$1"+ shift++ if [ "$VERBOSE" = true ]; then+ print_info "$description"+ "$@"+ else+ "$@" >/dev/null 2>&1+ fi+}++show_spinner() {+ local pid=$1+ local message=$2+ local spin='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'+ local i=0++ # Hide cursor+ tput civis 2>/dev/null || true++ while kill -0 $pid 2>/dev/null; do+ i=$(( (i+1) %10 ))+ printf "\r${BLUE}${spin:$i:1}${NC} ${message}..."+ sleep 0.1+ done++ # Show cursor+ tput cnorm 2>/dev/null || true+ printf "\r"+}++# Detect OS+detect_os() {+ print_step "Detecting operating system..."++ if [[ "$OSTYPE" == "linux-gnu"* ]]; then+ OS="linux"+ if [ -f /etc/os-release ]; then+ . /etc/os-release+ DISTRO=$ID+ print_success "Detected: Linux ($NAME)"+ else+ DISTRO="unknown"+ print_success "Detected: Linux (Unknown distribution)"+ fi+ elif [[ "$OSTYPE" == "darwin"* ]]; then+ OS="macos"+ DISTRO="macos"+ print_success "Detected: macOS"+ elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then+ OS="windows"+ DISTRO="windows"+ print_warning "Windows detected. WSL is required for Spree."+ echo -e "\nPlease install WSL (Windows Subsystem for Linux) first:"+ echo -e " ${BOLD}wsl --install${NC}"+ echo -e "\nThen run this installer from within WSL."+ exit 1+ else+ OS="unknown"+ DISTRO="unknown"+ print_error "Unsupported operating system: $OSTYPE"+ exit 1+ fi+}+++# Get app name from user+get_app_name() {+ print_step "Setting up your Spree application..."++ # Use default app name if auto-accept is enabled and no app name provided+ if [ "$AUTO_ACCEPT" = true ] && [[ -z "$APP_NAME" ]]; then+ APP_NAME="spree"+ print_info "Using default app name: $APP_NAME"+ fi++ # Check if app name was provided via command line argument or auto-accept+ if [[ -n "$APP_NAME" ]]; then+ # Validate app name provided via argument+ if [[ ! "$APP_NAME" =~ ^[a-z0-9_]+$ ]]; then+ print_error "App name must contain only lowercase letters, numbers, and underscores"+ print_error "Provided: $APP_NAME"+ exit 1+ fi++ # Handle existing directory+ if [ -d "$APP_NAME" ]; then+ if [ "$FORCE_REMOVE" = true ]; then+ print_warning "Directory '$APP_NAME' already exists, removing..."+ rm -rf "$APP_NAME"+ else+ print_error "Directory '$APP_NAME' already exists"+ print_error "Use --force to remove it automatically"+ exit 1+ fi+ fi++ print_success "App name set to: $APP_NAME"+ return 0+ fi++ # Interactive prompt if app name not provided+ echo -e "\n${BOLD}What would you like to name your application?${NC}"+ echo -e "This will be used for the directory name and Spree Commerce application name."+ echo -e "Use lowercase letters, numbers, and underscores (e.g., my_store, awesome_shop)"+ echo -e "${BLUE}Press Enter to use default: 'spree'${NC}"+ echo++ while true; do+ read -p "App name [spree]: " APP_NAME++ # Use default if empty+ if [[ -z "$APP_NAME" ]]; then+ APP_NAME="spree"+ fi++ # Validate app name+ if [[ ! "$APP_NAME" =~ ^[a-z0-9_]+$ ]]; then+ print_error "App name must contain only lowercase letters, numbers, and underscores"+ continue+ fi++ if [ -d "$APP_NAME" ]; then+ print_warning "Directory '$APP_NAME' already exists"+ read -p "Remove and continue? (y/n): " -n 1 -r+ echo+ if [[ $REPLY =~ ^[Yy]$ ]]; then+ rm -rf "$APP_NAME"+ break+ else+ print_info "Please choose a different name"+ continue+ fi+ fi++ break+ done++ print_success "App name set to: $APP_NAME"+}++# Ask about loading sample data+ask_sample_data() {+ print_step "Configure sample data..."++ # Skip prompt if auto-accept is enabled+ if [ "$AUTO_ACCEPT" = true ]; then+ LOAD_SAMPLE_DATA="true"+ print_info "Sample data will be loaded (default)"+ return 0+ fi++ echo -e "\n${BOLD}Would you like to load sample data?${NC}"+ echo -e "Sample data includes demo products, categories, and content to help you get started."+ echo -e "${BLUE}Press Enter to load sample data (recommended for testing)${NC}"+ echo++ read -p "Load sample data? (Y/n): " -r+ echo++ # Default to yes if empty response+ if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then+ LOAD_SAMPLE_DATA="true"+ print_success "Sample data will be loaded"+ else+ LOAD_SAMPLE_DATA="false"+ print_success "Sample data will not be loaded"+ fi+}++# Ask about admin credentials+ask_admin_credentials() {+ print_step "Configure admin user..."++ # Skip prompt if auto-accept is enabled+ if [ "$AUTO_ACCEPT" = true ]; then+ ADMIN_EMAIL="[email protected]"+ ADMIN_PASSWORD="spree123"+ print_info "Using default admin credentials:"+ print_info " Email: ${BOLD}$ADMIN_EMAIL${NC}"+ print_info " Password: ${BOLD}$ADMIN_PASSWORD${NC}"+ return 0+ fi++ echo -e "\n${BOLD}Set up your admin user credentials${NC}"+ echo -e "These credentials will be used to access the admin panel."+ echo -e "${BLUE}Press Enter to use defaults${NC}"+ echo++ # Ask for admin email+ read -p "Admin email [[email protected]]: " ADMIN_EMAIL+ if [[ -z "$ADMIN_EMAIL" ]]; then+ ADMIN_EMAIL="[email protected]"+ fi++ # Ask for admin password+ read -p "Admin password [spree123]: " ADMIN_PASSWORD+ if [[ -z "$ADMIN_PASSWORD" ]]; then+ ADMIN_PASSWORD="spree123"+ fi++ echo+ print_success "Admin credentials set:"+ print_info " Email: ${BOLD}$ADMIN_EMAIL${NC}"+ print_info " Password: ${BOLD}$ADMIN_PASSWORD${NC}"+}++# Install system dependencies+install_system_deps() {+ print_step "Installing system dependencies..."++ if [ "$OS" = "macos" ]; then+ if ! command_exists brew; then+ print_warning "Homebrew is not installed"+ echo -e "\n${BOLD}Installing Homebrew...${NC}"+ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"++ # Add Homebrew to PATH+ if [[ $(uname -m) == 'arm64' ]]; then+ echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile+ eval "$(/opt/homebrew/bin/brew shellenv)"+ else+ echo 'eval "$(/usr/local/bin/brew shellenv)"' >> ~/.zprofile+ eval "$(/usr/local/bin/brew shellenv)"+ fi++ print_success "Homebrew installed successfully"+ fi++ print_info "Installing libvips..."+ run_with_status "Running: brew install vips" brew install vips || {+ print_warning "Package may already be installed"+ }++ print_success "System dependencies installed"++ elif [ "$OS" = "linux" ]; then+ if [ "$DISTRO" = "ubuntu" ] || [ "$DISTRO" = "debian" ]; then+ print_info "Installing libvips-dev..."+ run_with_status "Running: apt-get update" sudo apt-get update+ run_with_status "Running: apt-get install runtime deps" sudo apt-get install -y build-essential libvips-dev libssl-dev libreadline-dev zlib1g-dev libsqlite3-dev++ print_success "System dependencies installed"+ elif [ "$DISTRO" = "fedora" ] || [ "$DISTRO" = "rhel" ] || [ "$DISTRO" = "centos" ]; then+ print_info "Installing vips development packages..."+ run_with_status "Running: dnf/yum install runtime deps" sudo dnf install -y vips vips-devel gcc gcc-c++ make openssl-devel readline-devel zlib-devel sqlite-devel || \+ sudo yum install -y vips vips-devel gcc gcc-c++ make openssl-devel readline-devel zlib-devel sqlite-devel++ print_success "System dependencies installed"+ else+ print_warning "Please install libvips development packages manually for your distribution"+ press_any_key+ fi+ fi+}++# Install rbenv and Ruby+install_ruby() {+ print_step "Checking Ruby installation..."++ # Check if Ruby 3.3.0 is already installed+ if command_exists ruby; then+ CURRENT_RUBY=$(ruby -v | awk '{print $2}' | cut -d'p' -f1)+ if [[ "$CURRENT_RUBY" == "$RUBY_VERSION"* ]]; then+ print_success "Ruby $RUBY_VERSION is already installed"+ return 0+ else+ print_info "Current Ruby version: $CURRENT_RUBY"+ print_info "Spree requires Ruby $RUBY_VERSION"+ fi+ fi++ # Check for rbenv+ if ! command_exists rbenv; then+ print_info "Installing rbenv..."++ if [ "$OS" = "macos" ]; then+ brew install rbenv ruby-build+ elif [ "$OS" = "linux" ]; then+ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash++ # Add rbenv to PATH+ export PATH="$HOME/.rbenv/bin:$PATH"+ eval "$(rbenv init - bash)"++ # Add to shell profile+ if [ -f ~/.bashrc ]; then+ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc+ echo 'eval "$(rbenv init - bash)"' >> ~/.bashrc+ fi+ if [ -f ~/.zshrc ]; then+ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc+ echo 'eval "$(rbenv init - zsh)"' >> ~/.zshrc+ fi+ fi++ print_success "rbenv installed"+ else+ print_success "rbenv is already installed"+ fi++ # Initialize rbenv in current shell+ export PATH="$HOME/.rbenv/bin:$PATH"+ eval "$(rbenv init - bash)" 2>/dev/null || true++ # Install Ruby 3.3.0+ print_info "Installing Ruby $RUBY_VERSION (this may take several minutes)..."++ if rbenv versions | grep -q "$RUBY_VERSION"; then+ print_success "Ruby $RUBY_VERSION is already installed via rbenv"+ else+ rbenv install "$RUBY_VERSION"+ print_success "Ruby $RUBY_VERSION installed successfully"+ fi++ rbenv global "$RUBY_VERSION"+ rbenv rehash++ print_success "Ruby $RUBY_VERSION is now active"+}++# Install Rails+install_rails() {+ print_step "Installing Rails $RAILS_VERSION..."++ # Ensure rbenv is initialized+ export PATH="$HOME/.rbenv/bin:$PATH"+ eval "$(rbenv init - bash)" 2>/dev/null || true++ # Check if Rails is already installed+ if command_exists rails; then+ CURRENT_RAILS=$(rails --version | awk '{print $2}')+ print_info "Current Rails version: $CURRENT_RAILS"+ fi++ # Install specific Rails version+ print_info "Installing Rails gem (this may take a few minutes)..."+ run_with_status "Running: gem install rails -v $RAILS_VERSION" gem install rails -v "$RAILS_VERSION" --no-document+ run_quiet rbenv rehash++ print_success "Rails $RAILS_VERSION installed successfully"+}++# Create Rails app with Spree template+create_rails_app() {+ print_step "Creating new Spree Commerce application..."++ # Ensure rbenv is initialized+ export PATH="$HOME/.rbenv/bin:$PATH"+ eval "$(rbenv init - bash)" 2>/dev/null || true++ # Download template if running from URL, or use local if exists+ TEMPLATE_FILE="template.rb"+ if [ ! -f "$TEMPLATE_FILE" ]; then+ print_info "Downloading Spree Rails template..."+ curl -fsSL "$TEMPLATE_URL" -o "$TEMPLATE_FILE"+ fi++ print_info "Creating Spree Commerce application '$APP_NAME'..."++ if [ "$VERBOSE" = false ]; then+ echo -e "${YELLOW}This will take several minutes. Please be patient...${NC}\n"+ fi++ # Prepare environment variables+ local use_local_spree="false"+ if [ "$USE_LOCAL_SPREE" = true ]; then+ use_local_spree="true"+ fi++ # Run rails new with the template+ if [ "$VERBOSE" = true ]; then+ VERBOSE_MODE=1 LOAD_SAMPLE_DATA="$LOAD_SAMPLE_DATA" USE_LOCAL_SPREE="$use_local_spree" ADMIN_EMAIL="$ADMIN_EMAIL" ADMIN_PASSWORD="$ADMIN_PASSWORD" rails _${RAILS_VERSION}_ new "$APP_NAME" -m "$TEMPLATE_FILE"+ else+ # Run in background with spinner+ VERBOSE_MODE=0 LOAD_SAMPLE_DATA="$LOAD_SAMPLE_DATA" USE_LOCAL_SPREE="$use_local_spree" ADMIN_EMAIL="$ADMIN_EMAIL" ADMIN_PASSWORD="$ADMIN_PASSWORD" rails _${RAILS_VERSION}_ new "$APP_NAME" -m "$TEMPLATE_FILE" >/tmp/spree_install.log 2>&1 &+ local rails_pid=$!++ # Show spinner with progress messages+ local elapsed=0+ local spin='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'+ local i=0++ # Hide cursor+ tput civis 2>/dev/null || true++ while kill -0 $rails_pid 2>/dev/null; do+ i=$(( (i+1) %10 ))++ # Change message based on elapsed time+ if [ $elapsed -lt 30 ]; then+ msg="Installing Rails and dependencies"+ elif [ $elapsed -lt 60 ]; then+ msg="Installing Spree gems (this takes a while)"+ elif [ $elapsed -lt 90 ]; then+ msg="Setting up Devise authentication"+ elif [ $elapsed -lt 120 ]; then+ msg="Running Spree generators"+ elif [ $elapsed -lt 150 ]; then+ msg="Configuring payment integrations"+ elif [ $elapsed -lt 180 ]; then+ msg="Setting up database"+ else+ msg="Almost done, finalizing installation"+ fi++ printf "\r${BLUE}${spin:$i:1}${NC} ${msg}... (${elapsed}s)"+ sleep 1+ elapsed=$((elapsed + 1))+ done++ # Show cursor+ tput cnorm 2>/dev/null || true+ printf "\r\033[K" # Clear line++ # Check if rails command succeeded+ wait $rails_pid+ local exit_code=$?++ if [ $exit_code -ne 0 ]; then+ print_error "Spree Commerce application creation failed!"+ echo -e "\n${YELLOW}Error log:${NC}"+ tail -50 /tmp/spree_install.log+ exit 1+ fi++ rm -f /tmp/spree_install.log+ fi++ # Clean up downloaded template if it was downloaded+ if [ -f "$TEMPLATE_FILE" ] && [ "$TEMPLATE_FILE" != "template.rb" ]; then+ rm "$TEMPLATE_FILE"+ fi++ print_success "Spree Commerce application created successfully"+}++# Final instructions+show_final_instructions() {+ print_header+ print_success "Spree Commerce installation completed successfully!"++ echo -e "\n${BOLD}${GREEN}What's next?${NC}\n"++ echo -e "${BOLD}1. Start the development server:${NC}"+ echo -e " ${BLUE}cd $APP_NAME${NC}"+ echo -e " ${BLUE}bin/dev${NC}"++ echo -e "\n${BOLD}2. Access your Spree store:${NC}"+ echo -e " • Storefront: ${BLUE}http://localhost:3000${NC}"+ echo -e " • Admin Panel: ${BLUE}http://localhost:3000/admin${NC}"+ echo -e " • Admin credentials:"+ echo -e " Email: ${BOLD}$ADMIN_EMAIL${NC}"+ echo -e " Password: ${BOLD}$ADMIN_PASSWORD${NC}"++ echo -e "\n${BOLD}3. Useful commands:${NC}"+ echo -e " ${BLUE}bin/rails console${NC} # Rails console"+ if [ "$LOAD_SAMPLE_DATA" = "false" ]; then+ echo -e " ${BLUE}bin/rails spree_sample:load${NC} # Load sample data"+ fi++ echo -e "\n${BOLD}4. Documentation:${NC}"+ echo -e " • Developer Guide: ${BLUE}https://spreecommerce.org/docs/developer${NC}"+ echo -e " • API Documentation: ${BLUE}https://spreecommerce.org/docs/api${NC}"++ echo -e "\n${BOLD}${GREEN}Happy coding with Spree Commerce!${NC}\n"++ # Skip server start prompt if auto-accept is enabled+ if [ "$AUTO_ACCEPT" = true ]; then+ return 0+ fi++ # Ask if user wants to start server now (Y is default)+ read -p "Would you like to start the server now? (Y/n): " -r+ echo++ # Default to yes if empty response+ if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then+ print_info "Starting server... (Press Ctrl+C to stop)"+ cd "$APP_NAME"+ bin/dev+ fi+}++# Main installation flow+main() {+ print_header++ echo -e "This installer will set up Spree Commerce on your system."+ echo -e "It will install the following if needed:"+ echo -e " • System dependencies (libvips for image processing)"+ echo -e " • rbenv (Ruby version manager)"+ echo -e " • Ruby $RUBY_VERSION"+ echo -e " • Rails $RAILS_VERSION"+ echo -e " • Create a new Spree Commerce application"++ if [ "$USE_LOCAL_SPREE" = true ]; then+ echo -e "\n${YELLOW}Using local Spree gems from parent directory${NC}"+ fi++ if [ "$AUTO_ACCEPT" = false ]; then+ press_any_key+ fi++ detect_os+ install_system_deps+ install_ruby+ install_rails+ get_app_name+ ask_sample_data+ ask_admin_credentials+ create_rails_app+ show_final_instructions+}++# Run main installation+maindiff --git a/template.rb b/template.rbnew file mode 100644index 0000000000..128768cd70--- /dev/null+++ b/template.rb@@ -0,0 +1,188 @@+# Spree Commerce Rails Application Template+# This template sets up a new Rails application with Spree Commerce++# Check if verbose mode is enabled via environment variable+VERBOSE = ENV['VERBOSE_MODE'] == '1'+LOAD_SAMPLE_DATA = ENV['LOAD_SAMPLE_DATA'] == 'true'+USE_LOCAL_SPREE = ENV['USE_LOCAL_SPREE'] == 'true'+ADMIN_EMAIL = ENV['ADMIN_EMAIL'] || '[email protected]'+ADMIN_PASSWORD = ENV['ADMIN_PASSWORD'] || 'spree123'++def add_gems+ say 'Adding required gems to Gemfile...', :blue++ # Core dependencies+ gem 'devise'++ # Spree gems - using main branch for latest+ spree_opts = USE_LOCAL_SPREE ? { path: '../' } : { github: 'spree/spree', branch: 'main' }+ gem 'spree', spree_opts+ gem 'spree_emails', spree_opts+ gem 'spree_sample', spree_opts+ gem 'spree_admin', spree_opts+ gem 'spree_storefront', spree_opts+ # translations+ gem 'spree_i18n'++ # Payment & Analytics integrations+ gem 'spree_stripe', github: 'spree/spree_stripe', branch: 'main'+ gem 'spree_google_analytics', github: 'spree/spree_google_analytics', branch: 'main'+ gem 'spree_klaviyo', github: 'spree/spree_klaviyo', branch: 'main'+ gem 'spree_paypal_checkout', github: 'spree/spree_paypal_checkout', branch: 'main'++ # Development & Test gems+ gem_group :development, :test do+ gem 'spree_dev_tools'+ gem 'bullet'+ gem 'pry-byebug'+ gem 'awesome_print'+ gem 'letter_opener'+ gem 'listen'+ end+end++def setup_importmap+ say 'Setting up JavaScript with Importmap...', :blue++ # Rails 8 already has importmap, turbo, and stimulus by default+ # Just ensure they're properly set up by running the install tasks+ # Using system with 'yes' to auto-accept prompts+ if VERBOSE+ system("yes | bin/rails importmap:install")+ system("yes | bin/rails turbo:install")+ system("yes | bin/rails stimulus:install")+ else+ system("yes | bin/rails importmap:install >/dev/null 2>&1")+ system("yes | bin/rails turbo:install >/dev/null 2>&1")+ system("yes | bin/rails stimulus:install >/dev/null 2>&1")+ end+end++def setup_devise+ say 'Setting up Devise authentication...', :blue++ if VERBOSE+ rails_command 'generate devise:install'+ rails_command 'generate devise Spree::User'+ rails_command 'generate devise Spree::AdminUser'+ else+ run 'bin/rails generate devise:install >/dev/null 2>&1'+ run 'bin/rails generate devise Spree::User >/dev/null 2>&1'+ run 'bin/rails generate devise Spree::AdminUser >/dev/null 2>&1'+ end+end++def install_spree+ say 'Running Spree installer...', :blue++ # Run Spree installer with all options+ if VERBOSE+ rails_command "generate spree:install --auto-accept --user_class=Spree::User --admin_user_class=Spree::AdminUser --authentication=devise --install_storefront=true --install_admin=true --admin_email=#{ADMIN_EMAIL} --admin_password=#{ADMIN_PASSWORD}"+ rails_command 'generate spree_stripe:install'+ rails_command 'generate spree_google_analytics:install'+ rails_command 'generate spree_klaviyo:install'+ rails_command 'generate spree_paypal_checkout:install'+ else+ run "bin/rails generate spree:install --auto-accept --user_class=Spree::User --admin_user_class=Spree::AdminUser --authentication=devise --install_storefront=true --install_admin=true --admin_email=#{ADMIN_EMAIL} --admin_password=#{ADMIN_PASSWORD} >/dev/null 2>&1"+ run 'bin/rails generate spree_stripe:install >/dev/null 2>&1'+ run 'bin/rails generate spree_google_analytics:install >/dev/null 2>&1'+ run 'bin/rails generate spree_klaviyo:install >/dev/null 2>&1'+ run 'bin/rails generate spree_paypal_checkout:install >/dev/null 2>&1'+ end+end+++def configure_development_environment+ say 'Configuring development environment...', :blue++ # Bullet configuration+ create_file 'config/initializers/bullet.rb' do+ <<~RUBY+ if Rails.env.development? && defined?(Bullet)+ Bullet.enable = true+ Bullet.rails_logger = true+ Bullet.stacktrace_includes = [ 'spree_core', 'spree_storefront', 'spree_api', 'spree_admin', 'spree_emails' ]+ end+ RUBY+ end++ # Letter opener and file watcher configuration+ inject_into_file 'config/environments/development.rb', before: /^end/ do+ <<-RUBY++ # Letter Opener for email previews+ config.action_mailer.delivery_method = :letter_opener+ config.action_mailer.perform_deliveries = true++ # Improved file watching+ config.file_watcher = ActiveSupport::EventedFileUpdateChecker+ RUBY+ end+end++def setup_procfile+ say 'Setting up Procfile.dev...', :blue++ # Add web server to Procfile.dev+ append_to_file 'Procfile.dev' do+ "\nweb: bin/rails s -p 3000\n"+ end+end++def setup_database+ say 'Setting up database...', :blue++ if VERBOSE+ rails_command 'db:migrate'+ else+ run 'bin/rails db:migrate >/dev/null 2>&1'+ end+end++def load_sample_data+ if LOAD_SAMPLE_DATA+ say 'Loading sample data...', :blue+ if VERBOSE+ rails_command 'spree_sample:load'+ else+ run 'bin/rails spree_sample:load >/dev/null 2>&1'+ end+ end+end++def show_success_message+ say+ say '=' * 60, :green+ say 'Spree Commerce has been successfully installed!', :green+ say '=' * 60, :green+ say+ say 'To start your server:', :yellow+ say ' bin/dev', :bold+ say+ say 'Then visit:', :yellow+ say ' Storefront: http://localhost:3000', :bold+ say ' Admin Panel: http://localhost:3000/admin', :bold+ say+ say 'Admin credentials:', :yellow+ say " Email: #{ADMIN_EMAIL}", :bold+ say " Password: #{ADMIN_PASSWORD}", :bold+ say+ say 'Useful commands:', :yellow+ say ' bin/rails console # Rails console'+ say ' bin/rails spree_sample:load # Load more sample data'+ say+end++# Main template execution+add_gems++after_bundle do+ setup_importmap+ configure_development_environment+ setup_devise+ install_spree+ setup_procfile+ setup_database+ load_sample_data+ show_success_message+end