add `bundle install` to `jekyll new`

- automatically run `bundle install` from within the newly generated blog
   directory by default.
 - add a new switch to skip this default behaviour.
This commit is contained in:
Ashwin Maroli 2016-08-12 07:40:05 +05:30
parent 55de780520
commit 566b42b8b3
1 changed files with 23 additions and 1 deletions

View File

@ -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