Skip to content

Commit 840138f

Browse files
Update sandbox script
The previous Sandbox script was failing with `rails: command not found`. This script was pulled from Solidus Storefront.
1 parent f752af7 commit 840138f

1 file changed

Lines changed: 76 additions & 33 deletions

File tree

β€Žbin/sandboxβ€Ž

Lines changed: 76 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,104 @@
11
#!/usr/bin/env bash
22

33
set -e
4+
test -z "${DEBUG+empty_string}" || set -x
45

5-
case "$DB" in
6-
postgres|postgresql)
7-
RAILSDB="postgresql"
8-
;;
9-
mysql)
10-
RAILSDB="mysql"
11-
;;
12-
sqlite|'')
13-
RAILSDB="sqlite3"
14-
;;
15-
*)
16-
echo "Invalid DB specified: $DB"
17-
exit 1
18-
;;
19-
esac
6+
test "$DB" = "sqlite" && export DB="sqlite3"
207

21-
if [ ! -z $SOLIDUS_BRANCH ]
8+
if [ -z "$PAYMENT_METHOD" ]
229
then
23-
BRANCH=$SOLIDUS_BRANCH
24-
else
25-
BRANCH="main"
10+
PAYMENT_METHOD="none"
2611
fi
2712

28-
extension_name="solidus_paypal_commerce_platform"
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"
2919

3020
# Stay away from the bundler env of the containing extension.
3121
function unbundled {
32-
ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- "$@"
22+
ruby -rbundler -e'
23+
Bundler.with_unbundled_env {system *ARGV}' -- \
24+
env BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES=true $@
3325
}
3426

27+
echo "~~~> Removing the old sandbox"
3528
rm -rf ./sandbox
36-
rails new sandbox \
37-
--database="$RAILSDB" \
29+
30+
echo "~~~> Creating a pristine Rails app"
31+
rails_version=`bundle exec ruby -e'require "rails"; puts Rails.version'`
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}" \
3843
--skip-git \
3944
--skip-keeps \
4045
--skip-rc \
4146
--skip-bootsnap \
42-
--skip-test
47+
--skip-test \
48+
$skip_solid_flag
4349

4450
if [ ! -d "sandbox" ]; then
4551
echo 'sandbox rails application failed'
4652
exit 1
4753
fi
4854

55+
echo "~~~> Adding solidus (with i18n) to the Gemfile"
4956
cd ./sandbox
50-
unbundled bundle add solidus --github solidusio/solidus --branch "${BRANCH:-main}" --version '> 0.a'
57+
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
83+
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
91+
92+
unbundled bundle install --gemfile Gemfile
93+
5194
unbundled bundle exec rake db:drop db:create
52-
unbundled bundle exec rails generate solidus:install --payment-method=none --auto-accept "$@"
53-
unbundled bundle add ${extension_name} --path '../'
54-
unbundled bundle exec rails generate ${extension_name}:install --frontend=starter --migrate=true
95+
96+
export FRONTEND="$PWD/../template.rb"
97+
unbundled bundle exec rails generate solidus:install \
98+
--auto-accept \
99+
$@
55100

56101
echo
57-
echo "πŸš€ Sandbox app successfully created for ${extension_name}!"
58-
echo "πŸš€ Using $RAILSDB and Solidus $BRANCH"
59-
echo "πŸš€ Use 'export DB=[postgres|mysql|sqlite]' to control the DB adapter"
60-
echo "πŸš€ Use 'export SOLIDUS_BRANCH=<BRANCH-NAME>' to control the Solidus version"
61-
echo "πŸš€ This app is intended for test purposes."
102+
echo "πŸš€ Sandbox app successfully created for the storefront!"
103+
echo "πŸš€ Use 'export DB=[postgres|mysql|sqlite3]' to control the DB adapter"
104+
echo "πŸ§ͺ This app is intended for test purposes."

0 commit comments

Comments
Β (0)