Class: Belt::CLI::NewCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/belt/cli/new_command.rb

Constant Summary collapse

TEMPLATE_DIR =
File.expand_path('../../templates/new_app', __dir__)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_name, frontend: nil) ⇒ NewCommand

Returns a new instance of NewCommand.



35
36
37
38
39
# File 'lib/belt/cli/new_command.rb', line 35

def initialize(app_name, frontend: nil)
  @app_name = app_name.gsub(/[^a-z0-9_-]/i, '_').downcase
  @module_name = @app_name.split(/[-_]/).map(&:capitalize).join
  @frontend = frontend
end

Class Method Details

.run(args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/belt/cli/new_command.rb', line 11

def self.run(args)
  app_name = nil
  frontend = nil

  args.each do |arg|
    if arg.start_with?('--frontend')
      frontend = if arg.include?('=')
                   arg.split('=', 2).last
                 else
                   args[args.index(arg) + 1]
                 end
    elsif !arg.start_with?('-')
      app_name ||= arg
    end
  end

  if app_name.nil? || app_name.empty?
    puts 'Usage: belt new <app_name> [--frontend react|vue|svelte]'
    exit 1
  end

  new(app_name, frontend: frontend).generate
end

Instance Method Details

#generateObject



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

def generate
  if Dir.exist?(@app_name)
    puts "Directory '#{@app_name}' already exists."
    exit 1
  end

  puts "Creating new Belt application: #{@app_name}"
  create_structure
  generate_frontend if @frontend
  init_git
  puts "\n✓ #{@app_name} created successfully!"
  puts "\nNext steps:"
  puts "  cd #{@app_name}"
  puts '  bundle install'
  puts '  cd frontend && npm install && npm run dev' if @frontend
  puts '  # Define your models in infrastructure/schema.tf.rb'
  puts '  # Define your routes in infrastructure/routes.tf.rb'
  puts "  # Add controllers in lambda/controllers/#{@app_name}/"
end