-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
sandbox
executable file
路104 lines (89 loc) 路 2.42 KB
/
sandbox
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
# Used in the sandbox rake task in Rakefile
set -e
test -z "${DEBUG+empty_string}" || set -x
case "$DB" in
postgres|postgresql)
RAILSDB="postgresql"
HOST=${DB_POSTGRES_HOST:-${DB_HOST}}
USERNAME=$DB_USERNAME
PASSWORD=$DB_PASSWORD
;;
mysql)
RAILSDB="mysql"
HOST=${DB_MYSQL_HOST:-${DB_HOST}}
USERNAME=$DB_USERNAME
PASSWORD=$DB_PASSWORD
;;
sqlite|'')
RAILSDB="sqlite3"
;;
*)
echo "Invalid DB specified: $DB"
exit 1
;;
esac
# Stay away from the bundler env of the containing extension.
# # The unbundled helper requires Bundler 2.1 or above
function unbundled {
ruby -rbundler -e'
Gem::Version.new(Bundler::VERSION) < Gem::Version.new("2.1") ?
abort("The sandbox requires at least Bundler 2.1, please run bin/setup to update it.") :
Bundler.with_unbundled_env {system *ARGV}' -- \
env BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES=true $@
}
echo "~~~> Removing the old sandbox"
rm -rf ./sandbox
echo "~~~> Creating a pristine Rails app"
rails new sandbox \
--database="$RAILSDB" \
--skip-git \
--skip-keeps \
--skip-rc \
--skip-bootsnap \
--skip-test
if [ ! -d "sandbox" ]; then
echo 'sandbox rails application failed'
exit 1
fi
echo "~~~> Adding solidus (with i18n) to the Gemfile"
cd ./sandbox
cat <<RUBY >> Gemfile
gem 'solidus', path: '..'
gem 'solidus_admin', path: '../admin'
gem 'rails-i18n'
gem 'solidus_i18n'
group :test, :development do
platforms :mri do
gem 'pry-byebug'
end
end
RUBY
unbundled bundle install --gemfile Gemfile
replace_in_database_yml() {
if [ $RAILSDB = "postgresql" ]; then
sed -i.bck "/^ adapter:/a \ \ $1: $2" config/database.yml
elif [ $RAILSDB = "mysql" ]; then
sed -i.bck "s/^ $1:.*/\ \ $1: $2/" config/database.yml
fi
if [ -f config/database.yml.bck ]; then
rm -f config/database.yml.bck
fi
}
if [ ${HOST} ]; then
replace_in_database_yml "host" $HOST
fi
if [ ${USERNAME} ]; then
replace_in_database_yml "username" $USERNAME
fi
if [ ${PASSWORD} ]; then
replace_in_database_yml "password" $PASSWORD
fi
unbundled bin/rails db:drop db:create
echo "~~~> Running the solidus:install generator"
export SOLIDUS_ADMIN_LOOKBOOK=true
unbundled bin/rails generate solidus:install --admin-preview --auto-accept $@
echo "
馃殌 This app is intended for test purposes. If you're interested in running
馃殌 Solidus in production, visit:
馃殌 https://guides.solidus.io/developers/getting-started/first-time-installation"