bake-modernize 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa6740ccbd94a52cf7576969bc029688cea94874a0452d916a32567b8a6ecae4
4
- data.tar.gz: 335912cb4686761acd60aa98690ab172d541df80c07c172d2487cf7ac60b4ac5
3
+ metadata.gz: 47cb1bb4393b07e797bf267f72e5ee1a68b3f37bb1cfb349aa58e204744641aa
4
+ data.tar.gz: 55f6e5f7b1780d9d2db4eda70288cbe8d8dfc75f868170db9500a1f59bf869a1
5
5
  SHA512:
6
- metadata.gz: d7cf13bf723774322f6b9a111d231b071e29d755a9ddf4838b9d77424dc56bc84cfae7a8fb5e0399a6ad2b141878d37c97a93fe5acc988c4d43f4b296cc14b5e
7
- data.tar.gz: e982f49c80e8f6b919914e7474de76062fc6346cb7dcb0b704087d661d62e9a52690361c044edebbf20ebd0a6a429355bde879da892109ce33662cb5391443ba
6
+ metadata.gz: a0bf44bfc8f5d3c77621f40f3577216904c576d419c16fc689ada6078ed05abe89dbf96a01c1bfa4494eceae5535abde64d4d6b681736f93a1aeb09b9bd83f10
7
+ data.tar.gz: 4bf1de6748b60cbe02aab2aa2622d591749691e6fffe2b5de7b9ff3fb2639e24ad53908fa16027b99ef481f9a9c91a1a1cbac4008cc4bdcd56868142b63fbef1
@@ -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['{#{directories.keys.join(',')}}/**/*', 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/bake/modernize.rb ADDED
@@ -0,0 +1,4 @@
1
+
2
+ def modernize
3
+ call('modernize:actions', 'modernize:gemfile', 'modernize:gemspec')
4
+ end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Bake
22
22
  module Modernize
23
- VERSION = "0.1.0"
23
+ VERSION = "0.1.1"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bake-modernize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -72,6 +72,10 @@ 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
77
81
  homepage: https://github.com/ioquatix/bake-modernize