Class: LumiaServer::CLI::Build

Inherits:
Command
  • Object
show all
Defined in:
lib/lumia-server/command/build.rb

Instance Attribute Summary

Attributes inherited from Command

#args, #options

Instance Method Summary collapse

Methods inherited from Command

#initialize

Constructor Details

This class inherits a constructor from LumiaServer::CLI::Command

Instance Method Details

#runObject



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
# File 'lib/lumia-server/command/build.rb', line 10

def run
  FileUtils.mkdir_p File.join(Dir.home, '.lumia')

  LumiaServer::CLI.error('server.json was not found') unless File.exist?('server.json')
  @data = JSON.parse(File.read('server.json'))

  time = Benchmark.realtime {
    puts 'Initialising server..'
    yaml_file = File.join('build', '.lumia', 'server.yml')
    yaml = File.exist?(yaml_file) ? YAML.load(File.open(yaml_file)) : nil

    @server = Server.new(@data, yaml)

    puts 'Copying files..'
    Dir.glob("src/**/*").each do |file|
      unless File.directory?(file)
        out = file.sub('src', 'build')
        out = File.join(File.dirname(out), File.basename(out, '.erb'))
        FileUtils.mkdir_p File.dirname(out)
        File.open(file) do |fh|
          erb = ERB.new(fh.read)
          File.open(out, 'w') do |f|
            f.write erb.result(binding)
          end
        end
      end
    end

    puts 'Copying secrets..'
    @server.build_secrets

    @server.install_platform
    @server.install_mods

    update_yaml = {}
    update_yaml[@server.platform.name] = @server.platform.id
    @server.mods.each { |m|
      unless m.provider.nil?
        update_yaml[m.name] = m.id
      end
    }
    FileUtils.mkdir_p File.dirname(yaml_file)
    File.open(yaml_file, 'w') { |f| f.write update_yaml.to_yaml }
  }
  puts "Done. Server has been installed (#{time.round(3)}s)."
end