Skip to content

Commit f177263

Browse files
authored
Support VERSION and CHANGELOG.md files (#323)
1 parent 580243b commit f177263

25 files changed

Lines changed: 169 additions & 23 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ For previous pre-release, Java based Smithy-Ruby, see: [smithy-ruby/main](https:
1515
### Smithy Build
1616
local build using smithy cli
1717
```
18-
bundle exec smithy build --debug
18+
cd projections && bundle exec smithy build --debug
1919
```
2020

2121
local build using smithy-ruby executable:
2222
```
23-
SMITHY_PLUGIN_DIR=build/smithy/source/smithy-ruby bundle exec smithy-ruby smith client --gem-name weather --gem-version 1.0.0 --destination-root projections/weather <<< $(smithy ast model/weather.smithy)
23+
cd projections && SMITHY_PLUGIN_DIR=build/smithy/source/smithy-ruby bundle exec smithy-ruby smith client --gem-name weather --gem-version 1.0.0 --destination-root weather <<< $(smithy ast model/weather.smithy)
2424
```
2525

2626
### IRB

gems/smithy/lib/smithy/generators/client.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ def initialize(plan)
1313

1414
def generate
1515
gem_files.each_with_object([]) do |(file, content), files|
16-
next if file == "lib/#{@gem_name}/customizations.rb" && should_skip_customizations?
16+
if persisted_file?(file)
17+
say_status :skip, "Skipping #{file} because it already exists", :yellow unless @plan.quiet
18+
next
19+
end
1720

1821
create_file file, content
1922
files << file
@@ -29,6 +32,8 @@ def source
2932
# rubocop:disable Metrics/AbcSize
3033
def gem_files
3134
Enumerator.new do |e|
35+
e.yield 'VERSION', Views::Client::Version.new(@plan).render
36+
e.yield 'CHANGELOG.md', Views::Client::ChangelogMd.new.render
3237
e.yield "#{@gem_name}.gemspec", Views::Client::Gemspec.new(@plan).render
3338
e.yield '.rubocop.yml', Views::Client::RubocopYml.new(@plan).render
3439

@@ -92,8 +97,11 @@ def code_generated_plugins
9297
end
9398
end
9499

95-
def should_skip_customizations?
96-
Dir["#{destination_root}/**/*"].any? { |f| f.include?('/customizations.rb') }
100+
def persisted_file?(path)
101+
keep = %W[lib/#{@gem_name}/customizations.rb VERSION CHANGELOG.md]
102+
return false unless keep.include?(path)
103+
104+
File.exist?(File.join(destination_root, path))
97105
end
98106
end
99107
end

gems/smithy/lib/smithy/generators/schema.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ def initialize(plan)
1313

1414
def generate
1515
gem_files.each_with_object([]) do |(file, content), files|
16-
next if file == "lib/#{@gem_name}/customizations.rb" && should_skip_customizations?
16+
if persisted_file?(file)
17+
say_status :skip, "Skipping #{file} because it already exists", :yellow unless @plan.quiet
18+
next
19+
end
1720

1821
create_file file, content
1922
files << file
@@ -26,8 +29,11 @@ def source
2629

2730
private
2831

32+
# rubocop:disable Metrics/AbcSize
2933
def gem_files
3034
Enumerator.new do |e|
35+
e.yield 'VERSION', Views::Client::Version.new(@plan).render
36+
e.yield 'CHANGELOG.md', Views::Client::ChangelogMd.new.render
3137
e.yield "#{@gem_name}.gemspec", Views::Client::Gemspec.new(@plan).render
3238
e.yield '.rubocop.yml', Views::Client::RubocopYml.new(@plan).render
3339

@@ -52,9 +58,13 @@ def rbs_files
5258
e.yield "sig/#{@gem_name}/schema.rbs", Views::Client::SchemaRbs.new(@plan).render
5359
end
5460
end
61+
# rubocop:enable Metrics/AbcSize
5562

56-
def should_skip_customizations?
57-
Dir["#{destination_root}/**/*"].any? { |f| f.include?('/customizations.rb') }
63+
def persisted_file?(path)
64+
keep = %W[lib/#{@gem_name}/customizations.rb VERSION CHANGELOG.md]
65+
return false unless keep.include?(path)
66+
67+
File.exist?(File.join(destination_root, path))
5868
end
5969
end
6070
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Unreleased Changes
2+
------------------

gems/smithy/lib/smithy/templates/client/gemspec.erb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
Gem::Specification.new do |spec|
66
spec.name = '<%= gem_name %>'
7-
spec.version = '<%= gem_version %>'
7+
spec.version = File.read(File.expand_path('../VERSION', __FILE__))
88
spec.summary = 'Generated gem using Smithy'
99
spec.authors = ['Smithy Ruby']
10-
spec.files = Dir['lib/**/*.rb', base: __dir__]
10+
spec.files = Dir['VERSION', 'CHANGELOG.md', 'lib/**/*.rb', base: __dir__]
11+
spec.license = 'Apache-2.0'
1112

1213
<% dependencies.each do |dependency, version| -%>
1314
spec.add_dependency('<%= dependency %>', '<%= version %>')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= gem_version %>

gems/smithy/lib/smithy/views/client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module Client; end
2121
require_relative 'client/auth_parameters_rbs'
2222
require_relative 'client/auth_resolver'
2323
require_relative 'client/auth_resolver_rbs'
24+
require_relative 'client/changelog_md'
2425
require_relative 'client/client'
2526
require_relative 'client/client_rbs'
2627
require_relative 'client/customizations'
@@ -43,4 +44,5 @@ module Client; end
4344
require_relative 'client/spec_helper'
4445
require_relative 'client/types'
4546
require_relative 'client/types_rbs'
47+
require_relative 'client/version'
4648
require_relative 'client/waiters'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
module Smithy
4+
module Views
5+
module Client
6+
# @api private
7+
class ChangelogMd < View; end
8+
end
9+
end
10+
end

gems/smithy/lib/smithy/views/client/gemspec.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ def gem_name
1414
@plan.gem_name
1515
end
1616

17-
def gem_version
18-
@plan.gem_version
19-
end
20-
2117
def dependencies
2218
dependencies = @plan.welds.map(&:add_dependencies).reduce({}, :merge)
2319
dependencies = dependencies.except(@plan.welds.map(&:remove_dependencies).reduce([], :+))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
module Smithy
4+
module Views
5+
module Client
6+
# @api private
7+
class Version < View
8+
def initialize(plan)
9+
@plan = plan
10+
super()
11+
end
12+
13+
def gem_version
14+
@plan.gem_version
15+
end
16+
end
17+
end
18+
end
19+
end

0 commit comments

Comments
 (0)