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) ⇒ FrontendCommand
Returns a new instance of FrontendCommand.
32
33
34
35
36
37
38
|
# File 'lib/belt/cli/frontend_command.rb', line 32
def initialize(framework, quiet: false, announce: true)
@framework = framework
@quiet = quiet
@announce = announce
@app_name = detect_app_name
@module_name = @app_name.split(/[-_]/).map(&:capitalize).join
end
|
Class Method Details
.run(args) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/belt/cli/frontend_command.rb', line 17
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
#generate ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/belt/cli/frontend_command.rb', line 40
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..." 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)
puts "\nā Frontend (#{@framework}) created in frontend/" unless @quiet
install_dependencies(dest_dir)
setup_frontend_infra_for_existing_environments
generate_views_for_existing_resources
return if @quiet || !@announce
puts "\nNext steps:"
puts ' belt server # Start local dev server'
puts ' belt deploy # Deploy everything to AWS'
end
|
#npm_ok? ⇒ Boolean
71
72
73
|
# File 'lib/belt/cli/frontend_command.rb', line 71
def npm_ok?
@npm_ok != false
end
|