gemsmith 9.6.0 → 10.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +3 -0
- data.tar.gz.sig +0 -0
- data/README.md +75 -67
- data/lib/gemsmith.rb +2 -1
- data/lib/gemsmith/cli.rb +27 -17
- data/lib/gemsmith/credentials.rb +6 -3
- data/lib/gemsmith/gem/module_formatter.rb +7 -9
- data/lib/gemsmith/gem/requirement.rb +4 -2
- data/lib/gemsmith/gem/specification.rb +4 -0
- data/lib/gemsmith/generators/base.rb +4 -5
- data/lib/gemsmith/generators/bundler.rb +1 -1
- data/lib/gemsmith/generators/circle_ci.rb +13 -0
- data/lib/gemsmith/generators/cli.rb +1 -1
- data/lib/gemsmith/generators/gem.rb +1 -0
- data/lib/gemsmith/generators/git_cop.rb +13 -0
- data/lib/gemsmith/generators/pragma.rb +20 -17
- data/lib/gemsmith/generators/rails.rb +3 -8
- data/lib/gemsmith/generators/rake.rb +5 -1
- data/lib/gemsmith/helpers/cli.rb +7 -4
- data/lib/gemsmith/identity.rb +1 -5
- data/lib/gemsmith/rake/builder.rb +2 -6
- data/lib/gemsmith/rake/publisher.rb +12 -6
- data/lib/gemsmith/rake/tasks.rb +8 -3
- data/lib/gemsmith/templates/%gem_name%/%gem_name%.gemspec.tt +7 -5
- data/lib/gemsmith/templates/%gem_name%/README.md.tt +15 -15
- data/lib/gemsmith/templates/%gem_name%/Rakefile.tt +1 -0
- data/lib/gemsmith/templates/%gem_name%/circle.yml.tt +11 -0
- data/lib/gemsmith/templates/%gem_name%/lib/%gem_path%/cli.rb.tt +6 -7
- data/lib/gemsmith/templates/%gem_name%/lib/%gem_path%/identity.rb.tt +1 -7
- data/lib/gemsmith/templates/%gem_name%/lib/generators/%gem_path%/install/USAGE.tt +1 -1
- data/lib/gemsmith/templates/%gem_name%/lib/generators/%gem_path%/install/install_generator.rb.tt +1 -1
- data/lib/gemsmith/templates/%gem_name%/lib/generators/%gem_path%/upgrade/USAGE.tt +1 -1
- data/lib/gemsmith/templates/%gem_name%/lib/generators/%gem_path%/upgrade/upgrade_generator.rb.tt +1 -1
- data/lib/gemsmith/templates/%gem_name%/spec/lib/%gem_path%/cli_spec.rb.tt +7 -22
- metadata +58 -36
- metadata.gz.sig +0 -0
- data/lib/gemsmith/generators/travis.rb +0 -13
- data/lib/gemsmith/templates/%gem_name%/.travis.yml.tt +0 -11
- data/lib/gemsmith/templates/%gem_name%/gemfiles/rails-%rails_version%.x.gemfile.tt +0 -5
data/lib/gemsmith/credentials.rb
CHANGED
@@ -26,6 +26,7 @@ module Gemsmith
|
|
26
26
|
[Authenticators::RubyGems, Authenticators::Basic]
|
27
27
|
end
|
28
28
|
|
29
|
+
# :reek:DuplicateMethodCall
|
29
30
|
def initialize key: self.class.default_key,
|
30
31
|
url: self.class.default_url,
|
31
32
|
shell: Thor::Shell::Basic.new
|
@@ -49,6 +50,7 @@ module Gemsmith
|
|
49
50
|
end
|
50
51
|
|
51
52
|
# rubocop:disable Metrics/AbcSize
|
53
|
+
# :reek:TooManyStatements
|
52
54
|
def create
|
53
55
|
return if valid?
|
54
56
|
|
@@ -58,9 +60,10 @@ module Gemsmith
|
|
58
60
|
|
59
61
|
new_credentials = credentials.merge key => authenticator.new(login, password).authorization
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
-
|
63
|
+
file_path = self.class.file_path
|
64
|
+
FileUtils.mkdir_p File.dirname file_path
|
65
|
+
File.open(file_path, "w") { |file| file << YAML.dump(new_credentials) }
|
66
|
+
FileUtils.chmod(0o600, file_path)
|
64
67
|
end
|
65
68
|
|
66
69
|
private
|
@@ -8,6 +8,10 @@ module Gemsmith
|
|
8
8
|
class ModuleFormatter
|
9
9
|
using Refinements::Strings
|
10
10
|
|
11
|
+
def self.indent length = 0
|
12
|
+
" " * length
|
13
|
+
end
|
14
|
+
|
11
15
|
def initialize namespace
|
12
16
|
@namespace = namespace
|
13
17
|
@modules = namespace.split "::"
|
@@ -24,28 +28,22 @@ module Gemsmith
|
|
24
28
|
|
25
29
|
def prefix
|
26
30
|
modules.each.with_index.reduce "" do |result, (module_name, index)|
|
27
|
-
result + "#{
|
31
|
+
result + "#{self.class.indent index}module #{module_name}\n"
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
31
35
|
def body content
|
32
|
-
indent = indentation depth + 1
|
33
|
-
|
34
36
|
content.sub(/\A\n/, "").split("\n").reduce "" do |body, line|
|
35
37
|
next "#{body}\n" if line.blank?
|
36
|
-
body + "#{indent}#{line.gsub(/^\s{2}/, "")}\n"
|
38
|
+
body + "#{self.class.indent depth + 1}#{line.gsub(/^\s{2}/, "")}\n"
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
42
|
def suffix
|
41
43
|
modules.each.with_index.reduce "" do |result, (_, index)|
|
42
|
-
result + "#{
|
44
|
+
result + "#{self.class.indent depth - index}end\n"
|
43
45
|
end
|
44
46
|
end
|
45
|
-
|
46
|
-
def indentation length
|
47
|
-
" " * length
|
48
|
-
end
|
49
47
|
end
|
50
48
|
end
|
51
49
|
end
|
@@ -6,6 +6,7 @@ module Gemsmith
|
|
6
6
|
module Gem
|
7
7
|
# Defines a gem requirement. This is a partial, cleaner implementation of the RubyGems
|
8
8
|
# `Gem::Requirement` object.
|
9
|
+
# :reek:PrimaDonnaMethod
|
9
10
|
class Requirement
|
10
11
|
def self.operators
|
11
12
|
[">", ">=", "=", "!=", "<", "<=", "~>"]
|
@@ -43,10 +44,11 @@ module Gemsmith
|
|
43
44
|
private
|
44
45
|
|
45
46
|
def validate!
|
46
|
-
|
47
|
+
operators = self.class.operators
|
48
|
+
return true if operators.include?(operator)
|
47
49
|
|
48
50
|
fail Errors::RequirementOperator,
|
49
|
-
%(Invalid gem requirement operator. Use: #{
|
51
|
+
%(Invalid gem requirement operator. Use: #{operators.join ", "}.)
|
50
52
|
end
|
51
53
|
end
|
52
54
|
end
|
@@ -4,6 +4,8 @@ module Gemsmith
|
|
4
4
|
module Generators
|
5
5
|
# Abstract class from which all generators inherit from.
|
6
6
|
class Base
|
7
|
+
LIB_ROOT = File.join("%gem_name%", "lib").freeze
|
8
|
+
|
7
9
|
def initialize cli, configuration: {}
|
8
10
|
@cli = cli
|
9
11
|
@configuration = configuration
|
@@ -21,12 +23,9 @@ module Gemsmith
|
|
21
23
|
|
22
24
|
attr_reader :cli, :configuration
|
23
25
|
|
24
|
-
|
25
|
-
File.join "%gem_name%", "lib"
|
26
|
-
end
|
27
|
-
|
26
|
+
# :reek:UtilityFunction
|
28
27
|
def lib_gem_root
|
29
|
-
File.join
|
28
|
+
File.join LIB_ROOT, "%gem_path%"
|
30
29
|
end
|
31
30
|
|
32
31
|
def gem_name
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gemsmith
|
4
|
+
module Generators
|
5
|
+
# Generates Circle CI support.
|
6
|
+
class CircleCI < Base
|
7
|
+
def run
|
8
|
+
return unless configuration.dig(:generate, :circle_ci)
|
9
|
+
cli.template "%gem_name%/circle.yml.tt", configuration
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -11,7 +11,7 @@ module Gemsmith
|
|
11
11
|
cli.template "%gem_name%/bin/%gem_name%.tt", configuration
|
12
12
|
cli.template "%gem_name%/lib/%gem_path%/cli.rb.tt", configuration
|
13
13
|
cli.template "%gem_name%/spec/lib/%gem_path%/cli_spec.rb.tt", configuration
|
14
|
-
cli.chmod "#{
|
14
|
+
cli.chmod "#{gem_name}/bin/#{gem_name}", 0o755
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gemsmith
|
4
|
+
module Generators
|
5
|
+
# Generates Git Cop support.
|
6
|
+
class GitCop < Base
|
7
|
+
def run
|
8
|
+
return unless configuration.dig(:generate, :git_cop)
|
9
|
+
cli.uncomment_lines "#{gem_name}/Rakefile", %r(require.+git\/cop.+)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "pragmater"
|
4
3
|
require "pathname"
|
4
|
+
require "pragmater"
|
5
5
|
|
6
6
|
module Gemsmith
|
7
7
|
module Generators
|
@@ -14,26 +14,29 @@ module Gemsmith
|
|
14
14
|
# rubocop:disable Metrics/MethodLength
|
15
15
|
def whitelist
|
16
16
|
%W[
|
17
|
-
Gemfile
|
18
|
-
Guardfile
|
19
|
-
Rakefile
|
20
|
-
config.ru
|
21
|
-
bin/#{configuration.dig :gem, :name}
|
22
|
-
bin/
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
**/*Gemfile
|
18
|
+
**/*Guardfile
|
19
|
+
**/*Rakefile
|
20
|
+
**/*config.ru
|
21
|
+
**/*bin/#{configuration.dig :gem, :name}
|
22
|
+
**/*bin/bundle
|
23
|
+
**/*bin/rails
|
24
|
+
**/*bin/rake
|
25
|
+
**/*bin/setup
|
26
|
+
**/*bin/update
|
27
|
+
**/*bin/yarn
|
28
|
+
**/*.gemspec
|
29
|
+
**/*.rake
|
30
|
+
**/*.rb
|
26
31
|
]
|
27
32
|
end
|
28
33
|
|
29
34
|
def run
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
def whitelisted_files
|
36
|
-
Pathname.glob(%(#{gem_root}/**/*{#{whitelist.join ","}})).select(&:file?)
|
35
|
+
Pragmater::Runner.new(
|
36
|
+
gem_root,
|
37
|
+
comments: self.class.comments,
|
38
|
+
whitelist: whitelist
|
39
|
+
).run action: :add
|
37
40
|
end
|
38
41
|
end
|
39
42
|
end
|
@@ -15,7 +15,7 @@ module Gemsmith
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def create_engine
|
18
|
-
cli.template "#{
|
18
|
+
cli.template "#{LIB_ROOT}/%gem_path%/engine.rb.tt", configuration
|
19
19
|
cli.run "rails plugin new --skip #{configuration.dig :gem, :name} #{engine_options}"
|
20
20
|
end
|
21
21
|
|
@@ -28,11 +28,6 @@ module Gemsmith
|
|
28
28
|
cli.template "#{generator_root}/upgrade/USAGE.tt", configuration
|
29
29
|
end
|
30
30
|
|
31
|
-
def create_travis_gemfiles
|
32
|
-
return unless configuration.dig(:generate, :travis)
|
33
|
-
cli.template "%gem_name%/gemfiles/rails-%rails_version%.x.gemfile.tt", configuration
|
34
|
-
end
|
35
|
-
|
36
31
|
def stub_assets
|
37
32
|
cli.run %(printf "%s" > "#{gem_name}/app/assets/javascripts/#{gem_path}/application.js")
|
38
33
|
cli.run %(printf "%s" > "#{gem_name}/app/assets/stylesheets/#{gem_path}/application.css")
|
@@ -45,13 +40,13 @@ module Gemsmith
|
|
45
40
|
cli.remove_file "#{gem_name}/README.rdoc", configuration
|
46
41
|
end
|
47
42
|
|
43
|
+
# :reek:TooManyStatements
|
48
44
|
def run
|
49
45
|
return unless configuration.dig(:generate, :rails)
|
50
46
|
|
51
47
|
install_rails
|
52
48
|
create_engine
|
53
49
|
create_generator_files
|
54
|
-
create_travis_gemfiles
|
55
50
|
stub_assets
|
56
51
|
remove_files
|
57
52
|
end
|
@@ -70,7 +65,7 @@ module Gemsmith
|
|
70
65
|
end
|
71
66
|
|
72
67
|
def generator_root
|
73
|
-
"#{
|
68
|
+
"#{LIB_ROOT}/generators/%gem_path%"
|
74
69
|
end
|
75
70
|
|
76
71
|
def indentation
|
@@ -30,6 +30,10 @@ module Gemsmith
|
|
30
30
|
configuration.dig(:generate, :rspec) ? "spec" : ""
|
31
31
|
end
|
32
32
|
|
33
|
+
def git_cop_task
|
34
|
+
configuration.dig(:generate, :git_cop) ? "git_cop" : ""
|
35
|
+
end
|
36
|
+
|
33
37
|
def reek_task
|
34
38
|
configuration.dig(:generate, :reek) ? "reek" : ""
|
35
39
|
end
|
@@ -43,7 +47,7 @@ module Gemsmith
|
|
43
47
|
end
|
44
48
|
|
45
49
|
def code_quality_tasks
|
46
|
-
[reek_task, rubocop_task, scss_lint_task].compress.join " "
|
50
|
+
[git_cop_task, reek_task, rubocop_task, scss_lint_task].compress.join " "
|
47
51
|
end
|
48
52
|
|
49
53
|
def code_quality_task
|
data/lib/gemsmith/helpers/cli.rb
CHANGED
@@ -16,6 +16,8 @@ module Gemsmith
|
|
16
16
|
say "q. Quit.\n\n"
|
17
17
|
end
|
18
18
|
|
19
|
+
# :reek:FeatureEnvy
|
20
|
+
# :reek:TooManyStatements
|
19
21
|
def pick_gem gems, name
|
20
22
|
answer = ask "Enter selection:"
|
21
23
|
return if answer == "q"
|
@@ -25,7 +27,7 @@ module Gemsmith
|
|
25
27
|
if (1..gems.size).cover?(answer)
|
26
28
|
Gem::Specification.find name, gems[answer - 1].version.version
|
27
29
|
else
|
28
|
-
error "Invalid option: #{answer}"
|
30
|
+
say_status :error, "Invalid option: #{answer}", :red
|
29
31
|
nil
|
30
32
|
end
|
31
33
|
end
|
@@ -33,10 +35,11 @@ module Gemsmith
|
|
33
35
|
def inspect_gem specification, method
|
34
36
|
return unless specification
|
35
37
|
Gem::Inspector.new.public_send method, Gem::Specification.new(specification.spec_file)
|
36
|
-
rescue Versionaire::Errors::Conversion =>
|
37
|
-
error
|
38
|
+
rescue Versionaire::Errors::Conversion => error
|
39
|
+
say_status :error, error.message, :red
|
38
40
|
end
|
39
41
|
|
42
|
+
# :reek:TooManyStatements
|
40
43
|
def process_gem name, method
|
41
44
|
specs = Gem::Specification.find_all name
|
42
45
|
spec_count = specs.size
|
@@ -47,7 +50,7 @@ module Gemsmith
|
|
47
50
|
print_gems specs
|
48
51
|
inspect_gem pick_gem(specs, name), method
|
49
52
|
else
|
50
|
-
error
|
53
|
+
say_status(:error, "Unable to find gem: #{name}.", :red) and ""
|
51
54
|
end
|
52
55
|
end
|
53
56
|
end
|
data/lib/gemsmith/identity.rb
CHANGED
@@ -32,7 +32,7 @@ module Gemsmith
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def build gem_spec
|
35
|
-
path = package_path
|
35
|
+
path = gem_spec.package_path
|
36
36
|
|
37
37
|
if kernel.system("gem build #{gem_spec.name}.gemspec")
|
38
38
|
FileUtils.mkdir_p "pkg"
|
@@ -46,7 +46,7 @@ module Gemsmith
|
|
46
46
|
def install gem_spec
|
47
47
|
gem_name = "#{gem_spec.name} #{gem_spec.version_number}"
|
48
48
|
|
49
|
-
if kernel.system("gem install #{package_path
|
49
|
+
if kernel.system("gem install #{gem_spec.package_path}")
|
50
50
|
shell.confirm "Installed: #{gem_name}."
|
51
51
|
else
|
52
52
|
shell.error "Unable to install: #{gem_name}."
|
@@ -56,10 +56,6 @@ module Gemsmith
|
|
56
56
|
private
|
57
57
|
|
58
58
|
attr_reader :tocer, :shell, :kernel
|
59
|
-
|
60
|
-
def package_path gem_spec
|
61
|
-
File.join "pkg", gem_spec.package_file_name
|
62
|
-
end
|
63
59
|
end
|
64
60
|
end
|
65
61
|
end
|
@@ -9,12 +9,14 @@ require "gemsmith/cli"
|
|
9
9
|
module Gemsmith
|
10
10
|
module Rake
|
11
11
|
# Provides gem release functionality. Meant to be wrapped in Rake tasks.
|
12
|
+
# :reek:TooManyInstanceVariables
|
12
13
|
class Publisher
|
13
14
|
def self.gem_spec_path
|
14
15
|
String Dir["#{Dir.pwd}/*.gemspec"].first
|
15
16
|
end
|
16
17
|
|
17
18
|
# rubocop:disable Metrics/ParameterLists
|
19
|
+
# :reek:LongParameterList
|
18
20
|
def initialize gem_spec: Gemsmith::Gem::Specification.new(self.class.gem_spec_path),
|
19
21
|
gem_config: Gemsmith::CLI.configuration.to_h,
|
20
22
|
credentials: Gemsmith::Credentials,
|
@@ -32,11 +34,10 @@ module Gemsmith
|
|
32
34
|
|
33
35
|
# rubocop:disable Metrics/AbcSize
|
34
36
|
def push
|
35
|
-
creds = credentials.new key: gem_spec.allowed_push_key.to_sym,
|
36
|
-
url: gem_spec.allowed_push_host
|
37
|
+
creds = credentials.new key: gem_spec.allowed_push_key.to_sym, url: gem_host
|
37
38
|
creds.create
|
38
39
|
|
39
|
-
options = %(--key "#{translate_key creds.key}" --host "#{
|
40
|
+
options = %(--key "#{translate_key creds.key}" --host "#{gem_host}")
|
40
41
|
status = kernel.system %(gem push "pkg/#{gem_spec.package_file_name}" #{options})
|
41
42
|
process_push status
|
42
43
|
end
|
@@ -56,16 +57,21 @@ module Gemsmith
|
|
56
57
|
|
57
58
|
attr_reader :gem_spec, :gem_config, :credentials, :publisher, :shell, :kernel
|
58
59
|
|
60
|
+
def gem_host
|
61
|
+
gem_spec.allowed_push_host
|
62
|
+
end
|
63
|
+
|
59
64
|
def translate_key key
|
60
65
|
key == credentials.default_key ? :rubygems : key
|
61
66
|
end
|
62
67
|
|
63
68
|
def process_push status
|
69
|
+
package = gem_spec.package_file_name
|
70
|
+
|
64
71
|
if status
|
65
|
-
shell.confirm "Pushed #{
|
72
|
+
shell.confirm "Pushed #{package} to #{gem_host}."
|
66
73
|
else
|
67
|
-
shell.error "Failed pushing #{
|
68
|
-
"#{gem_spec.allowed_push_host}. " \
|
74
|
+
shell.error "Failed pushing #{package} to #{gem_host}. " \
|
69
75
|
"Check gemspec and gem credential settings."
|
70
76
|
end
|
71
77
|
|