gem_toys 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8fc9bcdb919f2a0f201a81e39147393ae2fb8b3a6caa37cd38944770cef390de
4
+ data.tar.gz: ad694499de8f8a2db342c748ada96842cfb3396dc53ed33b35d1928ca89b078c
5
+ SHA512:
6
+ metadata.gz: 3100babf6998a170b6d51c5e9f33a71e1e11742cd915a106d43a017190e21f9c7b629984c6729271f4f3c38f8b5024d6e696e0c448594e8ec48166edbdbcbee7
7
+ data.tar.gz: 36e525c0564e2685e4c404cc3f8f7aaf0ec03f04486b0fc4470bd1c69f752ddd4bd37a2ac130cf9d6701eebf9fc84747c705792a1fba261aef8a2242de737516
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## master (unreleased)
4
+
5
+ ## 0.1.0 (2020-07-08)
6
+
7
+ * Initial commit
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Alexander Popov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,62 @@
1
+ # Gem Toys
2
+
3
+ ![Cirrus CI - Base Branch Build Status](https://img.shields.io/cirrus/github/AlexWayfer/gem_toys?style=flat-square)
4
+ [![Codecov branch](https://img.shields.io/codecov/c/github/AlexWayfer/gem_toys/master.svg?style=flat-square)](https://codecov.io/gh/AlexWayfer/gem_toys)
5
+ [![Code Climate](https://img.shields.io/codeclimate/maintainability/AlexWayfer/gem_toys.svg?style=flat-square)](https://codeclimate.com/github/AlexWayfer/gem_toys)
6
+ ![Depfu](https://img.shields.io/depfu/AlexWayfer/gem_toys?style=flat-square)
7
+ [![Inline docs](https://inch-ci.org/github/AlexWayfer/gem_toys.svg?branch=master)](https://inch-ci.org/github/AlexWayfer/gem_toys)
8
+ [![license](https://img.shields.io/github/license/AlexWayfer/gem_toys.svg?style=flat-square)](https://github.com/AlexWayfer/gem_toys/blob/master/LICENSE)
9
+ [![Gem](https://img.shields.io/gem/v/gem_toys.svg?style=flat-square)](https://rubygems.org/gems/gem_toys)
10
+
11
+ [Toys](https://github.com/dazuma/toys) template for gems, like building, releasing, etc.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'gem_toys'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ ```shell
24
+ bundle install
25
+ ```
26
+
27
+ Or install it yourself as:
28
+
29
+ ```shell
30
+ gem install gem_toys
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ```ruby
36
+ # .toys.rb
37
+ require 'gem_toys'
38
+ expand GemToys::Template
39
+
40
+ # `gem` namespace created, aliases are optional, but handful
41
+ alias_tool :g, :gem
42
+ ```
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bundle install` to install dependencies.
47
+ Then, run `bundle exec rspec` to run the tests.
48
+
49
+ To install this gem onto your local machine, run `toys gem install`.
50
+ To release a new version, update the version number in `version.rb`,
51
+ and then run `bundle exec rake release`, which will create a git tag
52
+ for the version, push git commits and tags, and push the `.gem` file
53
+ to [rubygems.org](https://rubygems.org).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/AlexWayfer/gem_toys).
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the
62
+ [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'gem_toys/version'
4
+ require_relative 'gem_toys/template'
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'toys-core'
5
+
6
+ module GemToys
7
+ ## Template with gem tools, should be expanded in toys file
8
+ class Template
9
+ include Toys::Template
10
+
11
+ ## Module for common code between nested tools
12
+ module CommonCode
13
+ private
14
+
15
+ def project_name
16
+ @project_name ||= File.basename context_directory
17
+ end
18
+
19
+ def version_file_path
20
+ project_path = project_name.tr '-', '/'
21
+ @version_file_path ||= File.join context_directory, 'lib', project_path, 'version.rb'
22
+ end
23
+
24
+ def version_file_content
25
+ File.read version_file_path
26
+ end
27
+
28
+ def current_version
29
+ @current_version ||= version_file_content.match(/VERSION = '(.+)'/)[1]
30
+ end
31
+
32
+ def changelog_file_path
33
+ @changelog_file_path ||= File.join context_directory, 'CHANGELOG.md'
34
+ end
35
+
36
+ def gem_file_name
37
+ @gem_file_name ||= "#{project_name}-#{current_version}.gem"
38
+ end
39
+
40
+ def pkg_directory
41
+ @pkg_directory ||= "#{context_directory}/pkg"
42
+ end
43
+
44
+ def current_gem_file
45
+ "#{pkg_directory}/#{gem_file_name}"
46
+ end
47
+ end
48
+
49
+ on_expand do
50
+ tool :gem do
51
+ subtool_apply do
52
+ include :exec, exit_on_nonzero_status: true, log_level: Logger::UNKNOWN
53
+ include CommonCode
54
+ end
55
+
56
+ tool :build do
57
+ def run
58
+ sh 'gem build'
59
+ FileUtils.mkdir_p pkg_directory
60
+ FileUtils.mv "#{context_directory}/#{gem_file_name}", current_gem_file
61
+ end
62
+ end
63
+
64
+ tool :install do
65
+ def run
66
+ exec_tool 'gem build'
67
+ sh "gem install #{current_gem_file}"
68
+ end
69
+ end
70
+
71
+ tool :release do
72
+ required_arg :version
73
+
74
+ def run
75
+ update_version_file
76
+
77
+ ## Update CHANGELOG
78
+ update_changelog_file
79
+
80
+ ## Checkout to a new git branch, required for protected `master` with CI
81
+ # sh "git switch -c v#{version}"
82
+
83
+ commit_changes
84
+
85
+ ## Tag commit
86
+ sh "git tag -a v#{version} -m 'Version #{version}'"
87
+
88
+ ## Build new gem file
89
+ exec_tool 'gem build'
90
+
91
+ wait_for_manual_check
92
+
93
+ ## Push commit
94
+ sh 'git push'
95
+
96
+ ## Push tags
97
+ sh 'git push --tags'
98
+
99
+ sh "gem push #{current_gem_file}"
100
+ end
101
+
102
+ private
103
+
104
+ def update_version_file
105
+ File.write version_file_path, version_file_content.sub(/'.+'/, "'#{version}'")
106
+ end
107
+
108
+ TODAY = Date.today.to_s
109
+
110
+ def update_changelog_file
111
+ @changelog_lines = File.readlines(changelog_file_path)
112
+
113
+ existing_line = find_version_line_in_changelog_file
114
+
115
+ if existing_line
116
+ return if (existing_date = existing_line.match(/\((.*)\)/)[1]) == TODAY
117
+
118
+ abort "There is already #{version} version with date #{existing_date}"
119
+ end
120
+
121
+ File.write changelog_file_path, new_changelog_content
122
+ end
123
+
124
+ def find_version_line_in_changelog_file
125
+ @changelog_lines.find { |line| line.start_with? "## #{version} " }
126
+ end
127
+
128
+ def new_changelog_content
129
+ @changelog_lines.insert(
130
+ @changelog_lines.index("## master (unreleased)\n") + 2, "## #{version} (#{TODAY})\n\n"
131
+ ).join
132
+ end
133
+
134
+ def commit_changes
135
+ sh "git add #{version_file_path} #{changelog_file_path}"
136
+
137
+ sh "git commit -m 'Update version to #{version}'"
138
+ end
139
+
140
+ def wait_for_manual_check
141
+ STDOUT.puts 'Please, validate files and commits before pushing.'
142
+ STDIN.gets
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GemToys
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem_toys
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Popov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry-byebug
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: toys
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.10.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.10.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: codecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.18.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.18.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.86.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.86.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-performance
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.0'
139
+ description: 'Toys template for gems, like building, releasing, etc.
140
+
141
+ '
142
+ email:
143
+ - alex.wayfer@gmail.com
144
+ executables: []
145
+ extensions: []
146
+ extra_rdoc_files: []
147
+ files:
148
+ - CHANGELOG.md
149
+ - LICENSE.txt
150
+ - README.md
151
+ - lib/gem_toys.rb
152
+ - lib/gem_toys/template.rb
153
+ - lib/gem_toys/version.rb
154
+ homepage: https://github.com/AlexWayfer/gem_toys
155
+ licenses:
156
+ - MIT
157
+ metadata:
158
+ source_code_uri: https://github.com/AlexWayfer/gem_toys
159
+ homepage_uri: https://github.com/AlexWayfer/gem_toys
160
+ changelog_uri: https://github.com/AlexWayfer/gem_toys/blob/master/CHANGELOG.md
161
+ post_install_message:
162
+ rdoc_options: []
163
+ require_paths:
164
+ - lib
165
+ required_ruby_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '2.5'
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ requirements: []
176
+ rubygems_version: 3.1.2
177
+ signing_key:
178
+ specification_version: 4
179
+ summary: Toys template for gems
180
+ test_files: []