gem_check_updates 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +1 -1
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/exe/gcu +1 -0
- data/exe/gem-check-updates +1 -0
- data/gem_check_updates.gemspec +5 -11
- data/lib/.DS_Store +0 -0
- data/lib/gem_check_updates/.DS_Store +0 -0
- data/lib/gem_check_updates/gem.rb +38 -10
- data/lib/gem_check_updates/gemfile.rb +26 -47
- data/lib/gem_check_updates/message.rb +39 -5
- data/lib/gem_check_updates/runner.rb +46 -6
- data/lib/gem_check_updates/version.rb +3 -1
- data/lib/gem_check_updates/version_scope.rb +9 -0
- data/lib/gem_check_updates.rb +3 -0
- data/run.rb +2 -0
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0c947a224aae8d3c682bb9597f6f1f47b05a160e43b416d71b2bf0adb014a21
|
4
|
+
data.tar.gz: e78aaa5f5e0772f74ce9c49f4ef0e391b1197e37245635a0fe6c096ae5cd0cef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f4e6d7b361f8250c3d464b26cab0b97f22e0112158f7b8cd9b8bd5df8a68d06bc761d9bb28eea55738a8be03788b67efdc7bd3f91eb00b1e2ca6095549386e9
|
7
|
+
data.tar.gz: cf6a3236dc051a4dd051cd55c37ef22480ec3779663ee1d7c6b3b060775f9091851fc7acf1d226b0a80613b8f04122e5c8302d3104443bcced1a634a314246c2
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/exe/gcu
CHANGED
data/exe/gem-check-updates
CHANGED
data/gem_check_updates.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require 'gem_check_updates/version'
|
@@ -8,18 +10,10 @@ Gem::Specification.new do |spec|
|
|
8
10
|
spec.authors = ['Yusuke Mukai']
|
9
11
|
spec.email = ['mukopikmin@gmail.com']
|
10
12
|
|
11
|
-
spec.summary = '
|
12
|
-
spec.description = 'Automatically update gems
|
13
|
+
spec.summary = 'Automatically update Gemfile'
|
14
|
+
spec.description = 'Automatically update and overwrite version of gems in Gemfile'
|
13
15
|
spec.homepage = 'https://github.com/mukopikmin/gem_check_updates'
|
14
|
-
|
15
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
16
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
17
|
-
if spec.respond_to?(:metadata)
|
18
|
-
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
19
|
-
else
|
20
|
-
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
21
|
-
'public gem pushes.'
|
22
|
-
end
|
16
|
+
spec.licenses = ['MIT']
|
23
17
|
|
24
18
|
# Specify which files should be added to the gem when it is released.
|
25
19
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
data/lib/.DS_Store
CHANGED
Binary file
|
Binary file
|
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GemCheckUpdates
|
2
|
-
RUBYGEMS_API = 'https://rubygems.org/api/v1/versions'
|
4
|
+
RUBYGEMS_API = 'https://rubygems.org/api/v1/versions'
|
3
5
|
|
4
6
|
class Gem
|
5
7
|
attr_reader :name,
|
@@ -7,27 +9,53 @@ module GemCheckUpdates
|
|
7
9
|
:current_version,
|
8
10
|
:version_range
|
9
11
|
|
10
|
-
def initialize(name: nil,
|
12
|
+
def initialize(name: nil,
|
13
|
+
current_version: nil,
|
14
|
+
version_range: nil,
|
15
|
+
update_scope: GemCheckUpdates::VersionScope::MAJOR)
|
11
16
|
@name = name
|
12
17
|
@current_version = current_version
|
13
18
|
@version_range = version_range
|
14
19
|
|
15
|
-
check_update!
|
20
|
+
check_update!(update_scope)
|
16
21
|
end
|
17
22
|
|
18
23
|
def update_available?
|
19
|
-
!@latest_version.nil? &&
|
24
|
+
!@latest_version.nil? &&
|
25
|
+
!@current_version.nil? &&
|
26
|
+
@current_version != '0' &&
|
27
|
+
@latest_version > @current_version
|
20
28
|
end
|
21
29
|
|
22
|
-
def check_update!
|
23
|
-
response = RestClient.get("#{RUBYGEMS_API}/#{name}
|
24
|
-
|
30
|
+
def check_update!(update_scope)
|
31
|
+
response = RestClient.get("#{RUBYGEMS_API}/#{name}.json")
|
32
|
+
versions = JSON.parse(response.body)
|
33
|
+
|
34
|
+
@latest_version = scoped_latest_version(versions, update_scope)
|
25
35
|
|
26
|
-
|
27
|
-
rescue StandardError
|
36
|
+
self
|
37
|
+
rescue StandardError => e
|
28
38
|
@latest_version = nil
|
29
39
|
|
30
|
-
|
40
|
+
GemCheckUpdates::Message.out("Failed to check version \"#{@name}\".".red)
|
41
|
+
end
|
42
|
+
|
43
|
+
def scoped_latest_version(versions, scope)
|
44
|
+
numbers = versions.map { |v| v['number'] }
|
45
|
+
current_major, current_minor = @current_version.split('.')
|
46
|
+
|
47
|
+
case scope
|
48
|
+
when GemCheckUpdates::VersionScope::MINOR
|
49
|
+
numbers.select { |n| n.split('.').first == current_major }.max
|
50
|
+
when GemCheckUpdates::VersionScope::PATCH
|
51
|
+
numbers.select do |n|
|
52
|
+
major, minor = n.split('.')
|
53
|
+
major == current_major && minor == current_minor
|
54
|
+
end.max
|
55
|
+
else
|
56
|
+
# This branch is equal to specifying major updates
|
57
|
+
numbers.max
|
58
|
+
end
|
31
59
|
end
|
32
60
|
end
|
33
61
|
end
|
@@ -1,86 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GemCheckUpdates
|
2
4
|
class Gemfile
|
3
|
-
attr_reader :gems
|
5
|
+
attr_reader :file, :file_backup, :gems
|
4
6
|
|
5
|
-
def initialize(file)
|
7
|
+
def initialize(file, update_scope)
|
6
8
|
@file = file
|
7
|
-
@
|
8
|
-
|
9
|
-
|
10
|
-
def file_backup
|
11
|
-
"#{@file}.backup"
|
9
|
+
@file_backup = "#{@file}.backup"
|
10
|
+
@gems = parse(update_scope)
|
12
11
|
end
|
13
12
|
|
14
13
|
def backup
|
15
|
-
FileUtils.cp(@file, file_backup)
|
14
|
+
FileUtils.cp(@file, @file_backup)
|
16
15
|
end
|
17
16
|
|
18
17
|
def restore
|
19
|
-
FileUtils.mv(file_backup, @file)
|
20
|
-
remove_backup
|
18
|
+
FileUtils.mv(@file_backup, @file)
|
21
19
|
end
|
22
20
|
|
23
21
|
def remove_backup
|
24
|
-
FileUtils.rm(file_backup)
|
22
|
+
FileUtils.rm(@file_backup)
|
25
23
|
end
|
26
24
|
|
27
|
-
def parse
|
25
|
+
def parse(update_scope)
|
28
26
|
gems = Bundler::Definition.build(@file, nil, nil).dependencies.map do |gem|
|
29
|
-
|
27
|
+
GemCheckUpdates::Message.out('.')
|
30
28
|
|
31
29
|
name = gem.name
|
32
30
|
version_range, version = gem.requirements_list.first.split(' ')
|
33
31
|
|
34
32
|
Gem.new(name: name,
|
35
33
|
current_version: version,
|
36
|
-
version_range: version_range
|
34
|
+
version_range: version_range,
|
35
|
+
update_scope: update_scope)
|
37
36
|
end
|
38
37
|
|
39
|
-
|
40
|
-
puts
|
38
|
+
GemCheckUpdates::Message.out("\n\n")
|
41
39
|
|
42
40
|
gems
|
43
41
|
end
|
44
42
|
|
45
43
|
def update
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
current.each_line do |line|
|
51
|
-
if matcher = line.match(/gem ['"](.+?)['"]\s*,\s*['"][>=|~>]*\s+(.+?)['"]/)
|
52
|
-
_, name, old_version = *matcher
|
53
|
-
target = @gems.find { |gem| gem.name == name }
|
54
|
-
|
55
|
-
line.gsub!(old_version, target.latest_version) unless target.nil?
|
56
|
-
end
|
57
|
-
|
58
|
-
updated.puts(line)
|
59
|
-
end
|
44
|
+
gemfile_lines = []
|
45
|
+
File.open(@file) do |current|
|
46
|
+
current.each_line do |line|
|
47
|
+
gemfile_lines << line
|
60
48
|
end
|
61
49
|
end
|
62
50
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
51
|
+
File.open(@file, 'w') do |updated|
|
52
|
+
gemfile_lines.each do |line|
|
53
|
+
if matcher = line.match(/gem ['"](.+?)['"]\s*,\s*['"][>=|~>]*\s+(.+?)['"]/)
|
54
|
+
_, name, old_version = *matcher
|
55
|
+
target = @gems.find { |gem| gem.name == name }
|
69
56
|
|
70
|
-
|
71
|
-
|
72
|
-
puts 'If you want to apply these updates, run command with option \'-a\'.'
|
73
|
-
puts ' (Caution: This option will overwrite your Gemfile)'.red
|
74
|
-
puts
|
57
|
+
line.gsub!(old_version, target.latest_version) unless target.nil?
|
58
|
+
end
|
75
59
|
|
76
|
-
|
77
|
-
if gem.update_available?
|
78
|
-
puts " #{gem.name} \"#{gem.version_range} #{gem.current_version}\" → \"#{gem.version_range} #{gem.latest_version.green}\""
|
60
|
+
updated.puts(line)
|
79
61
|
end
|
80
62
|
end
|
81
|
-
|
82
|
-
puts
|
83
|
-
puts
|
84
63
|
end
|
85
64
|
end
|
86
65
|
end
|
@@ -1,9 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GemCheckUpdates
|
2
|
-
|
3
|
-
|
4
|
-
|
4
|
+
class Message
|
5
|
+
def self.out(str)
|
6
|
+
return if ENV['RACK_ENV'] == 'test'
|
7
|
+
|
8
|
+
print str
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.updatable_gems(gemfile, scope)
|
12
|
+
out <<~VERSIONS
|
13
|
+
Checking #{scope.green} updates are completed.
|
14
|
+
|
15
|
+
You can update following newer gems.
|
16
|
+
If you want to apply these updates, run command with option \'-a\'.
|
17
|
+
#{'(Caution: This option will overwrite your Gemfile)'.red}
|
18
|
+
|
19
|
+
#{gems_version_diff(gemfile)}
|
20
|
+
|
21
|
+
|
22
|
+
VERSIONS
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.update_completed(gemfile, scope)
|
26
|
+
out <<~VERSIONS
|
27
|
+
Checking #{scope.green} updates are completed.
|
28
|
+
|
29
|
+
Following gems have been updated!
|
30
|
+
|
31
|
+
#{gems_version_diff(gemfile)}
|
32
|
+
|
33
|
+
|
34
|
+
VERSIONS
|
35
|
+
end
|
5
36
|
|
6
|
-
|
7
|
-
|
37
|
+
def self.gems_version_diff(gemfile)
|
38
|
+
gemfile.gems
|
39
|
+
.select(&:update_available?)
|
40
|
+
.map { |gem| " #{gem.name} \"#{gem.version_range} #{gem.current_version}\" → \"#{gem.version_range} #{gem.latest_version.green}\"" }.join("\n")
|
41
|
+
end
|
8
42
|
end
|
9
43
|
end
|
@@ -1,13 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GemCheckUpdates
|
2
4
|
class Runner
|
3
5
|
def self.run(argv)
|
4
6
|
options = parse_options(argv)
|
5
|
-
|
7
|
+
scope = update_scope(options)
|
8
|
+
gemfile = Gemfile.new(options[:file], scope)
|
6
9
|
|
7
10
|
if options[:apply]
|
8
|
-
|
11
|
+
begin
|
12
|
+
gemfile.backup
|
13
|
+
gemfile.update
|
14
|
+
gemfile.remove_backup
|
15
|
+
|
16
|
+
GemCheckUpdates::Message.update_completed(gemfile, scope)
|
17
|
+
rescue StandardError => e
|
18
|
+
gemfile.restore
|
19
|
+
|
20
|
+
print e.message.red
|
21
|
+
end
|
9
22
|
else
|
10
|
-
gemfile
|
23
|
+
GemCheckUpdates::Message.updatable_gems(gemfile, scope)
|
11
24
|
end
|
12
25
|
end
|
13
26
|
|
@@ -15,9 +28,11 @@ module GemCheckUpdates
|
|
15
28
|
options = {
|
16
29
|
file: './Gemfile',
|
17
30
|
apply: false,
|
18
|
-
|
19
|
-
|
20
|
-
|
31
|
+
major: true,
|
32
|
+
minor: true,
|
33
|
+
patch: true
|
34
|
+
# keep_backup: false,
|
35
|
+
# verbose: false
|
21
36
|
}
|
22
37
|
|
23
38
|
OptionParser.new do |opt|
|
@@ -25,11 +40,36 @@ module GemCheckUpdates
|
|
25
40
|
|
26
41
|
opt.on('-f Gemfile', '--file', "Path to Gemfile (default: #{options[:file]})") { |v| options[:file] = v }
|
27
42
|
opt.on('-a', '--apply', "Apply updates (default: #{options[:apply]})") { |v| options[:apply] = v }
|
43
|
+
opt.on('--major', "Update major version (default: #{options[:major]})") do |v|
|
44
|
+
options[:major] = v
|
45
|
+
options[:minor] = !v
|
46
|
+
options[:patch] = !v
|
47
|
+
end
|
48
|
+
opt.on('--minor', "Update minor version (default: #{options[:minor]})") do |v|
|
49
|
+
options[:major] = !v
|
50
|
+
options[:minor] = v
|
51
|
+
options[:patch] = !v
|
52
|
+
end
|
53
|
+
opt.on('--patch', "Update patch version (default: #{options[:patch]})") do |v|
|
54
|
+
options[:major] = !v
|
55
|
+
options[:minor] = !v
|
56
|
+
options[:patch] = v
|
57
|
+
end
|
28
58
|
|
29
59
|
opt.parse!(argv)
|
30
60
|
end
|
31
61
|
|
32
62
|
options
|
33
63
|
end
|
64
|
+
|
65
|
+
def self.update_scope(options)
|
66
|
+
if !options[:major] && options[:minor]
|
67
|
+
GemCheckUpdates::VersionScope::MINOR
|
68
|
+
elsif !options[:major] && !options[:minor] && options[:patch]
|
69
|
+
GemCheckUpdates::VersionScope::PATCH
|
70
|
+
else
|
71
|
+
GemCheckUpdates::VersionScope::MAJOR
|
72
|
+
end
|
73
|
+
end
|
34
74
|
end
|
35
75
|
end
|
data/lib/gem_check_updates.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler'
|
2
4
|
require 'fileutils'
|
3
5
|
require 'optparse'
|
@@ -6,6 +8,7 @@ require 'colored'
|
|
6
8
|
require 'json'
|
7
9
|
|
8
10
|
require 'gem_check_updates/version'
|
11
|
+
require 'gem_check_updates/version_scope'
|
9
12
|
require 'gem_check_updates/message'
|
10
13
|
require 'gem_check_updates/gemfile'
|
11
14
|
require 'gem_check_updates/gem'
|
data/run.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_check_updates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yusuke Mukai
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '2.0'
|
111
|
-
description: Automatically update gems
|
111
|
+
description: Automatically update and overwrite version of gems in Gemfile
|
112
112
|
email:
|
113
113
|
- mukopikmin@gmail.com
|
114
114
|
executables:
|
@@ -132,16 +132,18 @@ files:
|
|
132
132
|
- gem_check_updates.gemspec
|
133
133
|
- lib/.DS_Store
|
134
134
|
- lib/gem_check_updates.rb
|
135
|
+
- lib/gem_check_updates/.DS_Store
|
135
136
|
- lib/gem_check_updates/gem.rb
|
136
137
|
- lib/gem_check_updates/gemfile.rb
|
137
138
|
- lib/gem_check_updates/message.rb
|
138
139
|
- lib/gem_check_updates/runner.rb
|
139
140
|
- lib/gem_check_updates/version.rb
|
141
|
+
- lib/gem_check_updates/version_scope.rb
|
140
142
|
- run.rb
|
141
143
|
homepage: https://github.com/mukopikmin/gem_check_updates
|
142
|
-
licenses:
|
143
|
-
|
144
|
-
|
144
|
+
licenses:
|
145
|
+
- MIT
|
146
|
+
metadata: {}
|
145
147
|
post_install_message:
|
146
148
|
rdoc_options: []
|
147
149
|
require_paths:
|
@@ -161,5 +163,5 @@ rubyforge_project:
|
|
161
163
|
rubygems_version: 2.7.7
|
162
164
|
signing_key:
|
163
165
|
specification_version: 4
|
164
|
-
summary:
|
166
|
+
summary: Automatically update Gemfile
|
165
167
|
test_files: []
|