|
1 | 1 | #!/usr/bin/env ruby
|
2 |
| -# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. |
3 | 2 |
|
4 |
| -ENGINE_PATH = File.expand_path('../..', __FILE__) |
5 |
| -load File.expand_path('../../test/dummy/script/rails', __FILE__) |
| 3 | +#This is standard Rails 4 Engine commands behavior. |
| 4 | +ENGINE_ROOT = File.expand_path('../..', __FILE__) |
| 5 | +ENGINE_PATH = File.expand_path('../../lib/cms/engine', __FILE__) |
6 | 6 |
|
| 7 | +# Modified the core `rails` script so that commands other than generate/destroy work in context of the test/dummy app. |
7 | 8 |
|
8 |
| -# Rails 3.2.2 generates the following instead, but you only get access to: |
9 |
| -# - rails generate |
10 |
| -# - rails destroy |
11 |
| -# I kept the above (for now anyway) so I can get access to rails server, though I will need to test that it works for other commands too. |
| 9 | +ARGV << '--help' if ARGV.empty? |
12 | 10 |
|
13 |
| -# Bugs: Adding the following would: |
14 |
| -# 1. Enable generators to work correctly (right now they put code into test/dummy) |
15 |
| -# 2. Prevent loading, since engine requires other files directly. |
| 11 | +aliases = { |
| 12 | + "g" => "generate", |
| 13 | + "d" => "destroy" |
| 14 | +} |
16 | 15 |
|
17 |
| -#ENGINE_ROOT = File.expand_path('../..', __FILE__) |
18 |
| -#ENGINE_PATH = File.expand_path('../../lib/cms/engine', __FILE__) |
19 |
| -## |
20 |
| -#require 'rails/all' |
21 |
| -#require 'rails/engine/commands' |
| 16 | +command = ARGV.first |
| 17 | +command = aliases[command] || command |
| 18 | + |
| 19 | +case command |
| 20 | + when 'generate', 'destroy' |
| 21 | + require 'rails/all' |
| 22 | + require 'rails/engine/commands' |
| 23 | + else |
| 24 | + # Commands like 'server' and 'console' will use test/dummy's rails script. |
| 25 | + load File.expand_path('../../test/dummy/script/rails', __FILE__) |
| 26 | + |
| 27 | +end |
0 commit comments