Class: Mimas::Plugins::Rails::Commands::Init

Inherits:
CLI::Commands::BaseCommand
  • Object
show all
Defined in:
lib/mimas/plugins/rails/commands/init.rb

Instance Method Summary collapse

Instance Method Details

#callObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mimas/plugins/rails/commands/init.rb', line 8

def call
  say "Initialising Mimas. We need some information about your site."
  say ""

  say "Your site's domain will be the containing folder on the server."
  domain        = ask "What is your site's domain name?"
  ip            = ask "What is your production server's IP address?"

  Dir.mkdir("deploy") unless Dir.exist? "deploy"

  destination_dir = File.join(Dir.pwd, Mimas::Config::DEFAULT_DIRECTORY)

  app_server = Bundler.load.requested_specs.map(&:name).filter { ["falcon", "puma"].include?(it) }.first

  configrb = template("config.rb", ip: ip, domain: domain, app_server: app_server)
  File.write(File.join(destination_dir, "mimas.rb"), configrb)

  copy_file(destination_dir, "Caddyfile.erb")

  if app_server == "falcon"
    falconrb = template("falcon.rb", domain: domain)
    File.write(File.join(destination_dir, "falcon.rb"), falconrb)
  end

  copy_file(destination_dir, "puma.rb") if app_server == "puma"

  Dir.mkdir("tmp") unless Dir.exist?("tmp")

  say ""
  say "Successfully created 'deploy/mimas.rb' and 'deploy/Caddyfile.erb'. Customise your deployment by editing these files."
  say "Please ensure your DNS is correctly configured."
end