Class: Belt::CLI::FrontendSetupCommand
- Inherits:
-
Object
- Object
- Belt::CLI::FrontendSetupCommand
show all
- Includes:
- AppDetection
- Defined in:
- lib/belt/cli/frontend_setup_command.rb
Constant Summary
collapse
- TEMPLATE_DIR =
File.expand_path('../../templates/module', __dir__)
- MODULE_DIR =
'infrastructure/modules/app'
Class Method Summary
collapse
Instance Method Summary
collapse
#detect_app_name, #detect_environments, #detect_namespace, #find_contracts_file_path, #find_routes_file_path, #find_schema_file_path, #s3_safe_name
Constructor Details
#initialize(_env = nil, quiet: false, frontend: nil) ⇒ FrontendSetupCommand
Returns a new instance of FrontendSetupCommand.
60
61
62
63
64
65
66
67
68
|
# File 'lib/belt/cli/frontend_setup_command.rb', line 60
def initialize(_env = nil, quiet: false, frontend: nil)
@app_name = detect_app_name
@quiet = quiet
@frontend = frontend || Frontend.new(name: 'frontend', path: 'frontend', default: true)
@tf_name = @frontend.tf_name
@output_prefix = @frontend.output_prefix
@include_dns = @frontend.slug == 'frontend'
@bucket_slug = @frontend.slug == 'frontend' ? 'frontend' : "#{@frontend.slug.tr('_', '-')}-frontend"
end
|
Class Method Details
.append_env_outputs_for(frontend, outputs_file) ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/belt/cli/frontend_setup_command.rb', line 27
def self.append_env_outputs_for(frontend, outputs_file)
return unless File.exist?(outputs_file)
return if frontend.tf_name == 'frontend'
content = File.read(outputs_file)
prefix = frontend.output_prefix
return if content.include?("output \"#{prefix}_bucket_name\"")
File.write(outputs_file, content + (frontend))
end
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/belt/cli/frontend_setup_command.rb', line 38
def self.(frontend)
prefix = frontend.output_prefix
label = frontend.name
<<~HCL
output "#{prefix}_bucket_name" {
description = "S3 bucket for #{label} frontend assets"
value = try(module.app.#{prefix}_bucket_name, "")
}
output "#{prefix}_distribution_id" {
description = "CloudFront distribution ID for #{label} frontend"
value = try(module.app.#{prefix}_distribution_id, "")
}
output "#{prefix}_url" {
description = "#{label} frontend URL"
value = try(module.app.#{prefix}_url, "")
}
HCL
end
|
Instance Method Details
#run ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/belt/cli/frontend_setup_command.rb', line 70
def run
validate!
generate_frontend_tf
ensure_cloudfront_cors
append_env_outputs
return if @quiet
puts "\n✓ Frontend infrastructure generated in #{MODULE_DIR}!"
puts "\nRun `belt deploy` to create the S3 bucket and CloudFront distribution."
puts 'Then `belt deploy frontend` to build and deploy.'
end
|