gem_polish 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/lib/gem_polish/cli/polisher.rb +166 -0
- data/lib/gem_polish/cli.rb +7 -122
- data/lib/gem_polish/version.rb +1 -1
- data/spec/lib/gem_polish/cli/polisher_spec.rb +90 -0
- data/spec/lib/gem_polish/cli/versioner_spec.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac3062847f504d97ef2f042caeb28d8260568057
|
4
|
+
data.tar.gz: d715b9cbc2c326f9c89ff81007deb3a3a21d064e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9053b78b5885b27d678fbbd900f544d81f822dd2950418559b1e2d99471757a74893eb7c322cbd0c193185210989b7c221a169ddcfdc7f6eb8f2a1daffe3ba8f
|
7
|
+
data.tar.gz: 759dfe1c8200cbee3bf328ba969832450589cf79fb1a1e377b8067c3fa9938060b8cb3bb08a5a096972118cca0ce5c383a96bf126f9e17808a6103ea77d7070f
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module GemPolish
|
4
|
+
class CLI::Polisher
|
5
|
+
def initialize(options, thor)
|
6
|
+
@options = options
|
7
|
+
@thor = thor
|
8
|
+
@defaults = set_defaults
|
9
|
+
end
|
10
|
+
|
11
|
+
def set_defaults
|
12
|
+
defaults_disabled? ? {} : read_from_conf_file
|
13
|
+
end
|
14
|
+
|
15
|
+
def insert_description
|
16
|
+
if description
|
17
|
+
@thor.gsub_file(gemspec, /TODO:.*summary.*(?=})/, description)
|
18
|
+
@thor.gsub_file(readme, /TODO:.*gem description/, description)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def insert_badges
|
23
|
+
if badges
|
24
|
+
@thor.insert_into_file(readme, after: /^#\s.*\n/, force: false) { badge_links }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def insert_coveralls
|
29
|
+
if parse_opt(:coveralls)
|
30
|
+
@thor.prepend_file(spec_helper, template(:coveralls) + "\n")
|
31
|
+
add_dev_dependency('simplecov', '0.7')
|
32
|
+
@thor.append_file(gemfile, %{gem 'coveralls', require: false})
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def insert_rspec_conf
|
37
|
+
if parse_opt(:rspec_conf)
|
38
|
+
@thor.append_file(spec_helper, "\n" + template(:rspec_configuration))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def insert_travis
|
43
|
+
if t = parse_opt(:travis)
|
44
|
+
@thor.say_status :rewrite, relative_destination(travis)
|
45
|
+
File.write(travis, YAML.dump(travis_content(t)))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def git_user
|
50
|
+
user = @options[:git_user] || read_from_git_config
|
51
|
+
user.empty? ? "TODO: Write your name" : user
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def description
|
57
|
+
@description ||= @options[:description]
|
58
|
+
end
|
59
|
+
|
60
|
+
BADGE_NAMES = {
|
61
|
+
'badge_fury' => 'Version',
|
62
|
+
'gemnasium' => 'Dependencies',
|
63
|
+
'travis' => 'Build Status',
|
64
|
+
'coveralls' => 'Coverage',
|
65
|
+
'code_climate' => 'Code Climate'
|
66
|
+
}
|
67
|
+
|
68
|
+
def badges
|
69
|
+
@badges ||= parse_opt(:badges)
|
70
|
+
end
|
71
|
+
|
72
|
+
def badge_links
|
73
|
+
"\n#{badges.map { |badge| badge_link(badge) }.join("\n")}\n"
|
74
|
+
end
|
75
|
+
|
76
|
+
def badge_link(badge)
|
77
|
+
path = "http://allthebadges.io/#{git_user}/#{gem_name}/#{badge}"
|
78
|
+
"[![#{BADGE_NAMES[badge]}](#{path}.png)](#{path})"
|
79
|
+
end
|
80
|
+
|
81
|
+
def read_from_git_config
|
82
|
+
# can it return nil?
|
83
|
+
`git config user.name`.to_s.chomp
|
84
|
+
end
|
85
|
+
|
86
|
+
def parse_opt(opt)
|
87
|
+
@options[opt] || @defaults[opt]
|
88
|
+
end
|
89
|
+
|
90
|
+
def read_from_conf_file
|
91
|
+
conf_file_present? ? load_conf_file : {}
|
92
|
+
end
|
93
|
+
|
94
|
+
def defaults_disabled?
|
95
|
+
@options[:no_default]
|
96
|
+
end
|
97
|
+
|
98
|
+
def conf_file_present?
|
99
|
+
File.exist?(conf_file)
|
100
|
+
end
|
101
|
+
|
102
|
+
def load_conf_file
|
103
|
+
YAML.load(File.read(conf_file)).each_with_object({}) do |(k, v), h|
|
104
|
+
h[k.to_sym] = v
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def add_dev_dependency(gem, version = nil)
|
109
|
+
total_size = File.size(gemspec)
|
110
|
+
pos_before_end = total_size - 4
|
111
|
+
insertion = %{ spec.add_development_dependency "#{gem}"}
|
112
|
+
return if File.read(gemspec).match(/#{insertion}/)
|
113
|
+
insertion << %{, "~> #{version}"} if version
|
114
|
+
|
115
|
+
@thor.say_status :append, relative_destination(gemspec)
|
116
|
+
File.open(gemspec, 'r+') do |file|
|
117
|
+
file.seek(pos_before_end, IO::SEEK_SET)
|
118
|
+
file.puts(insertion)
|
119
|
+
file.puts('end')
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def travis_content(opts)
|
124
|
+
c = { 'language' => 'ruby'}
|
125
|
+
c.merge((opts.is_a?(Hash) ? opts : { 'rvm' => opts }))
|
126
|
+
end
|
127
|
+
|
128
|
+
def relative_destination(dest)
|
129
|
+
d = File.expand_path(dest, @thor.destination_root)
|
130
|
+
@thor.relative_to_original_destination_root(d)
|
131
|
+
end
|
132
|
+
|
133
|
+
TEMPLATE_DIR = File.expand_path('../../../templates', __FILE__)
|
134
|
+
def template(name)
|
135
|
+
File.read("#{TEMPLATE_DIR}/#{name}.template")
|
136
|
+
end
|
137
|
+
|
138
|
+
def conf_file
|
139
|
+
"#{ENV['HOME']}/.gem_polish.yml"
|
140
|
+
end
|
141
|
+
|
142
|
+
def gem_name
|
143
|
+
File.basename(Dir.pwd)
|
144
|
+
end
|
145
|
+
|
146
|
+
def travis
|
147
|
+
".travis.yml"
|
148
|
+
end
|
149
|
+
|
150
|
+
def spec_helper
|
151
|
+
"spec/spec_helper.rb"
|
152
|
+
end
|
153
|
+
|
154
|
+
def gemspec
|
155
|
+
"#{gem_name}.gemspec"
|
156
|
+
end
|
157
|
+
|
158
|
+
def gemfile
|
159
|
+
"Gemfile"
|
160
|
+
end
|
161
|
+
|
162
|
+
def readme
|
163
|
+
"README.md"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
data/lib/gem_polish/cli.rb
CHANGED
@@ -4,6 +4,7 @@ require 'yaml'
|
|
4
4
|
module GemPolish
|
5
5
|
class CLI < Thor
|
6
6
|
|
7
|
+
require 'gem_polish/cli/polisher'
|
7
8
|
require 'gem_polish/cli/versioner'
|
8
9
|
include Thor::Actions
|
9
10
|
|
@@ -24,18 +25,12 @@ module GemPolish
|
|
24
25
|
desc: 'Bypasses ~/.gem_polish.yml. Defaults to false'
|
25
26
|
def polish(name = '.')
|
26
27
|
inside name do
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
insert_badges(badges, git_user_name, gem_name) if badges
|
35
|
-
insert_description(description) if description
|
36
|
-
insert_coveralls if parse_opt(:coverage, options, default)
|
37
|
-
insert_rspec_conf if parse_opt(:rspec_conf, options, default)
|
38
|
-
insert_travis(travis_opts) if travis_opts
|
28
|
+
p = Polisher.new(options, self)
|
29
|
+
p.insert_description
|
30
|
+
p.insert_badges
|
31
|
+
p.insert_coveralls
|
32
|
+
p.insert_rspec_conf
|
33
|
+
p.insert_travis
|
39
34
|
end
|
40
35
|
end
|
41
36
|
|
@@ -66,116 +61,6 @@ module GemPolish
|
|
66
61
|
end
|
67
62
|
end
|
68
63
|
end
|
69
|
-
|
70
|
-
no_commands do
|
71
|
-
def parse_opt(opt, opts, default)
|
72
|
-
opts[opt] || default[opt]
|
73
|
-
end
|
74
|
-
|
75
|
-
def extract_git_user(options)
|
76
|
-
user = options[:git_user] || `git config user.name`.chomp
|
77
|
-
user.empty? ? "TODO: Write your name" : user
|
78
|
-
end
|
79
|
-
|
80
|
-
def insert_description(description)
|
81
|
-
gsub_file(gemspec, /TODO:.*summary.*(?=})/, description)
|
82
|
-
gsub_file(readme, /TODO:.*gem description/, description)
|
83
|
-
end
|
84
|
-
|
85
|
-
BADGE_NAMES = {
|
86
|
-
'badge_fury' => 'Version',
|
87
|
-
'gemnasium' => 'Dependencies',
|
88
|
-
'travis' => 'Build Status',
|
89
|
-
'coveralls' => 'Coverage',
|
90
|
-
'code_climate' => 'Code Climate'
|
91
|
-
}
|
92
|
-
|
93
|
-
def insert_badges(badges, user, gem)
|
94
|
-
insert_into_file(readme, after: /^#\s.*\n/, force: false) do
|
95
|
-
"\n#{badges.map { |badge| badge_link(badge, user, gem) }.join("\n")}\n"
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def badge_link(badge, user, gem)
|
100
|
-
path = "http://allthebadges.io/#{user}/#{gem}/#{badge}"
|
101
|
-
"[![#{BADGE_NAMES[badge]}](#{path}.png)](#{path})"
|
102
|
-
end
|
103
|
-
|
104
|
-
def insert_coveralls
|
105
|
-
prepend_file(spec_helper, read_template(:coveralls) + "\n")
|
106
|
-
add_dev_dependency('simplecov', '0.7')
|
107
|
-
append_file(gemfile, %{gem 'coveralls', require: false})
|
108
|
-
end
|
109
|
-
|
110
|
-
def insert_rspec_conf
|
111
|
-
append_file(spec_helper, "\n" + read_template(:rspec_configuration))
|
112
|
-
end
|
113
|
-
|
114
|
-
def insert_travis(opts)
|
115
|
-
say_status :rewrite, relative_destination(travis)
|
116
|
-
File.write(travis, YAML.dump(travis_content(opts)))
|
117
|
-
end
|
118
|
-
|
119
|
-
def travis_content(opts)
|
120
|
-
c = { 'language' => 'ruby'}
|
121
|
-
c.merge((opts.is_a?(Hash) ? opts : { 'rvm' => opts }))
|
122
|
-
end
|
123
|
-
|
124
|
-
def relative_destination(dest)
|
125
|
-
d = File.expand_path(dest, destination_root)
|
126
|
-
relative_to_original_destination_root(d)
|
127
|
-
end
|
128
|
-
|
129
|
-
def def_conf
|
130
|
-
conf_file = "#{ENV['HOME']}/.gem_polish.yml"
|
131
|
-
conf = File.exists?(conf_file) ? YAML.load(File.read(conf_file)) : {}
|
132
|
-
conf.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
|
133
|
-
end
|
134
|
-
|
135
|
-
def gem_name
|
136
|
-
File.basename(Dir.pwd)
|
137
|
-
end
|
138
|
-
|
139
|
-
def travis
|
140
|
-
".travis.yml"
|
141
|
-
end
|
142
|
-
|
143
|
-
def spec_helper
|
144
|
-
"spec/spec_helper.rb"
|
145
|
-
end
|
146
|
-
|
147
|
-
def gemspec
|
148
|
-
"#{gem_name}.gemspec"
|
149
|
-
end
|
150
|
-
|
151
|
-
def gemfile
|
152
|
-
"Gemfile"
|
153
|
-
end
|
154
|
-
|
155
|
-
def readme
|
156
|
-
"README.md"
|
157
|
-
end
|
158
|
-
|
159
|
-
TEMPLATE_DIR = File.expand_path('../../templates', __FILE__)
|
160
|
-
def read_template(name)
|
161
|
-
File.read("#{TEMPLATE_DIR}/#{name}.template")
|
162
|
-
end
|
163
|
-
|
164
|
-
def add_dev_dependency(gem, version = nil)
|
165
|
-
total_size = File.size(gemspec)
|
166
|
-
pos_before_end = total_size - 4
|
167
|
-
insertion = %{ spec.add_development_dependency "#{gem}"}
|
168
|
-
return if File.read(gemspec).match(/#{insertion}/)
|
169
|
-
insertion << %{, "~> #{version}"} if version
|
170
|
-
|
171
|
-
say_status :append, relative_destination(gemspec)
|
172
|
-
File.open(gemspec, 'r+') do |file|
|
173
|
-
file.seek(pos_before_end, IO::SEEK_SET)
|
174
|
-
file.puts(insertion)
|
175
|
-
file.puts('end')
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
64
|
end
|
180
65
|
end
|
181
66
|
|
data/lib/gem_polish/version.rb
CHANGED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GemPolish::CLI::Polisher do
|
4
|
+
let(:thor) do
|
5
|
+
double(
|
6
|
+
gsub_file: true, insert_into_file: true, say_status: true,
|
7
|
+
append_file: true, prepend_file: true
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
class GemPolish::CLI::Polisher
|
12
|
+
# we need to override this, otherwise it really reads
|
13
|
+
# the conf file
|
14
|
+
def load_conf_file
|
15
|
+
{}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def new_polisher(options)
|
20
|
+
GemPolish::CLI::Polisher.new(options, thor)
|
21
|
+
# need to stub this, otherwise it really reads from the conf file
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#set_defaults" do
|
25
|
+
it "returns empty if --no-default was passed" do
|
26
|
+
polisher = new_polisher(no_default: true)
|
27
|
+
polisher.set_defaults.should be_empty
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns empty when no conf file is present" do
|
31
|
+
polisher = new_polisher({})
|
32
|
+
polisher.stub(conf_file_present?: false)
|
33
|
+
polisher.set_defaults.should be_empty
|
34
|
+
end
|
35
|
+
|
36
|
+
it "loads conf file when present" do
|
37
|
+
polisher = new_polisher({})
|
38
|
+
conf_file = { a: 1}
|
39
|
+
polisher.stub(load_conf_file: conf_file)
|
40
|
+
polisher.set_defaults.should == conf_file
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#insert_description" do
|
45
|
+
it "does nothing when no desciption was passed" do
|
46
|
+
polisher = new_polisher({})
|
47
|
+
thor.should_not receive(:gsub_file)
|
48
|
+
polisher.insert_description.should be_nil
|
49
|
+
end
|
50
|
+
|
51
|
+
it "inserts description in gemspec and README" do
|
52
|
+
polisher = new_polisher(description: 'test')
|
53
|
+
thor.should receive(:gsub_file).twice
|
54
|
+
polisher.insert_description
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#git_user" do
|
59
|
+
it "returns the provided git user name" do
|
60
|
+
polisher = new_polisher(git_user: 'Tester')
|
61
|
+
polisher.git_user.should == 'Tester'
|
62
|
+
end
|
63
|
+
|
64
|
+
it "tries to read from git_config when nothing was provided" do
|
65
|
+
polisher = new_polisher({})
|
66
|
+
polisher.stub(read_from_git_config: 'Gitter')
|
67
|
+
polisher.git_user.should == 'Gitter'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "returns a todo when there is no user in git config" do
|
71
|
+
polisher = new_polisher({})
|
72
|
+
polisher.stub(read_from_git_config: '')
|
73
|
+
polisher.git_user.should =~ /TODO/
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#insert_badges" do
|
78
|
+
it "does nothing when no badges were passed" do
|
79
|
+
polisher = new_polisher({})
|
80
|
+
thor.should_not receive(:insert_into_file)
|
81
|
+
polisher.insert_badges
|
82
|
+
end
|
83
|
+
|
84
|
+
it "inserts badges when badges are present" do
|
85
|
+
polisher = new_polisher(badges: ['travis'])
|
86
|
+
thor.should receive(:insert_into_file)
|
87
|
+
polisher.insert_badges
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -42,7 +42,7 @@ describe GemPolish::CLI::Versioner do
|
|
42
42
|
versioner.instance_variable_set(:@version, versioner.extract_from_version_file)
|
43
43
|
end
|
44
44
|
|
45
|
-
describe "
|
45
|
+
describe "returns an updated version hash for the given bumper" do
|
46
46
|
it "bumps revision" do
|
47
47
|
res = {
|
48
48
|
'major' => 2,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_polish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LFDM
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -92,11 +92,13 @@ files:
|
|
92
92
|
- gem_polish.thor
|
93
93
|
- lib/gem_polish.rb
|
94
94
|
- lib/gem_polish/cli.rb
|
95
|
+
- lib/gem_polish/cli/polisher.rb
|
95
96
|
- lib/gem_polish/cli/versioner.rb
|
96
97
|
- lib/gem_polish/version.rb
|
97
98
|
- lib/templates/coveralls.template
|
98
99
|
- lib/templates/rspec_configuration.template
|
99
100
|
- spec/gem_polish_spec.rb
|
101
|
+
- spec/lib/gem_polish/cli/polisher_spec.rb
|
100
102
|
- spec/lib/gem_polish/cli/versioner_spec.rb
|
101
103
|
- spec/spec_helper.rb
|
102
104
|
homepage: ''
|
@@ -125,5 +127,6 @@ specification_version: 4
|
|
125
127
|
summary: Command line tool to help with gem creation and maintenance
|
126
128
|
test_files:
|
127
129
|
- spec/gem_polish_spec.rb
|
130
|
+
- spec/lib/gem_polish/cli/polisher_spec.rb
|
128
131
|
- spec/lib/gem_polish/cli/versioner_spec.rb
|
129
132
|
- spec/spec_helper.rb
|