bake-modernize 0.2.0 → 0.2.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: 75271407b97ab96706e68b107d007bbfa046806ceae4e724a212da77eed2441e
4
- data.tar.gz: e8df139fdcda5491b67644d3fe4e5cf3304f49336eec48387813d7a90558edd0
3
+ metadata.gz: 6785dc90dc6b32261961f26ab0916074320227778d02035697a734fc5a59d3e4
4
+ data.tar.gz: a2aa0708cf930d71c899818529f83c73a41fda8ee12bafd1f566f84a0a247170
5
5
  SHA512:
6
- metadata.gz: 4a6abd81f19428b1528550cf0a6ece16dc320607055c8eb3415d6e3ed15c388b9bd3716d48509eac55198deeb6aa34806df68e85e91ef07b15995fa41b15f7da
7
- data.tar.gz: b6b5b87f2be7f43a8a7c53e58f6324c20cdc18c364c92908772cdd33e391b15513806f7b79a16be16ca54abcdc86c9e48e4aa84234432b8e891f471c188e023c
6
+ metadata.gz: cbe6b4c8e3122c153ad68d086e26b2aa16d3eb2b06aa07b8062a7e29b6e5797d1f77d0393748be6af95dfdb5441e730411f96c949e1b77efed8672a44e2a22d2
7
+ data.tar.gz: 6c8bd8d3cb2acf82336e58493c72e74e7541b9b29ef25991f130811434f6789ce6dc2224ff906c4ceda65cf7e7e6cf3667c1a1d434227ea38f1aa4536d9563e2
@@ -1,4 +1,4 @@
1
1
 
2
2
  def modernize
3
- call('modernize:actions', 'modernize:gemfile', 'modernize:gemspec')
3
+ call('modernize:actions', 'modernize:editorconfig', 'modernize:gemfile', 'modernize:gemspec')
4
4
  end
@@ -1,5 +1,7 @@
1
1
 
2
2
  require 'bake/modernize'
3
+ require 'rugged'
4
+ require 'markly'
3
5
 
4
6
  def actions
5
7
  update(root: Dir.pwd)
@@ -14,4 +16,58 @@ def update(root:)
14
16
 
15
17
  template_root = Bake::Modernize.template_path_for('actions')
16
18
  Bake::Modernize.copy_template(template_root, root)
19
+
20
+ readme_path = File.expand_path("README.md", root)
21
+ repository_url = self.repository_url(root)
22
+ self.update_badges(readme_path, repository_url)
23
+ end
24
+
25
+ private
26
+
27
+ def repository_url(root)
28
+ repository = Rugged::Repository.discover(root)
29
+ git_url = repository.remotes['origin'].url
30
+
31
+ if match = git_url.match(/@(?<url>.*?):(?<path>.*?)(\.git)?\z/)
32
+ return "https://#{match[:url]}/#{match[:path]}"
33
+ end
34
+ end
35
+
36
+ def badge_for(repository_url = self.repository_url)
37
+ "[![Development Status](#{repository_url}/workflows/Development/badge.svg)](#{repository_url}/actions?workflow=Development)"
38
+ end
39
+
40
+ def badge?(node)
41
+ return false unless node.type == :link
42
+ return node.all?{|child| child.type == :image}
43
+ end
44
+
45
+ def badges?(node)
46
+ node.any?{|child| badge?(child)}
47
+ end
48
+
49
+ def update_badges(readme_path, repository_url)
50
+ root = Markly.parse(File.read(readme_path))
51
+
52
+ node = root.first_child
53
+
54
+ # Skip heading:
55
+ node = node.next if node.type == :header
56
+
57
+ replacement = Markly.parse(badge_for(repository_url))
58
+
59
+ # We are looking for the first paragraph which contains only links, which contain one image.
60
+ while node
61
+ if badges?(node)
62
+ node = node.replace(replacement.first_child)
63
+ break
64
+ elsif node.type == :header
65
+ node.insert_before(replacement.first_child)
66
+ break
67
+ end
68
+
69
+ node = node.next
70
+ end
71
+
72
+ File.write(readme_path, root.to_markdown(width: 0))
17
73
  end
@@ -0,0 +1,17 @@
1
+
2
+ require 'bake/modernize'
3
+
4
+ def editorconfig
5
+ update(root: Dir.pwd)
6
+ end
7
+
8
+ def update(root:)
9
+ editorconfig_path = File.expand_path(".editorconfig", root)
10
+
11
+ if File.exist?(editorconfig_path)
12
+ FileUtils.rm_rf(editorconfig_path)
13
+ end
14
+
15
+ template_root = Bake::Modernize.template_path_for('editorconfig')
16
+ Bake::Modernize.copy_template(template_root, root)
17
+ end
@@ -155,7 +155,7 @@ end
155
155
  GITHUB_PROJECT = /github.com\/(?<account>.*?)\/(?<project>.*?)\/?/
156
156
 
157
157
  def detect_funding_uri(spec)
158
- if match = spec.homepage.match(GITHUB_PROJECT)
158
+ if match = spec.homepage&.match(GITHUB_PROJECT)
159
159
  account = match[:account]
160
160
 
161
161
  funding_uri = "https://github.com/sponsors/#{account}/"
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Bake
22
22
  module Modernize
23
- VERSION = "0.2.0"
23
+ VERSION = "0.2.1"
24
24
  end
25
25
  end
@@ -3,4 +3,3 @@ root = true
3
3
  [*]
4
4
  indent_style = tab
5
5
  indent_size = 2
6
-
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-29 00:00:00.000000000 Z
11
+ date: 2020-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-http
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: markly
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rugged
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: bake-bundler
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -66,14 +94,15 @@ dependencies:
66
94
  - - ">="
67
95
  - !ruby/object:Gem::Version
68
96
  version: '0'
69
- description:
70
- email:
97
+ description:
98
+ email:
71
99
  executables: []
72
100
  extensions: []
73
101
  extra_rdoc_files: []
74
102
  files:
75
103
  - bake/modernize.rb
76
104
  - bake/modernize/actions.rb
105
+ - bake/modernize/editorconfig.rb
77
106
  - bake/modernize/gemfile.rb
78
107
  - bake/modernize/gemspec.rb
79
108
  - lib/bake/modernize.rb
@@ -86,7 +115,7 @@ licenses:
86
115
  - MIT
87
116
  metadata:
88
117
  funding_uri: https://github.com/sponsors/ioquatix/
89
- post_install_message:
118
+ post_install_message:
90
119
  rdoc_options: []
91
120
  require_paths:
92
121
  - lib
@@ -102,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
131
  version: '0'
103
132
  requirements: []
104
133
  rubygems_version: 3.1.2
105
- signing_key:
134
+ signing_key:
106
135
  specification_version: 4
107
136
  summary: Automatically modernize parts of your project/gem.
108
137
  test_files: []