Class: Mimas::Plugins::Bridgetown::Commands::Init

Inherits:
CLI::Commands::BaseCommand
  • Object
show all
Defined in:
lib/mimas/plugins/bridgetown/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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mimas/plugins/bridgetown/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?"
  site_type     = ask "Are you creating a \n  1. Static site \n  2. Static site and Ruby service \n (1 | 2)"
  site_type     = site_types[site_type]

  app_server = Bundler.load.requested_specs.map(&:name).filter { ["falcon", "puma"].include?(it) }.first
  server_confirmation = "n"
  if site_type == :hybrid
    server_confirmation = ask "Are you using the #{app_server} server? (y|n)" if app_server

    unless server_confirmation.downcase == "y"
      say "Bridgetown and Mimas natively support Falcon and Puma. To use another server, ensure you configure it to bind to a unix socket defined in `ENV['MIMAS_UNIX_SOCKET']`".white.bold
    end
  end

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

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

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

  if site_type == :hybrid
    copy_file(destination_dir, "Caddyfile.static.erb")
    copy_file(destination_dir, "Caddyfile.ruby.erb", rename: "Caddyfile.api.erb")

    if server_confirmation == "y"
      if app_server == "falcon"
        falconrb = template("falcon.rb", domain: domain)
        File.write(File.join(destination_dir, "falcon.rb"), falconrb)
      elsif app_server == "puma"
        copy_file(destination_dir, "puma.rb")
      end
    end

  else
    copy_file(destination_dir, "Caddyfile.static.erb", rename: "Caddyfile.erb")
  end

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

  say ""
  say "Successfully created files under `deploy/`. Customise your deployment by editing these files."
  say "Please ensure your DNS is correctly configured."
end

#site_typesObject



59
60
61
62
63
64
# File 'lib/mimas/plugins/bridgetown/commands/init.rb', line 59

def site_types
  {
    "1" => :static,
    "2" => :hybrid
  }
end