-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
local
executable file
·53 lines (41 loc) · 1.32 KB
/
local
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
#!/usr/bin/env ruby
require 'shellwords'
require File.expand_path('../../spec/support/detect_rails_version', __FILE__)
unless ARGV[0]
puts <<-EOF
Usage: ./script/#{__FILE__} COMMAND [ARGS]
The command will be run in the context of the local rails
app stored in test-rails-app.
Examples:
./script/local server
./script/local c
./script/local rake db:migrate
EOF
exit(1)
end
# Set up some variables
rails_version = detect_rails_version!
dir = ".test-rails-apps"
path = "#{dir}/test-rails-app-#{rails_version}"
# Ensure .test-rails-apps is created
system "mkdir #{dir}" unless File.exists?(dir)
# Create the sample rails app if it doesn't already exist
unless File.exists? path
args = %w[
-m\ spec/support/rails_template_with_data.rb
--skip-gemfile
--skip-bundle
--skip-git
--skip-turbolinks
--skip-test-unit
]
system "RAILS='#{rails_version}' bundle exec rails new #{Shellwords.escape path} #{args.join ' '}"
end
# Link this rails app
system "rm test-rails-app"
system "ln -s #{Shellwords.escape path} test-rails-app"
# If it's a rails command, auto add the rails script
RAILS_COMMANDS = %w{generate console server dbconsole g c s runner}
args = RAILS_COMMANDS.include?(ARGV[0]) ? ["rails", ARGV].flatten : ARGV
# Run the command
exec "cd test-rails-app && GEMFILE=../Gemfile bundle exec #{args.join(" ")}"