Class: Belt::CLI::FrontendCommand
- Inherits:
-
Object
- Object
- Belt::CLI::FrontendCommand
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
#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(framework, quiet: false, announce: true, name: nil, path: nil) ⇒ FrontendCommand
Returns a new instance of FrontendCommand.
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/belt/cli/frontend_command.rb', line 36
def initialize(framework, quiet: false, announce: true, name: nil, path: nil)
@framework = framework
@quiet = quiet
@announce = announce
@app_name = detect_app_name
@module_name = @app_name.split(/[-_]/).map(&:capitalize).join
@name = name || (path ? File.basename(path) : 'frontend')
@path = path || name || 'frontend'
@frontend = Frontend.new(name: @name, path: @path, default: @name == 'frontend' && @path == 'frontend')
end
|
Class Method Details
.run(args) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/belt/cli/frontend_command.rb', line 18
def self.run(args)
name = FrontendRegistry.(args, '--name')
path = FrontendRegistry.(args, '--path')
framework = args.shift
if framework.nil? || !FRAMEWORKS.include?(framework)
puts "Usage: belt generate frontend <#{FRAMEWORKS.join('|')}> [--name NAME] [--path DIR]"
puts "\nScaffolds a frontend application with build tooling and API client."
puts "\nExamples:"
puts ' belt generate frontend react'
puts ' belt generate frontend vue'
puts ' belt generate frontend react --name ops --path ops-app'
exit 1
end
new(framework, name: name, path: path).generate
end
|
Instance Method Details
#generate ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/belt/cli/frontend_command.rb', line 47
def generate
dest_dir = @frontend.path
if Dir.exist?(dest_dir) && !Dir.empty?(dest_dir)
puts "Directory '#{dest_dir}/' already exists and is not empty."
exit 1
end
puts "Creating #{@framework} frontend application..." unless @quiet
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)
register_frontend!
puts "\nā Frontend (#{@framework}) created in #{dest_dir}/" unless @quiet
install_dependencies(dest_dir)
setup_frontend_infra_for_existing_environments
generate_views_for_existing_resources
return if @quiet || !@announce
puts "\nNext steps:"
if @frontend.name == 'frontend'
puts ' belt server # Start local dev server'
else
puts " belt server --frontend #{@frontend.name}"
end
puts ' belt deploy # Deploy everything to AWS'
end
|
#npm_ok? ⇒ Boolean
83
84
85
|
# File 'lib/belt/cli/frontend_command.rb', line 83
def npm_ok?
@npm_ok != false
end
|