run bundle install after the creation of a site (add the skip_bundle option to bypass it)

did committed Jan 14, 2014
commit 827e78588a42e0aeb4cdec7b0cf47baaeb356b66
Showing 9 changed files with 61 additions and 14 deletions
locomotive/wagon.rb b/lib/locomotive/wagon.rb +4 -3
@@ @@ -9,11 +9,12 @@ module Locomotive
#
# @param [ String ] name The name of the site (underscored)
# @param [ String ] path The destination path of the site
+ # @param [ Boolean ] skip_bundle Do not run bundle install
# @param [ Object ] generator The wrapping class of the generator itself
# @param [ String ] options Options for the generator (ex: --force_haml)
#
- def self.init(name, path, generator, options)
- generator.klass.start [name, path, options]
+ def self.init(name, path, skip_bundle, generator, options)
+ generator.klass.start [name, path, skip_bundle, options]
end
# Start the thin server which serves the LocomotiveCMS site from the system.
@@ @@ -127,7 +128,7 @@ module Locomotive
# generate an almost blank site
require 'locomotive/wagon/generators/site'
generator = Locomotive::Wagon::Generators::Site::Cloned
- generator.start [name, path, connection_info.symbolize_keys]
+ generator.start [name, path, true, connection_info.symbolize_keys]
# pull the remote site
self.pull(target_path, options.merge(connection_info).with_indifferent_access, { disable_misc: true })
locomotive/wagon/cli.rb b/lib/locomotive/wagon/cli.rb +15 -7
@@ @@ -131,9 +131,10 @@ module Locomotive
end
desc 'init NAME [PATH] [OPTIONS]', 'Create a brand new LocomotiveCMS site'
- method_option :template, aliases: '-t', type: 'string', default: 'blank', desc: 'instead of building from a blank site, you can have a pre-fetched site with form a template (see the templates command)'
- method_option :lib, aliases: '-l', type: 'string', desc: 'Path to an external ruby lib or generator'
- method_option :verbose, aliases: '-v', type: 'boolean', default: false, desc: 'display the full error stack trace if an error occurs'
+ method_option :template, aliases: '-t', type: 'string', default: 'blank', desc: 'instead of building from a blank site, you can have a pre-fetched site with form a template (see the templates command)'
+ method_option :lib, aliases: '-l', type: 'string', desc: 'Path to an external ruby lib or generator'
+ method_option :skip_bundle, type: 'boolean', default: false, desc: "Don't run bundle install"
+ method_option :verbose, aliases: '-v', type: 'boolean', default: false, desc: 'display the full error stack trace if an error occurs'
def init(name, path = '.', generator_options = nil)
force_color_if_asked(options)
require 'locomotive/wagon/generators/site'
@@ @@ -143,8 +144,8 @@ module Locomotive
say "Unknown site template '#{options[:template]}'", :red
else
begin
- if Locomotive::Wagon.init(name, path, generator, generator_options)
- self.print_next_instructions_when_site_created(name, path)
+ if Locomotive::Wagon.init(name, path, options[:skip_bundle], generator, generator_options)
+ self.print_next_instructions_when_site_created(name, path, options[:skip_bundle])
end
rescue GeneratorException => e
self.print_exception(e, options[:verbose])
@@ @@ -176,6 +177,7 @@ module Locomotive
method_option :lib, aliases: '-l', type: 'string', desc: 'Path to an external ruby lib or generator'
method_option :json, aliases: '-j', type: :boolean, default: false, desc: 'Output the list in JSON'
def list_templates
+ puts Gem.ruby
force_color_if_asked(options)
require 'locomotive/wagon/generators/site'
require File.expand_path(options[:lib]) if options[:lib]
@@ @@ -260,11 +262,17 @@ module Locomotive
#
# @param [ String ] name The name of the site
# @param [ String ] path The path of the local site
+ # @param [ Boolean ] skip_bundle Do not run bundle install
#
- def print_next_instructions_when_site_created(name, path)
+ def print_next_instructions_when_site_created(name, path, skip_bundle)
say "\nCongratulations, your site \"#{name}\" has been created successfully !", :green
say 'Next steps:', :bold
- say "\tcd #{path}/#{name}\n\tbundle install\n\tbundle exec wagon serve\n\topen http://0.0.0.0:3333"
+
+ next_intructions = "\tcd #{path}/#{name}\n\t"
+ next_instructions += "bundle install\n\t" if skip_bundle
+ next_instructions += "bundle exec wagon serve\n\topen http://0.0.0.0:3333"
+
+ say next_instructions
end
# Print the exception.
locomotive/wagon/generators/site/base.rb b/lib/locomotive/wagon/generators/site/base.rb +17 -4
@@ @@ -13,6 +13,7 @@ module Locomotive
argument :name
argument :target_path
+ argument :skip_bundle
def copy_sources
directory('.', self.destination, { recursive: true }, {
@@ @@ -25,16 +26,16 @@ module Locomotive
File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'generators', self.name.demodulize.underscore)
end
- def destination
- File.join(target_path, name)
- end
-
def self.may_use_haml
class_option :haml, type: :boolean, default: nil, required: false, desc: 'HAML over HTML?'
end
protected
+ def destination
+ File.join(target_path, name)
+ end
+
def haml?
if options[:haml].nil?
yes?('Do you prefer HAML templates ?')
@@ @@ -43,6 +44,18 @@ module Locomotive
end
end
+ def bundle_install
+ return if skip_bundle
+
+ FileUtils.cd self.destination
+
+ say_status :run, "bundle install"
+
+ ENV['BUNDLE_GEMFILE'] = nil
+
+ print `"#{Gem.ruby}" -rubygems "#{Gem.bin_path('bundler', 'bundle')}" install`
+ end
+
end
end
locomotive/wagon/generators/site/blank.rb b/lib/locomotive/wagon/generators/site/blank.rb +5 -0
@@ @@ -16,6 +16,11 @@ module Locomotive
remove_file File.join(self.destination, 'app/views/pages/404.liquid.haml')
end
end
+
+ def bundle_install
+ super
+ end
+
end
Locomotive::Wagon::Generators::Site.register(:blank, Blank, %{
locomotive/wagon/generators/site/bootstrap2.rb b/lib/locomotive/wagon/generators/site/bootstrap2.rb +4 -0
@@ @@ -19,6 +19,10 @@ module Locomotive
end
end
+ def bundle_install
+ super
+ end
+
end
Locomotive::Wagon::Generators::Site.register(:bootstrap2, Bootstrap2, %{
locomotive/wagon/generators/site/bootstrap3.rb b/lib/locomotive/wagon/generators/site/bootstrap3.rb +4 -0
@@ @@ -19,6 +19,10 @@ module Locomotive
end
end
+ def bundle_install
+ super
+ end
+
end
Locomotive::Wagon::Generators::Site.register(:bootstrap3, Bootstrap3, %{
locomotive/wagon/generators/site/cloned.rb b/lib/locomotive/wagon/generators/site/cloned.rb +4 -0
@@ @@ -16,6 +16,10 @@ module Locomotive
}.merge(self.connection_info))
end
+ def bundle_install
+ super
+ end
+
end
end
end
locomotive/wagon/generators/site/foundation.rb b/lib/locomotive/wagon/generators/site/foundation.rb +4 -0
@@ @@ -19,6 +19,10 @@ module Locomotive
end
end
+ def bundle_install
+ super
+ end
+
end
Locomotive::Wagon::Generators::Site.register(:foundation, Foundation, %{
locomotive/wagon/generators/site/unzip.rb b/lib/locomotive/wagon/generators/site/unzip.rb +4 -0
@@ @@ -59,6 +59,10 @@ module Locomotive
directory('.', self.destination, { recursive: true })
end
+ def bundle_install
+ super
+ end
+
def self.source_root
# only way to change the source root from the instance
@@source_root