Class: Belt::CLI::Frontend
- Inherits:
-
Object
- Object
- Belt::CLI::Frontend
- Defined in:
- lib/belt/cli/frontend_registry.rb
Overview
A named frontend application (SPA) in a Belt project.
Belt apps historically used a single frontend/ directory. Apps like
Stowzilla have several (customer app/, ops ops-app/, …). This object
is the per-frontend view of path, build output, and terraform outputs.
Instance Attribute Summary collapse
-
#bucket_output ⇒ Object
readonly
Returns the value of attribute bucket_output.
-
#cloudfront_domain_output ⇒ Object
readonly
Returns the value of attribute cloudfront_domain_output.
-
#default ⇒ Object
Returns the value of attribute default.
-
#dist ⇒ Object
readonly
Returns the value of attribute dist.
-
#distribution_output ⇒ Object
readonly
Returns the value of attribute distribution_output.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#url_output ⇒ Object
readonly
Returns the value of attribute url_output.
Class Method Summary collapse
Instance Method Summary collapse
- #app_jsx ⇒ Object
-
#default? ⇒ Boolean
rubocop:enable Metrics/ParameterLists.
-
#dist_dir ⇒ Object
Build output directory.
- #distribution_output_explicit? ⇒ Boolean
- #exists? ⇒ Boolean
-
#initialize(name:, path:, dist: nil, bucket_output: nil, distribution_output: nil, url_output: nil, cloudfront_domain_output: nil, default: false) ⇒ Frontend
constructor
rubocop:disable Metrics/ParameterLists -- keyword options from YAML config.
- #label ⇒ Object
- #output_prefix ⇒ Object
- #package_json ⇒ Object
- #slug ⇒ Object
- #src_dir ⇒ Object
-
#tf_name ⇒ Object
Terraform resource name:
frontendfor the default,{slug}_frontendotherwise. - #yaml_lines ⇒ Object
Constructor Details
#initialize(name:, path:, dist: nil, bucket_output: nil, distribution_output: nil, url_output: nil, cloudfront_domain_output: nil, default: false) ⇒ Frontend
rubocop:disable Metrics/ParameterLists -- keyword options from YAML config
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/belt/cli/frontend_registry.rb', line 19 def initialize(name:, path:, dist: nil, bucket_output: nil, distribution_output: nil, url_output: nil, cloudfront_domain_output: nil, default: false) @name = name.to_s @path = path.to_s.sub(%r{/\z}, '') @dist = dist @default = default @bucket_output = bucket_output || default_output('bucket_name') @distribution_output_explicit = present_output?(distribution_output) @distribution_output = @distribution_output_explicit ? distribution_output : default_output('distribution_id') @url_output = url_output || default_output('url') @cloudfront_domain_output = cloudfront_domain_output end |
Instance Attribute Details
#bucket_output ⇒ Object (readonly)
Returns the value of attribute bucket_output.
14 15 16 |
# File 'lib/belt/cli/frontend_registry.rb', line 14 def bucket_output @bucket_output end |
#cloudfront_domain_output ⇒ Object (readonly)
Returns the value of attribute cloudfront_domain_output.
14 15 16 |
# File 'lib/belt/cli/frontend_registry.rb', line 14 def cloudfront_domain_output @cloudfront_domain_output end |
#default ⇒ Object
Returns the value of attribute default.
16 17 18 |
# File 'lib/belt/cli/frontend_registry.rb', line 16 def default @default end |
#dist ⇒ Object (readonly)
Returns the value of attribute dist.
14 15 16 |
# File 'lib/belt/cli/frontend_registry.rb', line 14 def dist @dist end |
#distribution_output ⇒ Object (readonly)
Returns the value of attribute distribution_output.
14 15 16 |
# File 'lib/belt/cli/frontend_registry.rb', line 14 def distribution_output @distribution_output end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/belt/cli/frontend_registry.rb', line 14 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
16 17 18 |
# File 'lib/belt/cli/frontend_registry.rb', line 16 def path @path end |
#url_output ⇒ Object (readonly)
Returns the value of attribute url_output.
14 15 16 |
# File 'lib/belt/cli/frontend_registry.rb', line 14 def url_output @url_output end |
Class Method Details
.slug(name) ⇒ Object
45 46 47 |
# File 'lib/belt/cli/frontend_registry.rb', line 45 def self.slug(name) name.to_s.downcase.gsub(/[^a-z0-9]+/, '_').gsub(/\A_|_\z/, '') end |
Instance Method Details
#app_jsx ⇒ Object
66 67 68 |
# File 'lib/belt/cli/frontend_registry.rb', line 66 def app_jsx File.join(src_dir, 'App.jsx') end |
#default? ⇒ Boolean
rubocop:enable Metrics/ParameterLists
33 34 35 |
# File 'lib/belt/cli/frontend_registry.rb', line 33 def default? @default end |
#dist_dir ⇒ Object
Build output directory. Explicit dist: wins; otherwise prefer dist/
then build/ (CRA / some Vite configs) then default dist.
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/belt/cli/frontend_registry.rb', line 76 def dist_dir return File.join(path, @dist) if @dist && !@dist.to_s.empty? %w[dist build].each do |dir| candidate = File.join(path, dir) return candidate if Dir.exist?(candidate) end File.join(path, 'dist') end |
#distribution_output_explicit? ⇒ Boolean
37 38 39 |
# File 'lib/belt/cli/frontend_registry.rb', line 37 def distribution_output_explicit? @distribution_output_explicit end |
#exists? ⇒ Boolean
70 71 72 |
# File 'lib/belt/cli/frontend_registry.rb', line 70 def exists? Dir.exist?(path) && File.file?(package_json) end |
#label ⇒ Object
87 88 89 |
# File 'lib/belt/cli/frontend_registry.rb', line 87 def label name == 'frontend' ? 'frontend' : "frontend '#{name}'" end |
#output_prefix ⇒ Object
54 55 56 |
# File 'lib/belt/cli/frontend_registry.rb', line 54 def output_prefix tf_name end |
#package_json ⇒ Object
62 63 64 |
# File 'lib/belt/cli/frontend_registry.rb', line 62 def package_json File.join(path, 'package.json') end |
#slug ⇒ Object
41 42 43 |
# File 'lib/belt/cli/frontend_registry.rb', line 41 def slug self.class.slug(name) end |
#src_dir ⇒ Object
58 59 60 |
# File 'lib/belt/cli/frontend_registry.rb', line 58 def src_dir File.join(path, 'src') end |
#tf_name ⇒ Object
Terraform resource name: frontend for the default, {slug}_frontend otherwise.
50 51 52 |
# File 'lib/belt/cli/frontend_registry.rb', line 50 def tf_name slug == 'frontend' ? 'frontend' : "#{slug}_frontend" end |
#yaml_lines ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/belt/cli/frontend_registry.rb', line 91 def yaml_lines lines = [" #{name}:", " path: #{path}"] lines << " dist: #{dist}" if dist && !dist.to_s.empty? lines << ' default: true' if default? lines << " bucket_output: #{bucket_output}" if bucket_output != inferred_output('bucket_name') if distribution_output != inferred_output('distribution_id') lines << " distribution_output: #{distribution_output}" end lines << " url_output: #{url_output}" if url_output != inferred_output('url') lines << " cloudfront_domain_output: #{cloudfront_domain_output}" if cloudfront_domain_output lines end |