Class: Belt::CLI::FrontendCommand

Inherits:
Object
  • Object
show all
Includes:
AppDetection
Defined in:
lib/belt/cli/frontend_command.rb

Constant Summary collapse

TEMPLATE_DIR =
File.expand_path('../../templates/frontend', __dir__)
FRAMEWORKS =
%w[react vue svelte].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AppDetection

#detect_app_name

Constructor Details

#initialize(framework) ⇒ FrontendCommand

Returns a new instance of FrontendCommand.



31
32
33
34
35
# File 'lib/belt/cli/frontend_command.rb', line 31

def initialize(framework)
  @framework = framework
  @app_name = detect_app_name
  @module_name = @app_name.split(/[-_]/).map(&:capitalize).join
end

Class Method Details

.run(args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/belt/cli/frontend_command.rb', line 16

def self.run(args)
  framework = args.shift

  if framework.nil? || !FRAMEWORKS.include?(framework)
    puts "Usage: belt generate frontend <#{FRAMEWORKS.join('|')}>"
    puts "\nScaffolds a frontend application with build tooling and API client."
    puts "\nExamples:"
    puts '  belt generate frontend react'
    puts '  belt generate frontend vue'
    exit 1
  end

  new(framework).generate
end

Instance Method Details

#generateObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/belt/cli/frontend_command.rb', line 37

def generate
  dest_dir = 'frontend'

  if Dir.exist?(dest_dir) && !Dir.empty?(dest_dir)
    puts "Directory 'frontend/' already exists and is not empty."
    exit 1
  end

  puts "Creating #{@framework} frontend application..."
  framework_dir = File.join(TEMPLATE_DIR, @framework)

  unless Dir.exist?(framework_dir)
    puts "āœ— Template not found for '#{@framework}'. Available: #{FRAMEWORKS.join(', ')}"
    exit 1
  end

  copy_template(framework_dir, dest_dir)

  puts "\nāœ“ Frontend (#{@framework}) created in frontend/"
  puts "\nNext steps:"
  puts '  cd frontend && npm install && npm run dev'
  puts '  belt setup frontend <env>    # Generate CloudFront + S3 infrastructure'
  puts '  belt deploy frontend <env>   # Build and deploy to AWS'
end