bake-modernize 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bake/modernize.rb +4 -0
- data/bake/modernize/actions.rb +17 -0
- data/bake/modernize/gemfile.rb +39 -0
- data/bake/modernize/gemspec.rb +180 -0
- data/lib/bake/modernize.rb +1 -1
- data/lib/bake/modernize/version.rb +1 -1
- data/template/actions/.github/workflows/development.yml +46 -0
- data/template/editorconfig/.editorconfig +6 -0
- data/template/readme/README.md +47 -0
- metadata +13 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75271407b97ab96706e68b107d007bbfa046806ceae4e724a212da77eed2441e
|
4
|
+
data.tar.gz: e8df139fdcda5491b67644d3fe4e5cf3304f49336eec48387813d7a90558edd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a6abd81f19428b1528550cf0a6ece16dc320607055c8eb3415d6e3ed15c388b9bd3716d48509eac55198deeb6aa34806df68e85e91ef07b15995fa41b15f7da
|
7
|
+
data.tar.gz: b6b5b87f2be7f43a8a7c53e58f6324c20cdc18c364c92908772cdd33e391b15513806f7b79a16be16ca54abcdc86c9e48e4aa84234432b8e891f471c188e023c
|
data/bake/modernize.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
require 'bake/modernize'
|
3
|
+
|
4
|
+
def actions
|
5
|
+
update(root: Dir.pwd)
|
6
|
+
end
|
7
|
+
|
8
|
+
def update(root:)
|
9
|
+
travis_path = File.expand_path(".travis.yml", root)
|
10
|
+
|
11
|
+
if File.exist?(travis_path)
|
12
|
+
FileUtils.rm_rf(travis_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
template_root = Bake::Modernize.template_path_for('actions')
|
16
|
+
Bake::Modernize.copy_template(template_root, root)
|
17
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
|
2
|
+
require 'bake/modernize'
|
3
|
+
|
4
|
+
def gemfile
|
5
|
+
update(root: Dir.pwd)
|
6
|
+
end
|
7
|
+
|
8
|
+
def update(root:)
|
9
|
+
gemfile_path = File.expand_path("Gemfile", root)
|
10
|
+
gems_path = File.expand_path("gems.rb", root)
|
11
|
+
|
12
|
+
if File.exist?(gemfile_path)
|
13
|
+
FileUtils::Verbose.mv gemfile_path, gems_path
|
14
|
+
end
|
15
|
+
|
16
|
+
gemfile_lock_path = File.expand_path("Gemfile.lock", root)
|
17
|
+
gems_locked_path = File.expand_path("gems.locked", root)
|
18
|
+
|
19
|
+
if File.exist?(gemfile_lock_path)
|
20
|
+
FileUtils::Verbose.mv gemfile_lock_path, gems_locked_path
|
21
|
+
end
|
22
|
+
|
23
|
+
gitignore_path = File.expand_path(".gitignore", root)
|
24
|
+
|
25
|
+
if File.exist?(gitignore_path)
|
26
|
+
lines = File.readlines(gitignore_path)
|
27
|
+
|
28
|
+
if index = lines.index{|pattern| pattern =~ /Gemfile\.lock/}
|
29
|
+
lines[index] = "/gems.locked"
|
30
|
+
elsif !lines.index{|pattern| pattern =~ /gems\.locked/}
|
31
|
+
lines << ""
|
32
|
+
lines << "/gems.locked"
|
33
|
+
end
|
34
|
+
|
35
|
+
File.open(gitignore_path, "w") do |file|
|
36
|
+
file.puts(lines)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
|
2
|
+
# Rewrite the current gemspec.
|
3
|
+
def gemspec
|
4
|
+
path = self.default_gemspec_path
|
5
|
+
buffer = StringIO.new
|
6
|
+
|
7
|
+
update(path: path, output: buffer)
|
8
|
+
|
9
|
+
File.write(path, buffer.string)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Rewrite the specified gemspec.
|
13
|
+
# @param
|
14
|
+
def update(path: self.default_gemspec_path, output: $stdout)
|
15
|
+
spec = Gem::Specification.load(path)
|
16
|
+
|
17
|
+
root = File.dirname(path)
|
18
|
+
version_path = self.version_path(root)
|
19
|
+
|
20
|
+
constant = File.read(version_path)
|
21
|
+
.scan(/module\s+(.*?)$/)
|
22
|
+
.flatten
|
23
|
+
.join("::")
|
24
|
+
|
25
|
+
spec.metadata["funding_uri"] ||= detect_funding_uri(spec)
|
26
|
+
spec.metadata["documentation_uri"] ||= detect_documentation_uri(spec)
|
27
|
+
|
28
|
+
spec.metadata.delete_if{|_, value| value.nil?}
|
29
|
+
|
30
|
+
output.puts
|
31
|
+
output.puts "require_relative #{version_path.sub(/\.rb$/, '').inspect}"
|
32
|
+
output.puts
|
33
|
+
output.puts "Gem::Specification.new do |spec|"
|
34
|
+
output.puts "\tspec.name = #{spec.name.dump}"
|
35
|
+
output.puts "\tspec.version = #{constant}::VERSION"
|
36
|
+
output.puts "\t"
|
37
|
+
output.puts "\tspec.summary = #{spec.summary.inspect}"
|
38
|
+
output.puts "\tspec.authors = #{spec.authors.inspect}"
|
39
|
+
output.puts "\tspec.license = #{spec.license.inspect}"
|
40
|
+
|
41
|
+
if spec.homepage and !spec.homepage.empty?
|
42
|
+
output.puts "\t"
|
43
|
+
output.puts "\tspec.homepage = #{spec.homepage.inspect}"
|
44
|
+
end
|
45
|
+
|
46
|
+
if spec.metadata.any?
|
47
|
+
output.puts "\t"
|
48
|
+
output.puts "\tspec.metadata = {"
|
49
|
+
spec.metadata.sort.each do |key, value|
|
50
|
+
output.puts "\t\t#{key.inspect} => #{value.inspect},"
|
51
|
+
end
|
52
|
+
output.puts "\t}"
|
53
|
+
end
|
54
|
+
|
55
|
+
output.puts "\t"
|
56
|
+
output.puts "\tspec.files = #{directory_glob_for(spec)}"
|
57
|
+
|
58
|
+
if spec.require_paths != ['lib']
|
59
|
+
output.puts "\tspec.require_paths = ['lib']"
|
60
|
+
end
|
61
|
+
|
62
|
+
if executables = spec.executables and executables.any?
|
63
|
+
output.puts "\t"
|
64
|
+
output.puts "\tspec.executables = #{executables.inspect}"
|
65
|
+
end
|
66
|
+
|
67
|
+
if extensions = spec.extensions and extensions.any?
|
68
|
+
output.puts "\t"
|
69
|
+
output.puts "\tspec.extensions = #{extensions.inspect}"
|
70
|
+
end
|
71
|
+
|
72
|
+
if required_ruby_version = spec.required_ruby_version
|
73
|
+
output.puts
|
74
|
+
output.puts "\tspec.required_ruby_version = #{required_ruby_version.to_s.inspect}"
|
75
|
+
end
|
76
|
+
|
77
|
+
if spec.dependencies.any?
|
78
|
+
output.puts "\t"
|
79
|
+
spec.dependencies.sort.each do |dependency|
|
80
|
+
next unless dependency.type == :runtime
|
81
|
+
output.puts "\tspec.add_dependency #{format_dependency(dependency)}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
if spec.development_dependencies.any?
|
86
|
+
output.puts "\t"
|
87
|
+
spec.development_dependencies.sort.each do |dependency|
|
88
|
+
output.puts "\tspec.add_development_dependency #{format_dependency(dependency)}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
output.puts "end"
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def directory_glob_for(spec, paths = spec.files)
|
98
|
+
directories = {}
|
99
|
+
root = File.dirname(spec.loaded_from)
|
100
|
+
|
101
|
+
paths.each do |path|
|
102
|
+
directory, _ = path.split(File::SEPARATOR, 2)
|
103
|
+
|
104
|
+
full_path = File.expand_path(directory, root)
|
105
|
+
if File.directory?(full_path)
|
106
|
+
directories[directory] = true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
return "Dir.glob('{#{directories.keys.join(',')}}/**/*', File::FNM_DOTMATCH, base: __dir__)"
|
111
|
+
end
|
112
|
+
|
113
|
+
def format_dependency(dependency)
|
114
|
+
requirements = dependency.requirements_list
|
115
|
+
|
116
|
+
if requirements.size == 1
|
117
|
+
requirements = requirements.first
|
118
|
+
end
|
119
|
+
|
120
|
+
if requirements == ">= 0"
|
121
|
+
requirements = nil
|
122
|
+
end
|
123
|
+
|
124
|
+
if dependency.name == "bundler"
|
125
|
+
requirements = nil
|
126
|
+
end
|
127
|
+
|
128
|
+
if requirements
|
129
|
+
"#{dependency.name.inspect}, #{requirements.inspect}"
|
130
|
+
else
|
131
|
+
"#{dependency.name.inspect}"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def default_gemspec_path
|
136
|
+
Dir["*.gemspec"].first
|
137
|
+
end
|
138
|
+
|
139
|
+
def version_path(root)
|
140
|
+
Dir["lib/**/version.rb", base: root].first
|
141
|
+
end
|
142
|
+
|
143
|
+
require 'async'
|
144
|
+
require 'async/http/internet'
|
145
|
+
|
146
|
+
def valid_uri?(uri)
|
147
|
+
Sync do
|
148
|
+
internet = Async::HTTP::Internet.new
|
149
|
+
response = internet.head(uri)
|
150
|
+
|
151
|
+
next response.success?
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
GITHUB_PROJECT = /github.com\/(?<account>.*?)\/(?<project>.*?)\/?/
|
156
|
+
|
157
|
+
def detect_funding_uri(spec)
|
158
|
+
if match = spec.homepage.match(GITHUB_PROJECT)
|
159
|
+
account = match[:account]
|
160
|
+
|
161
|
+
funding_uri = "https://github.com/sponsors/#{account}/"
|
162
|
+
|
163
|
+
if valid_uri?(funding_uri)
|
164
|
+
return funding_uri
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def detect_documentation_uri(spec)
|
170
|
+
if match = spec.homepage.match(GITHUB_PROJECT)
|
171
|
+
account = match[:account]
|
172
|
+
project = match[:project]
|
173
|
+
|
174
|
+
documentation_uri = "https://#{account}.github.io/#{project}/"
|
175
|
+
|
176
|
+
if valid_uri?(documentation_uri)
|
177
|
+
return documentation_uri
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
data/lib/bake/modernize.rb
CHANGED
@@ -33,7 +33,7 @@ module Bake
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def self.copy_template(source_path, destination_path)
|
36
|
-
glob = Build::Files::Glob.new(source_path, '
|
36
|
+
glob = Build::Files::Glob.new(source_path, '**/*')
|
37
37
|
|
38
38
|
glob.each do |path|
|
39
39
|
full_path = File.join(destination_path, path.relative_path)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
name: Development
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
runs-on: ${{matrix.os}}-latest
|
8
|
+
continue-on-error: ${{matrix.experimental}}
|
9
|
+
|
10
|
+
strategy:
|
11
|
+
matrix:
|
12
|
+
os:
|
13
|
+
- ubuntu
|
14
|
+
- macos
|
15
|
+
|
16
|
+
ruby:
|
17
|
+
- 2.5
|
18
|
+
- 2.6
|
19
|
+
- 2.7
|
20
|
+
|
21
|
+
experimental: [false]
|
22
|
+
env: [""]
|
23
|
+
|
24
|
+
include:
|
25
|
+
- os: ubuntu
|
26
|
+
ruby: truffleruby
|
27
|
+
experimental: true
|
28
|
+
- os: ubuntu
|
29
|
+
ruby: jruby
|
30
|
+
experimental: true
|
31
|
+
- os: ubuntu
|
32
|
+
ruby: head
|
33
|
+
experimental: true
|
34
|
+
|
35
|
+
steps:
|
36
|
+
- uses: actions/checkout@v2
|
37
|
+
- uses: ruby/setup-ruby@v1
|
38
|
+
with:
|
39
|
+
ruby-version: ${{matrix.ruby}}
|
40
|
+
|
41
|
+
- name: Install dependencies
|
42
|
+
run: ${{matrix.env}} bundle install
|
43
|
+
|
44
|
+
- name: Run tests
|
45
|
+
timeout-minutes: 5
|
46
|
+
run: ${{matrix.env}} bundle exec rspec
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# #{title}
|
2
|
+
|
3
|
+
#{description}
|
4
|
+
|
5
|
+
[![Development](https://github.com/#{account}/#{project}/workflows/Development/badge.svg)](https://github.com/#{account}/#{project}/actions?workflow=Development)
|
6
|
+
|
7
|
+
## Motivation
|
8
|
+
|
9
|
+
#{motivation}
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Please see the [project documentation](https://#{account}.github.io/#{project}/) or run it locally using `bake utopia:project:serve`.
|
14
|
+
|
15
|
+
## Contributing
|
16
|
+
|
17
|
+
We welcome contributions to this project.
|
18
|
+
|
19
|
+
1. Fork it
|
20
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
21
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
22
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
23
|
+
5. Create new Pull Request
|
24
|
+
|
25
|
+
## License
|
26
|
+
|
27
|
+
Released under the MIT license.
|
28
|
+
|
29
|
+
Copyright, 2020, by [Samuel G. D. Williams](http://www.codeotaku.com).
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
32
|
+
of this software and associated documentation files (the "Software"), to deal
|
33
|
+
in the Software without restriction, including without limitation the rights
|
34
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
35
|
+
copies of the Software, and to permit persons to whom the Software is
|
36
|
+
furnished to do so, subject to the following conditions:
|
37
|
+
|
38
|
+
The above copyright notice and this permission notice shall be included in
|
39
|
+
all copies or substantial portions of the Software.
|
40
|
+
|
41
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
42
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
43
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
44
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
45
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
46
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
47
|
+
THE SOFTWARE.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bake-modernize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async-http
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: build-files
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '1.6'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '1.6'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bake-bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,8 +72,15 @@ executables: []
|
|
72
72
|
extensions: []
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
|
+
- bake/modernize.rb
|
76
|
+
- bake/modernize/actions.rb
|
77
|
+
- bake/modernize/gemfile.rb
|
78
|
+
- bake/modernize/gemspec.rb
|
75
79
|
- lib/bake/modernize.rb
|
76
80
|
- lib/bake/modernize/version.rb
|
81
|
+
- template/actions/.github/workflows/development.yml
|
82
|
+
- template/editorconfig/.editorconfig
|
83
|
+
- template/readme/README.md
|
77
84
|
homepage: https://github.com/ioquatix/bake-modernize
|
78
85
|
licenses:
|
79
86
|
- MIT
|