Module: Rain::CLI::Static

Extended by:
Static
Included in:
Static
Defined in:
lib/cli/static.rb

Defined Under Namespace

Classes: FakeRequest, RequestResult

Instance Method Summary collapse

Instance Method Details

#build(application_path:) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cli/static.rb', line 19

def build(application_path:)
   = load_user_application(app_path: File.expand_path('app', application_path))
  build_path = File.expand_path('build', application_path)

  FileUtils.rm_rf(build_path)
  FileUtils.mkdir_p(build_path)
  FileUtils.cp_r("#{File.expand_path('public', application_path)}/.", build_path)

  Low::Events::RequestEvent.define do |observers|
    observers << Providers['rain.router']
  end

  request_results(metadata:).each do |request_result|
    folder_path = File.join(build_path, request_result.path)

    puts "#{folder_path} => #{request_result.status}"

    FileUtils.mkdir_p(folder_path)
    File.write(File.expand_path('index.html', folder_path), request_result.html)
  end
end