diff --git a/Rakefile b/Rakefile index 494e284beb..6d8bd6c2bf 100644 --- a/Rakefile +++ b/Rakefile @@ -39,16 +39,17 @@ namespace :alchemy do namespace :spec do desc "Prepares database for testing Alchemy" task :prepare do - result = system <<~BASH - cd spec/dummy && \ - export RAILS_ENV=test && \ - bin/rake db:create && \ - bin/rake db:environment:set && \ - bin/rake db:migrate:reset && \ - bin/rails g alchemy:install --skip --skip-demo-files && \ - cd - - BASH - result || fail + system( + <<~BASH + cd spec/dummy && \ + export RAILS_ENV=test && \ + bin/rake db:create && \ + bin/rake db:environment:set && \ + bin/rake db:migrate:reset && \ + bin/rails g alchemy:install --skip --skip-demo-files --auto-accept && \ + cd - + BASH + ) || fail end end diff --git a/lib/alchemy/install/tasks.rb b/lib/alchemy/install/tasks.rb index 584fccdf91..4c584667f9 100644 --- a/lib/alchemy/install/tasks.rb +++ b/lib/alchemy/install/tasks.rb @@ -7,18 +7,24 @@ class Tasks < Thor include Thor::Actions no_tasks do - def inject_routes - mountpoint = ask "- At which path do you want to mount Alchemy CMS at? (DEFAULT: At root path '/')" - mountpoint = "/" if mountpoint.empty? + def inject_routes(auto_accept = false) + mountpoint = "/" + unless auto_accept + mountpoint = ask("- At which path do you want to mount Alchemy CMS at?", default: mountpoint) + end sentinel = /\.routes\.draw do(?:\s*\|map\|)?\s*$/ inject_into_file "./config/routes.rb", "\n mount Alchemy::Engine => '#{mountpoint}'\n", { after: sentinel, verbose: true } end - def set_primary_language - code = ask "- What is the language code of your site's primary language? (DEFAULT: en)" - code = "en" if code.empty? - name = ask "- What is the name of your site's primary language? (DEFAULT: English)" - name = "English" if name.empty? + def set_primary_language(auto_accept = false) + code = "en" + unless auto_accept + code = ask("- What is the language code of your site's primary language?", default: code) + end + name = "English" + unless auto_accept + name = ask("- What is the name of your site's primary language?", default: name) + end gsub_file "./config/alchemy/config.yml", /default_language:\n\s\scode:\sen\n\s\sname:\sEnglish/m do "default_language:\n code: #{code}\n name: #{name}" end diff --git a/lib/generators/alchemy/install/install_generator.rb b/lib/generators/alchemy/install/install_generator.rb index 05afd1c460..6eb640de3e 100644 --- a/lib/generators/alchemy/install/install_generator.rb +++ b/lib/generators/alchemy/install/install_generator.rb @@ -7,6 +7,11 @@ module Generators class InstallGenerator < ::Rails::Generators::Base desc "Installs Alchemy into your App." + class_option :auto_accept, + type: :boolean, + default: false, + desc: "Automatically accept defaults." + class_option :skip_demo_files, type: :boolean, default: false, @@ -23,7 +28,7 @@ def setup header say "Welcome to AlchemyCMS!" say "Let's begin with some questions.\n\n" - install_tasks.inject_routes + install_tasks.inject_routes(options[:auto_accept]) end def copy_config @@ -61,7 +66,11 @@ def copy_demo_views end def copy_dragonfly_config - template "#{__dir__}/templates/dragonfly.rb.tt", app_config_path.join("initializers", "dragonfly.rb") + template( + "#{__dir__}/templates/dragonfly.rb.tt", + app_config_path.join("initializers", "dragonfly.rb"), + skip: options[:auto_accept] + ) end def install_gutentag_migrations @@ -90,7 +99,7 @@ def copy_alchemy_entry_point def set_primary_language header - install_tasks.set_primary_language + install_tasks.set_primary_language(options[:auto_accept]) end def setup_database @@ -115,12 +124,16 @@ def finalize private def header + return if options[:auto_accept] + puts "─────────────────────" puts "* Alchemy Installer *" puts "─────────────────────" end def say(something) + return if options[:auto_accept] + puts " #{something}" end