|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
3 | 3 | set -e |
4 | | -set -x |
| 4 | +test -z "${DEBUG+empty_string}" || set -x |
5 | 5 |
|
6 | | -replace_in_database_yml() { |
7 | | - if [[ "$DB" == "postgresql" ]]; then |
8 | | - sed -i.bck "/^ adapter:/a \ \ $1: $2" config/database.yml |
9 | | - elif [[ "$DB" == "mysql" ]]; then |
10 | | - sed -i.bck "s/^ $1:.*/\ \ $1: $2/" config/database.yml |
11 | | - fi |
| 6 | +test "$DB" = "sqlite" && export DB="sqlite3" |
12 | 7 |
|
13 | | - test -f config/database.yml.bck && rm -f config/database.yml.bck |
14 | | -} |
| 8 | +if [ -z "$PAYMENT_METHOD" ] |
| 9 | +then |
| 10 | + PAYMENT_METHOD="none" |
| 11 | +fi |
| 12 | + |
| 13 | +if [ -z "$SOLIDUS_BRANCH" ] |
| 14 | +then |
| 15 | + echo "~~> Use 'export SOLIDUS_BRANCH=[main|v4.0|...]' to control the Solidus branch" |
| 16 | + SOLIDUS_BRANCH="main" |
| 17 | +fi |
| 18 | +echo "~~> Using branch $SOLIDUS_BRANCH of solidus" |
15 | 19 |
|
16 | 20 | # Stay away from the bundler env of the containing extension. |
17 | 21 | function unbundled { |
18 | | - set +x |
19 | | - ruby -rbundler -e'Bundler.with_unbundled_env { system *ARGV }' -- "$@" |
| 22 | + ruby -rbundler -e' |
| 23 | + Bundler.with_unbundled_env {system *ARGV}' -- \ |
| 24 | + env BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES=true $@ |
20 | 25 | } |
21 | 26 |
|
22 | | -# "sqlite" is set by the ORB extension instead of "sqlite3", |
23 | | -# all other options are already in the format expected by `rails new`. |
24 | | -test "$DB" = "sqlite" && export DB="sqlite3" |
25 | | - |
26 | | -# Remove some noise generated by bundler |
27 | | -export BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES=true |
28 | | - |
| 27 | +echo "~~~> Removing the old sandbox" |
29 | 28 | rm -rf ./sandbox |
| 29 | + |
| 30 | +echo "~~~> Creating a pristine Rails app" |
30 | 31 | rails_version=`bundle exec ruby -e'require "rails"; puts Rails.version'` |
31 | | -rails _${rails_version}_ new sandbox \ |
| 32 | + |
| 33 | +# --skip-solid was added in Rails 8.0 to skip Solid Cache, Queue, and Cable |
| 34 | +# setup which is unnecessary for the sandbox and fails during generation. |
| 35 | +rails_major=$(echo "$rails_version" | cut -d. -f1) |
| 36 | +skip_solid_flag="" |
| 37 | +if [ "$rails_major" -ge 8 ] 2>/dev/null; then |
| 38 | + skip_solid_flag="--skip-solid" |
| 39 | +fi |
| 40 | + |
| 41 | +bundle exec rails _${rails_version}_ new sandbox \ |
| 42 | + --database="${DB:-sqlite3}" \ |
32 | 43 | --skip-git \ |
33 | | - --database=${DB:-sqlite3} \ |
34 | | - --skip-rc |
| 44 | + --skip-keeps \ |
| 45 | + --skip-rc \ |
| 46 | + --skip-bootsnap \ |
| 47 | + --skip-test \ |
| 48 | + $skip_solid_flag |
35 | 49 |
|
36 | 50 | if [ ! -d "sandbox" ]; then |
37 | 51 | echo 'sandbox rails application failed' |
38 | 52 | exit 1 |
39 | 53 | fi |
40 | 54 |
|
| 55 | +echo "~~~> Adding solidus (with i18n) to the Gemfile" |
41 | 56 | cd ./sandbox |
42 | 57 |
|
43 | | -# Coverage |
44 | | -echo "require_relative '../../coverage.rb' if ENV['COVERAGE']" >> config/boot.rb |
45 | | -echo "gem 'rspec_junit_formatter', require: false" >> Gemfile |
46 | | -echo "gem 'simplecov', '~> 0.22', require: false" >> Gemfile |
47 | | -echo "gem 'simplecov-cobertura', require: false" >> Gemfile |
48 | | -unbundled bundle install |
| 58 | +if [ -n "$DB_HOST" ]; then |
| 59 | + echo "~~~> Configuring database.yml for DB_HOST=$DB_HOST" |
| 60 | + ruby -i -pe ' |
| 61 | + if $_ =~ /^ pool:/ |
| 62 | + $_ += " host: <%= ENV.fetch(\"DB_HOST\", \"localhost\") %>\n" |
| 63 | + $_ += " username: <%= ENV[\"DB_USERNAME\"] %>\n" |
| 64 | + end |
| 65 | + ' config/database.yml |
| 66 | +fi |
| 67 | + |
| 68 | +cat <<RUBY >> Gemfile |
| 69 | +gem 'solidus', github: 'solidusio/solidus', branch: '$SOLIDUS_BRANCH' |
| 70 | +gem 'rails-i18n' |
| 71 | +gem 'solidus_i18n' |
| 72 | +gem 'solidus_auth_devise', github: "solidusio/solidus_auth_devise" |
| 73 | +
|
| 74 | +# Ruby 4.0 removed benchmark from default gems, but ActiveSupport requires it. |
| 75 | +gem 'benchmark' if RUBY_VERSION >= '4.0' |
| 76 | +
|
| 77 | +group :test, :development do |
| 78 | + platforms :mri do |
| 79 | + gem 'pry-byebug' |
| 80 | + end |
| 81 | +end |
| 82 | +RUBY |
49 | 83 |
|
50 | | -test -n "${host}" && replace_in_database_yml "host" "${host}" |
51 | | -test -n "${username}" && replace_in_database_yml "username" "${username}" |
52 | | -test -n "${password}" && replace_in_database_yml "password" "${password}" |
| 84 | +echo "Generating manifest file" |
| 85 | +mkdir -p app/assets/config |
| 86 | +cat <<MANIFESTJS > app/assets/config/manifest.js |
| 87 | +//= link_tree ../images |
| 88 | +//= link_directory ../javascripts .js |
| 89 | +//= link_directory ../stylesheets .css |
| 90 | +MANIFESTJS |
53 | 91 |
|
54 | | -unbundled bundle add solidus \ |
55 | | - --github "${SOLIDUS_REPO:-solidusio/solidus}" \ |
56 | | - --branch "${SOLIDUS_BRANCH:-main}" \ |
57 | | - --version '> 0.a' |
| 92 | +unbundled bundle install --gemfile Gemfile |
58 | 93 |
|
59 | 94 | unbundled bundle exec rake db:drop db:create |
60 | 95 |
|
61 | 96 | export FRONTEND="$PWD/../template.rb" |
62 | | -unbundled bundle exec rails generate solidus:install --auto-accept "$@" |
| 97 | +unbundled bundle exec rails generate solidus:install \ |
| 98 | + --auto-accept \ |
| 99 | + $@ |
63 | 100 |
|
64 | 101 | echo |
65 | 102 | echo "🚀 Sandbox app successfully created for the starter frontend!" |
66 | 103 | echo "🚀 Use 'export DB=[postgres|mysql|sqlite3]' to control the DB adapter" |
67 | | -echo "🚀 This app is intended for test purposes." |
| 104 | +echo "🧪 This app is intended for test purposes." |
0 commit comments