From 009873aec89a4b843b41accf616b42b7a9917ba8 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 6 Jan 2013 16:13:47 -0700 Subject: Introduce ./bin for your app's executables: bin/bundle, bin/rails, bin/rake. Executable scripts are versioned code like the rest of your app. To generate a stub for a bundled gem: 'bundle binstubs unicorn' and 'git add bin/unicorn' --- railties/lib/rails/generators/actions.rb | 2 +- .../rails/generators/rails/app/app_generator.rb | 22 +++++++++++----------- .../rails/generators/rails/app/templates/README | 11 +++++++---- .../generators/rails/app/templates/bin/bundle | 3 +++ .../rails/generators/rails/app/templates/bin/rails | 3 +++ .../rails/generators/rails/app/templates/bin/rake | 3 +++ .../generators/rails/app/templates/script/rails | 5 ----- .../rails/plugin_new/plugin_new_generator.rb | 14 +++++++------- .../rails/plugin_new/templates/bin/rails.tt | 7 +++++++ .../rails/plugin_new/templates/script/rails.tt | 7 ------- 10 files changed, 42 insertions(+), 35 deletions(-) create mode 100644 railties/lib/rails/generators/rails/app/templates/bin/bundle create mode 100644 railties/lib/rails/generators/rails/app/templates/bin/rails create mode 100644 railties/lib/rails/generators/rails/app/templates/bin/rake delete mode 100644 railties/lib/rails/generators/rails/app/templates/script/rails create mode 100644 railties/lib/rails/generators/rails/plugin_new/templates/bin/rails.tt delete mode 100644 railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt (limited to 'railties/lib/rails/generators') diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index b96ee9295e..71cb0b903b 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -186,7 +186,7 @@ module Rails log :generate, what argument = args.map {|arg| arg.to_s }.flatten.join(" ") - in_root { run_ruby_script("script/rails generate #{what} #{argument}", verbose: false) } + in_root { run_ruby_script("bin/rails generate #{what} #{argument}", verbose: false) } end # Runs the supplied rake task diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 372790df59..7d9044a2b4 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -63,6 +63,13 @@ module Rails keep_file 'app/models/concerns' end + def bin + directory "bin" do |content| + "#{shebang}\n" + content + end + chmod "bin", 0755, verbose: false + end + def config empty_directory "config" @@ -103,13 +110,6 @@ module Rails directory "public", "public", recursive: false end - def script - directory "script" do |content| - "#{shebang}\n" + content - end - chmod "script", 0755, verbose: false - end - def test empty_directory_with_keep_file 'test/fixtures' empty_directory_with_keep_file 'test/controllers' @@ -178,6 +178,10 @@ module Rails build(:app) end + def create_bin_files + build(:bin) + end + def create_config_files build(:config) end @@ -211,10 +215,6 @@ module Rails build(:public_directory) end - def create_script_files - build(:script) - end - def create_test_files build(:test) unless options[:skip_test_unit] end diff --git a/railties/lib/rails/generators/rails/app/templates/README b/railties/lib/rails/generators/rails/app/templates/README index 2bd7c27f2a..e566c01c46 100644 --- a/railties/lib/rails/generators/rails/app/templates/README +++ b/railties/lib/rails/generators/rails/app/templates/README @@ -166,6 +166,7 @@ The default directory structure of a generated Ruby on Rails application: | | `-- concerns | `-- views | `-- layouts + |-- bin |-- config | |-- environments | |-- initializers @@ -177,7 +178,6 @@ The default directory structure of a generated Ruby on Rails application: | `-- tasks |-- log |-- public - |-- script |-- test | |-- controllers | |-- fixtures @@ -226,6 +226,12 @@ app/helpers generated for you automatically when using generators for controllers. Helpers can be used to wrap functionality for your views into methods. +bin + Your app's executables -- bundler, rake, rails, and more -- automatically + run using your app's Ruby version and its bundled gems. When you bundle + a new gem and need to run one of its executables, use `bundle binstubs ` + to add it. For example, `bundle binstubs unicorn` adds ./bin/unicorn. + config Configuration files for the Rails environment, the routing map, the database, and other dependencies. @@ -248,9 +254,6 @@ public default HTML files. This should be set as the DOCUMENT_ROOT of your web server. -script - Helper scripts for automation and generation. - test Unit and functional tests along with fixtures. When using the rails generate command, template test files will be generated for you and placed in this diff --git a/railties/lib/rails/generators/rails/app/templates/bin/bundle b/railties/lib/rails/generators/rails/app/templates/bin/bundle new file mode 100644 index 0000000000..e0df7f4440 --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/bin/bundle @@ -0,0 +1,3 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +require 'rubygems' +load Gem.bin_path('bundler', 'bundle') diff --git a/railties/lib/rails/generators/rails/app/templates/bin/rails b/railties/lib/rails/generators/rails/app/templates/bin/rails new file mode 100644 index 0000000000..6a128b95e5 --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/bin/rails @@ -0,0 +1,3 @@ +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/railties/lib/rails/generators/rails/app/templates/bin/rake b/railties/lib/rails/generators/rails/app/templates/bin/rake new file mode 100644 index 0000000000..d14fc8395b --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/bin/rake @@ -0,0 +1,3 @@ +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/railties/lib/rails/generators/rails/app/templates/script/rails b/railties/lib/rails/generators/rails/app/templates/script/rails deleted file mode 100644 index 11bc1edde9..0000000000 --- a/railties/lib/rails/generators/rails/app/templates/script/rails +++ /dev/null @@ -1,5 +0,0 @@ -# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. - -APP_PATH = File.expand_path('../../config/application', __FILE__) -require File.expand_path('../../config/boot', __FILE__) -require 'rails/commands' diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index cd756a729d..af00748037 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -130,13 +130,13 @@ task default: :test end end - def script(force = false) + def bin(force = false) return unless engine? - directory "script", force: force do |content| + directory "bin", force: force do |content| "#{shebang}\n" + content end - chmod "script", 0755, verbose: false + chmod "bin", 0755, verbose: false end def gemfile_entry @@ -214,8 +214,8 @@ task default: :test build(:images) end - def create_script_files - build(:script) + def create_bin_files + build(:bin) end def create_test_files @@ -264,8 +264,8 @@ task default: :test store_application_definition! build(:test_dummy_config) build(:test_dummy_clean) - # ensure that script/rails has proper dummy_path - build(:script, true) + # ensure that bin/rails has proper dummy_path + build(:bin, true) end end diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/bin/rails.tt b/railties/lib/rails/generators/rails/plugin_new/templates/bin/rails.tt new file mode 100644 index 0000000000..aa87d1b50c --- /dev/null +++ b/railties/lib/rails/generators/rails/plugin_new/templates/bin/rails.tt @@ -0,0 +1,7 @@ +# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. + +ENGINE_ROOT = File.expand_path('../..', __FILE__) +ENGINE_PATH = File.expand_path('../../lib/<%= name -%>/engine', __FILE__) + +require 'rails/all' +require 'rails/engine/commands' diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt b/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt deleted file mode 100644 index aa87d1b50c..0000000000 --- a/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +++ /dev/null @@ -1,7 +0,0 @@ -# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. - -ENGINE_ROOT = File.expand_path('../..', __FILE__) -ENGINE_PATH = File.expand_path('../../lib/<%= name -%>/engine', __FILE__) - -require 'rails/all' -require 'rails/engine/commands' -- cgit v1.2.3