belt 0.2.10 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +63 -0
- data/README.md +169 -0
- data/lib/belt/action_router.rb +32 -4
- data/lib/belt/cli/app_detection.rb +19 -5
- data/lib/belt/cli/contracts_command.rb +142 -0
- data/lib/belt/cli/destroy_command.rb +193 -10
- data/lib/belt/cli/environment_command.rb +32 -0
- data/lib/belt/cli/generate_command.rb +5 -5
- data/lib/belt/cli/new_command.rb +2 -2
- data/lib/belt/cli/plugin_command.rb +221 -0
- data/lib/belt/cli/routes_command/schema_loader.rb +17 -7
- data/lib/belt/cli/routes_command.rb +7 -3
- data/lib/belt/cli/setup_command.rb +1 -1
- data/lib/belt/cli/views_command.rb +7 -2
- data/lib/belt/cli.rb +7 -0
- data/lib/belt/helpers/cors_origin.rb +19 -2
- data/lib/belt/helpers/response.rb +13 -2
- data/lib/belt/lambda_handler.rb +14 -5
- data/lib/belt/root.rb +12 -3
- data/lib/belt/route_dsl.rb +2 -2
- data/lib/belt/version.rb +1 -1
- data/lib/templates/environment/backend.tf.erb +1 -2
- data/lib/templates/frontend_infra/frontend.tf.erb +2 -1
- data/lib/templates/module/frontend.tf.erb +2 -1
- data/lib/templates/module/main.tf.erb +1 -1
- data/lib/templates/new_app/AGENTS.md.erb +4 -4
- data/lib/templates/new_app/README.md.erb +2 -2
- data/lib/templates/plugin/AGENTS.md.erb +135 -0
- data/lib/templates/plugin/CHANGELOG.md.erb +5 -0
- data/lib/templates/plugin/Gemfile.erb +11 -0
- data/lib/templates/plugin/LICENSE.erb +21 -0
- data/lib/templates/plugin/README.md.erb +63 -0
- data/lib/templates/plugin/Rakefile.erb +7 -0
- data/lib/templates/plugin/gemspec.erb +26 -0
- data/lib/templates/plugin/gitignore.erb +11 -0
- data/lib/templates/plugin/lib/belt/generators/generator.rb.erb +122 -0
- data/lib/templates/plugin/lib/belt/module/configuration.rb.erb +15 -0
- data/lib/templates/plugin/lib/belt/module/version.rb.erb +7 -0
- data/lib/templates/plugin/lib/belt/module.rb.erb +27 -0
- data/lib/templates/plugin/lib/entry.rb.erb +3 -0
- data/lib/templates/plugin/rspec.erb +3 -0
- data/lib/templates/plugin/spec/configuration_spec.rb.erb +17 -0
- data/lib/templates/plugin/spec/spec_helper.rb.erb +19 -0
- metadata +21 -3
- /data/lib/templates/new_app/config/{schema.tf.rb.erb → contracts.rb.erb} +0 -0
- /data/lib/templates/new_app/config/{routes.tf.rb.erb → routes.rb.erb} +0 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require 'erb'
|
|
5
|
+
|
|
6
|
+
module Belt
|
|
7
|
+
module Generators
|
|
8
|
+
# Generator registered automatically by Belt::CLI::GeneratorRegistry.
|
|
9
|
+
# File must live at: lib/belt/generators/<%= underscored %>_generator.rb
|
|
10
|
+
#
|
|
11
|
+
# Available as:
|
|
12
|
+
# belt generate <%= plugin_name %>
|
|
13
|
+
# belt destroy <%= plugin_name %>
|
|
14
|
+
class <%= generator_class %>
|
|
15
|
+
TEMPLATE_DIR = File.expand_path('../<%= underscored %>/templates', __dir__)
|
|
16
|
+
|
|
17
|
+
def self.description
|
|
18
|
+
'Install <%= summary %>'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.run(args)
|
|
22
|
+
if args.include?('--help') || args.include?('-h')
|
|
23
|
+
print_help
|
|
24
|
+
return
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
new(args).generate
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.destroy(args)
|
|
31
|
+
new(args).destroy
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.print_help
|
|
35
|
+
puts <<~HELP
|
|
36
|
+
Install <%= gem_name %> into a Belt application.
|
|
37
|
+
|
|
38
|
+
Usage: belt generate <%= plugin_name %> [options]
|
|
39
|
+
|
|
40
|
+
Options:
|
|
41
|
+
--force Overwrite existing files
|
|
42
|
+
-h, --help Show this help
|
|
43
|
+
|
|
44
|
+
What gets created (customize this generator):
|
|
45
|
+
infrastructure/modules/<%= plugin_name %>/ Terraform module (optional)
|
|
46
|
+
config/lambda/<%= plugin_name %>.yml Lambda configuration (optional)
|
|
47
|
+
lambda/<%= plugin_name %>.rb Lambda entry point (optional)
|
|
48
|
+
|
|
49
|
+
What stays in the gem (no generation needed):
|
|
50
|
+
<%= constant_path %> Runtime library API
|
|
51
|
+
|
|
52
|
+
After generation:
|
|
53
|
+
1. Wire any Terraform module into your environment main.tf
|
|
54
|
+
2. Configure environment variables / secrets
|
|
55
|
+
3. Deploy: belt deploy <env>
|
|
56
|
+
|
|
57
|
+
Examples:
|
|
58
|
+
belt g <%= plugin_name %>
|
|
59
|
+
belt d <%= plugin_name %>
|
|
60
|
+
HELP
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def initialize(args)
|
|
64
|
+
@force = args.include?('--force')
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def generate
|
|
68
|
+
# TODO: copy templates into the host app.
|
|
69
|
+
# Pattern used by belt-messaging / belt-pay:
|
|
70
|
+
#
|
|
71
|
+
# generate_terraform_module
|
|
72
|
+
# generate_lambda_config
|
|
73
|
+
# generate_lambda_entry_point
|
|
74
|
+
# inject_routes
|
|
75
|
+
#
|
|
76
|
+
# Templates live under TEMPLATE_DIR. Use ERB + FileUtils.
|
|
77
|
+
puts " # TODO: implement <%= generator_class %>#generate"
|
|
78
|
+
puts " # Templates directory: #{TEMPLATE_DIR}"
|
|
79
|
+
print_success
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def destroy
|
|
83
|
+
# TODO: remove files created by #generate
|
|
84
|
+
puts " # TODO: implement <%= generator_class %>#destroy"
|
|
85
|
+
puts "\n✓ <%= module_name %> removed!"
|
|
86
|
+
puts ' Don\'t forget to remove any module references from environment main.tf files.'
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
private
|
|
90
|
+
|
|
91
|
+
def print_success
|
|
92
|
+
puts ''
|
|
93
|
+
puts "✓ <%= module_name %> installed (scaffold — implement the generator next)!"
|
|
94
|
+
puts ''
|
|
95
|
+
puts 'Next steps:'
|
|
96
|
+
puts " 1. Add ERB templates under lib/belt/<%= underscored %>/templates/"
|
|
97
|
+
puts " 2. Implement generate/destroy in lib/belt/generators/<%= underscored %>_generator.rb"
|
|
98
|
+
puts ' 3. See belt-messaging or belt-pay for full working examples'
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# ---- helpers (copy patterns from belt-messaging / belt-pay) ----
|
|
102
|
+
|
|
103
|
+
def write_template(relative_template, destination, binding_context = binding)
|
|
104
|
+
source = File.join(TEMPLATE_DIR, relative_template)
|
|
105
|
+
unless File.exist?(source)
|
|
106
|
+
puts " skip missing template #{relative_template}"
|
|
107
|
+
return
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
if File.exist?(destination) && !@force
|
|
111
|
+
puts " skip #{destination} (already exists, use --force to overwrite)"
|
|
112
|
+
return
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
FileUtils.mkdir_p(File.dirname(destination))
|
|
116
|
+
content = ERB.new(File.read(source), trim_mode: '-').result(binding_context)
|
|
117
|
+
File.write(destination, content)
|
|
118
|
+
puts " create #{destination}"
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Belt
|
|
4
|
+
module <%= module_name %>
|
|
5
|
+
class Configuration
|
|
6
|
+
# Add plugin-specific settings here.
|
|
7
|
+
# attr_accessor :api_key, :logger
|
|
8
|
+
attr_accessor :logger
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
@logger = nil # Falls back to Belt::Observability::Logger if available
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '<%= underscored %>/version'
|
|
4
|
+
require_relative '<%= underscored %>/configuration'
|
|
5
|
+
|
|
6
|
+
module Belt
|
|
7
|
+
module <%= module_name %>
|
|
8
|
+
class Error < StandardError; end
|
|
9
|
+
class ConfigurationError < Error; end
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
attr_writer :configuration
|
|
13
|
+
|
|
14
|
+
def configuration
|
|
15
|
+
@configuration ||= Configuration.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def configure
|
|
19
|
+
yield(configuration)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def reset_configuration!
|
|
23
|
+
@configuration = Configuration.new
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe <%= constant_path %>::Configuration do
|
|
6
|
+
it 'has a default configuration' do
|
|
7
|
+
expect(<%= constant_path %>.configuration).to be_a(described_class)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'accepts configure block' do
|
|
11
|
+
<%= constant_path %>.configure do |config|
|
|
12
|
+
config.logger = :test_logger
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
expect(<%= constant_path %>.configuration.logger).to eq(:test_logger)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'belt/<%= underscored %>'
|
|
4
|
+
|
|
5
|
+
RSpec.configure do |config|
|
|
6
|
+
config.expect_with :rspec do |expectations|
|
|
7
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
config.mock_with :rspec do |mocks|
|
|
11
|
+
mocks.verify_partial_doubles = true
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
|
15
|
+
|
|
16
|
+
config.before do
|
|
17
|
+
<%= constant_path %>.reset_configuration!
|
|
18
|
+
end
|
|
19
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: belt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.12
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stowzilla
|
|
@@ -74,6 +74,7 @@ files:
|
|
|
74
74
|
- lib/belt/cli/backup_runner.rb
|
|
75
75
|
- lib/belt/cli/bucket_security.rb
|
|
76
76
|
- lib/belt/cli/console_command.rb
|
|
77
|
+
- lib/belt/cli/contracts_command.rb
|
|
77
78
|
- lib/belt/cli/deploy_command.rb
|
|
78
79
|
- lib/belt/cli/destroy_command.rb
|
|
79
80
|
- lib/belt/cli/doctor_command.rb
|
|
@@ -90,6 +91,7 @@ files:
|
|
|
90
91
|
- lib/belt/cli/lambda_config_command.rb
|
|
91
92
|
- lib/belt/cli/new_command.rb
|
|
92
93
|
- lib/belt/cli/path_gem_materializer.rb
|
|
94
|
+
- lib/belt/cli/plugin_command.rb
|
|
93
95
|
- lib/belt/cli/routes_command.rb
|
|
94
96
|
- lib/belt/cli/routes_command/route_inference.rb
|
|
95
97
|
- lib/belt/cli/routes_command/schema_loader.rb
|
|
@@ -143,15 +145,31 @@ files:
|
|
|
143
145
|
- lib/templates/new_app/Gemfile.erb
|
|
144
146
|
- lib/templates/new_app/README.md.erb
|
|
145
147
|
- lib/templates/new_app/Rakefile.erb
|
|
148
|
+
- lib/templates/new_app/config/contracts.rb.erb
|
|
146
149
|
- lib/templates/new_app/config/lambda/api.yml.erb
|
|
147
|
-
- lib/templates/new_app/config/routes.
|
|
148
|
-
- lib/templates/new_app/config/schema.tf.rb.erb
|
|
150
|
+
- lib/templates/new_app/config/routes.rb.erb
|
|
149
151
|
- lib/templates/new_app/gitignore.erb
|
|
150
152
|
- lib/templates/new_app/lambda/api.rb.erb
|
|
151
153
|
- lib/templates/new_app/lambda/config/environment.rb.erb
|
|
152
154
|
- lib/templates/new_app/lambda/controllers/application_controller.rb.erb
|
|
153
155
|
- lib/templates/new_app/lambda/lib/routes/routes.rb.erb
|
|
154
156
|
- lib/templates/new_app/lambda/models/application_record.rb.erb
|
|
157
|
+
- lib/templates/plugin/AGENTS.md.erb
|
|
158
|
+
- lib/templates/plugin/CHANGELOG.md.erb
|
|
159
|
+
- lib/templates/plugin/Gemfile.erb
|
|
160
|
+
- lib/templates/plugin/LICENSE.erb
|
|
161
|
+
- lib/templates/plugin/README.md.erb
|
|
162
|
+
- lib/templates/plugin/Rakefile.erb
|
|
163
|
+
- lib/templates/plugin/gemspec.erb
|
|
164
|
+
- lib/templates/plugin/gitignore.erb
|
|
165
|
+
- lib/templates/plugin/lib/belt/generators/generator.rb.erb
|
|
166
|
+
- lib/templates/plugin/lib/belt/module.rb.erb
|
|
167
|
+
- lib/templates/plugin/lib/belt/module/configuration.rb.erb
|
|
168
|
+
- lib/templates/plugin/lib/belt/module/version.rb.erb
|
|
169
|
+
- lib/templates/plugin/lib/entry.rb.erb
|
|
170
|
+
- lib/templates/plugin/rspec.erb
|
|
171
|
+
- lib/templates/plugin/spec/configuration_spec.rb.erb
|
|
172
|
+
- lib/templates/plugin/spec/spec_helper.rb.erb
|
|
155
173
|
- lib/templates/views/Edit.jsx.erb
|
|
156
174
|
- lib/templates/views/Form.jsx.erb
|
|
157
175
|
- lib/templates/views/Index.jsx.erb
|
|
File without changes
|
|
File without changes
|