Skip to content

Commit

Permalink
Add --auto-accept option to installer
Browse files Browse the repository at this point in the history
Great for CIs
  • Loading branch information
tvdeyen committed Jul 11, 2020
1 parent 5bf1900 commit 8af3e09
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
21 changes: 11 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 14 additions & 8 deletions lib/alchemy/install/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 16 additions & 3 deletions lib/generators/alchemy/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 8af3e09

Please sign in to comment.