diff --git a/lib/jekyll/commands/new.rb b/lib/jekyll/commands/new.rb index 90e35fee..c8569164 100644 --- a/lib/jekyll/commands/new.rb +++ b/lib/jekyll/commands/new.rb @@ -11,6 +11,7 @@ module Jekyll c.option "force", "--force", "Force creation even if PATH already exists" c.option "blank", "--blank", "Creates scaffolding but with empty files" + c.option "skip-bundle", "--skip-bundle", "Skip 'bundle install'" c.action do |args, options| Jekyll::Commands::New.process(args, options) @@ -34,7 +35,7 @@ module Jekyll create_site new_blog_path end - Jekyll.logger.info "New jekyll site installed in #{new_blog_path.cyan}." + after_install(new_blog_path, options) end def create_blank_site(path) @@ -114,6 +115,27 @@ RUBY def scaffold_path "_posts/0000-00-00-welcome-to-jekyll.markdown.erb" end + + # After a new blog has been created, print a success notification and + # then automatically execute bundle install from within the new blog dir + # unless the user opts to generate a blank blog or skip 'bundle install'. + + def after_install(path, options = {}) + Jekyll.logger.info "New jekyll site installed in #{path.cyan}." + Jekyll.logger.info "Bundle install skipped." if options["skip-bundle"] + + unless options["blank"] || options["skip-bundle"] + bundle_install path + end + end + + def bundle_install(path) + Jekyll::External.require_with_graceful_fail "bundler" + Jekyll.logger.info "Running bundle install in #{path.cyan}..." + Dir.chdir(path) do + system("bundle", "install") + end + end end end end diff --git a/test/test_new_command.rb b/test/test_new_command.rb index aea7dd4c..982de1da 100644 --- a/test/test_new_command.rb +++ b/test/test_new_command.rb @@ -40,9 +40,12 @@ class TestNewCommand < JekyllUnitTest should "display a success message" do Jekyll::Commands::New.process(@args) - output = Jekyll.logger.messages.last + output = Jekyll.logger.messages[-3] + output_last = Jekyll.logger.messages.last success_message = "New jekyll site installed in #{@full_path.cyan}." + bundle_message = "Running bundle install in #{@full_path.cyan}..." assert_includes output, success_message + assert_includes output_last, bundle_message end should "copy the static files in site template to the new directory" do @@ -85,7 +88,10 @@ class TestNewCommand < JekyllUnitTest should "create blank project" do blank_contents = %w(/_drafts /_layouts /_posts /index.html) capture_stdout { Jekyll::Commands::New.process(@args, "--blank") } + output = Jekyll.logger.messages.last + bundle_message = "Running bundle install in #{@full_path.cyan}..." assert_same_elements blank_contents, dir_contents(@full_path) + refute_includes output, bundle_message end should "force created folder" do @@ -93,6 +99,13 @@ class TestNewCommand < JekyllUnitTest output = capture_stdout { Jekyll::Commands::New.process(@args, "--force") } assert_match(%r!New jekyll site installed in!, output) end + + should "skip bundle install when opted to" do + capture_stdout { Jekyll::Commands::New.process(@args, "--skip-bundle") } + output = Jekyll.logger.messages.last + bundle_message = "Bundle install skipped." + assert_includes output, bundle_message + end end context "when multiple args are given" do