gemsmith 7.7.0 → 8.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 +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +114 -118
- data/bin/gemsmith +2 -1
- data/lib/gemsmith/cli.rb +195 -99
- data/lib/gemsmith/cli_helpers.rb +8 -19
- data/lib/gemsmith/credentials.rb +2 -2
- data/lib/gemsmith/gem/inspector.rb +30 -0
- data/lib/gemsmith/gem/module_formatter.rb +51 -0
- data/lib/gemsmith/gem/requirement.rb +2 -0
- data/lib/gemsmith/{aids/gem_spec.rb → gem/specification.rb} +19 -26
- data/lib/gemsmith/generators/base.rb +33 -0
- data/lib/gemsmith/generators/bundler.rb +15 -0
- data/lib/gemsmith/generators/cli.rb +17 -0
- data/lib/gemsmith/generators/code_climate.rb +14 -0
- data/lib/gemsmith/generators/documentation.rb +28 -0
- data/lib/gemsmith/generators/gem.rb +17 -0
- data/lib/gemsmith/{skeletons/git_skeleton.rb → generators/git.rb} +13 -7
- data/lib/gemsmith/generators/git_hub.rb +14 -0
- data/lib/gemsmith/generators/guard.rb +13 -0
- data/lib/gemsmith/generators/pragma.rb +40 -0
- data/lib/gemsmith/generators/rails.rb +85 -0
- data/lib/gemsmith/generators/rake.rb +40 -0
- data/lib/gemsmith/generators/reek.rb +13 -0
- data/lib/gemsmith/generators/rspec.rb +23 -0
- data/lib/gemsmith/generators/rubocop.rb +16 -0
- data/lib/gemsmith/{skeletons/ruby_skeleton.rb → generators/ruby.rb} +5 -5
- data/lib/gemsmith/generators/scss_lint.rb +13 -0
- data/lib/gemsmith/generators/travis.rb +13 -0
- data/lib/gemsmith/git.rb +19 -0
- data/lib/gemsmith/identity.rb +1 -1
- data/lib/gemsmith/rake/builder.rb +65 -0
- data/lib/gemsmith/rake/{release.rb → publisher.rb} +14 -5
- data/lib/gemsmith/rake/tasks.rb +32 -20
- data/lib/gemsmith/template_helper.rb +28 -0
- data/lib/gemsmith/templates/%gem_name%/%gem_name%.gemspec.tt +30 -28
- data/lib/gemsmith/templates/%gem_name%/.codeclimate.yml.tt +36 -0
- data/lib/gemsmith/templates/%gem_name%/.rubocop.yml.tt +9 -1
- data/lib/gemsmith/templates/%gem_name%/.travis.yml.tt +4 -1
- data/lib/gemsmith/templates/%gem_name%/{CHANGELOG.md.tt → CHANGES.md.tt} +0 -0
- data/lib/gemsmith/templates/%gem_name%/Guardfile.tt +1 -1
- data/lib/gemsmith/templates/%gem_name%/README.md.tt +20 -18
- data/lib/gemsmith/templates/%gem_name%/Rakefile.tt +6 -1
- data/lib/gemsmith/templates/%gem_name%/bin/%gem_name%.tt +4 -4
- data/lib/gemsmith/templates/%gem_name%/bin/setup.tt +1 -1
- data/lib/gemsmith/templates/%gem_name%/lib/%gem_path%.rb.tt +4 -0
- data/lib/gemsmith/templates/%gem_name%/lib/%gem_path%/cli.rb.tt +54 -0
- data/lib/gemsmith/templates/%gem_name%/lib/{%gem_name% → %gem_path%}/engine.rb.tt +2 -4
- data/lib/gemsmith/templates/%gem_name%/lib/{%gem_name% → %gem_path%}/identity.rb.tt +3 -5
- data/lib/gemsmith/templates/%gem_name%/lib/generators/{%gem_name% → %gem_path%}/install/USAGE.tt +0 -0
- data/lib/gemsmith/templates/%gem_name%/lib/generators/{%gem_name% → %gem_path%}/install/install_generator.rb.tt +2 -5
- data/lib/gemsmith/templates/%gem_name%/lib/generators/{%gem_name% → %gem_path%}/upgrade/USAGE.tt +0 -0
- data/lib/gemsmith/templates/%gem_name%/lib/generators/{%gem_name% → %gem_path%}/upgrade/upgrade_generator.rb.tt +2 -5
- data/lib/gemsmith/templates/%gem_name%/lib/tasks/reek.rake.tt +6 -0
- data/lib/gemsmith/templates/%gem_name%/lib/tasks/scss_lint.rake.tt +6 -0
- data/lib/gemsmith/templates/%gem_name%/spec/lib/%gem_path%/cli_spec.rb.tt +83 -0
- data/lib/gemsmith/templates/%gem_name%/spec/rails_helper.rb.tt +14 -0
- data/lib/gemsmith/templates/%gem_name%/spec/spec_helper.rb.tt +29 -16
- data/lib/gemsmith/templates/%gem_name%/spec/support/shared_contexts/temp_dir.rb.tt +9 -0
- data/lib/tasks/reek.rake +8 -0
- data/lib/tasks/rspec.rake +2 -0
- data/lib/tasks/rubocop.rake +2 -0
- metadata +138 -149
- metadata.gz.sig +0 -0
- data/lib/gemsmith/aids/git.rb +0 -12
- data/lib/gemsmith/aids/spec.rb +0 -46
- data/lib/gemsmith/configuration.rb +0 -200
- data/lib/gemsmith/rake/build.rb +0 -38
- data/lib/gemsmith/skeletons/base_skeleton.rb +0 -29
- data/lib/gemsmith/skeletons/bundler_skeleton.rb +0 -15
- data/lib/gemsmith/skeletons/cli_skeleton.rb +0 -16
- data/lib/gemsmith/skeletons/documentation_skeleton.rb +0 -28
- data/lib/gemsmith/skeletons/gem_skeleton.rb +0 -17
- data/lib/gemsmith/skeletons/git_hub_skeleton.rb +0 -14
- data/lib/gemsmith/skeletons/guard_skeleton.rb +0 -13
- data/lib/gemsmith/skeletons/pry_skeleton.rb +0 -13
- data/lib/gemsmith/skeletons/rails_skeleton.rb +0 -61
- data/lib/gemsmith/skeletons/rake_skeleton.rb +0 -37
- data/lib/gemsmith/skeletons/rspec_skeleton.rb +0 -26
- data/lib/gemsmith/skeletons/rubocop_skeleton.rb +0 -15
- data/lib/gemsmith/skeletons/travis_skeleton.rb +0 -13
- data/lib/gemsmith/templates/%gem_name%/lib/%gem_name%.rb.tt +0 -6
- data/lib/gemsmith/templates/%gem_name%/lib/%gem_name%/cli.rb.tt +0 -40
- data/lib/gemsmith/templates/%gem_name%/lib/tasks/console.rake.tt +0 -7
- data/lib/gemsmith/templates/%gem_name%/spec/lib/%gem_name%/%gem_name%_spec.rb.tt +0 -7
- data/lib/gemsmith/templates/%gem_name%/spec/support/extensions/pry.rb.tt +0 -5
- data/lib/gemsmith/templates/%gem_name%/spec/support/kit/default_config.rb.tt +0 -18
- data/lib/gemsmith/templates/%gem_name%/spec/support/kit/stderr.rb.tt +0 -9
- data/lib/gemsmith/templates/%gem_name%/spec/support/kit/stdout.rb.tt +0 -9
- data/lib/gemsmith/templates/%gem_name%/spec/support/kit/temp_dir.rb.tt +0 -25
- data/lib/tasks/console.rake +0 -7
data/lib/gemsmith/cli_helpers.rb
CHANGED
@@ -3,18 +3,6 @@
|
|
3
3
|
module Gemsmith
|
4
4
|
# Command Line Interface (CLI) helpers for the CLI class.
|
5
5
|
module CLIHelpers
|
6
|
-
def gem_name
|
7
|
-
configuration.gem_name
|
8
|
-
end
|
9
|
-
|
10
|
-
def gem_class
|
11
|
-
configuration.gem_class
|
12
|
-
end
|
13
|
-
|
14
|
-
def rails_version
|
15
|
-
configuration.rails_version
|
16
|
-
end
|
17
|
-
|
18
6
|
module_function
|
19
7
|
|
20
8
|
def print_gems gems
|
@@ -28,27 +16,28 @@ module Gemsmith
|
|
28
16
|
return if answer == "q"
|
29
17
|
|
30
18
|
if (1..gems.size).cover?(answer.to_i)
|
31
|
-
|
19
|
+
Gem::Specification.find name, gems[answer.to_i - 1].version.version
|
32
20
|
else
|
33
21
|
error "Invalid option: #{answer}"
|
34
22
|
nil
|
35
23
|
end
|
36
24
|
end
|
37
25
|
|
38
|
-
def
|
26
|
+
def inspect_gem specification, method
|
39
27
|
return unless specification
|
40
|
-
|
41
|
-
|
28
|
+
Gem::Inspector.new.public_send method, Gem::Specification.new(specification.spec_file)
|
29
|
+
rescue Versionaire::Errors::Conversion => exception
|
30
|
+
error(exception.message)
|
42
31
|
end
|
43
32
|
|
44
33
|
def process_gem name, method
|
45
|
-
specs =
|
34
|
+
specs = Gem::Specification.find_all name
|
46
35
|
|
47
36
|
if specs.size == 1
|
48
|
-
|
37
|
+
inspect_gem specs.first, method
|
49
38
|
elsif specs.size > 1
|
50
39
|
print_gems specs
|
51
|
-
|
40
|
+
inspect_gem pick_gem(specs, name), method
|
52
41
|
else
|
53
42
|
error("Unable to find gem: #{name}.") and ""
|
54
43
|
end
|
data/lib/gemsmith/credentials.rb
CHANGED
@@ -6,7 +6,7 @@ require "gemsmith/authenticators/ruby_gems"
|
|
6
6
|
require "gemsmith/authenticators/basic"
|
7
7
|
|
8
8
|
module Gemsmith
|
9
|
-
#
|
9
|
+
# Generates gem credentials for RubyGems and/or alternative servers.
|
10
10
|
class Credentials
|
11
11
|
attr_reader :key, :url
|
12
12
|
|
@@ -55,7 +55,7 @@ module Gemsmith
|
|
55
55
|
|
56
56
|
FileUtils.mkdir_p File.dirname self.class.file_path
|
57
57
|
File.open(self.class.file_path, "w") { |file| file << YAML.dump(new_credentials) }
|
58
|
-
FileUtils.chmod(
|
58
|
+
FileUtils.chmod(0o600, self.class.file_path)
|
59
59
|
end
|
60
60
|
|
61
61
|
private
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "open3"
|
4
|
+
|
5
|
+
module Gemsmith
|
6
|
+
module Gem
|
7
|
+
# Provides the ability to investigate a gem in greater detail.
|
8
|
+
class Inspector
|
9
|
+
def self.editor
|
10
|
+
ENV.fetch "EDITOR"
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize shell: Open3
|
14
|
+
@shell = shell
|
15
|
+
end
|
16
|
+
|
17
|
+
def edit specification
|
18
|
+
shell.capture2 self.class.editor, specification.path
|
19
|
+
end
|
20
|
+
|
21
|
+
def visit specification
|
22
|
+
shell.capture2 "open", specification.homepage_url
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_reader :shell
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "refinements/strings"
|
4
|
+
|
5
|
+
module Gemsmith
|
6
|
+
module Gem
|
7
|
+
# Formats single or multiple modules with correct, two-space indentation for templates.
|
8
|
+
class ModuleFormatter
|
9
|
+
using Refinements::Strings
|
10
|
+
|
11
|
+
def initialize namespace
|
12
|
+
@namespace = namespace
|
13
|
+
@modules = namespace.split "::"
|
14
|
+
@depth = namespace.scan("::").length
|
15
|
+
end
|
16
|
+
|
17
|
+
def render content
|
18
|
+
"#{prefix}#{body content}#{suffix.chomp}"
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :namespace, :modules, :depth
|
24
|
+
|
25
|
+
def prefix
|
26
|
+
modules.each.with_index.reduce "" do |result, (module_name, index)|
|
27
|
+
result + "#{indentation index}module #{module_name}\n"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def body content
|
32
|
+
indent = indentation depth + 1
|
33
|
+
|
34
|
+
content.sub(/\A\n/, "").split("\n").reduce "" do |body, line|
|
35
|
+
next "#{body}\n" if line.blank?
|
36
|
+
body + "#{indent}#{line.gsub(/^\s{2}/, "")}\n"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def suffix
|
41
|
+
modules.each.with_index.reduce "" do |result, (_, index)|
|
42
|
+
result + "#{indentation depth - index}end\n"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def indentation length
|
47
|
+
" " * length
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "versionaire"
|
4
4
|
|
5
5
|
module Gemsmith
|
6
|
-
module
|
6
|
+
module Gem
|
7
7
|
# A Gem::Specification with additional enhancements.
|
8
|
-
class
|
8
|
+
class Specification
|
9
9
|
def self.specification
|
10
10
|
::Gem::Specification
|
11
11
|
end
|
@@ -14,10 +14,6 @@ module Gemsmith
|
|
14
14
|
::Gem::DEFAULT_HOST
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.editor
|
18
|
-
ENV.fetch "EDITOR"
|
19
|
-
end
|
20
|
-
|
21
17
|
def self.find name, version
|
22
18
|
specification.find_by_name name, version
|
23
19
|
end
|
@@ -26,11 +22,19 @@ module Gemsmith
|
|
26
22
|
specification.find_all_by_name name, requirement
|
27
23
|
end
|
28
24
|
|
29
|
-
def initialize file_path
|
25
|
+
def initialize file_path
|
30
26
|
@file_path = file_path
|
31
|
-
@shell = shell
|
32
27
|
@spec = self.class.specification.load file_path
|
33
28
|
validate
|
29
|
+
@version = Versionaire::Version @spec.version.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
def name
|
33
|
+
spec.name
|
34
|
+
end
|
35
|
+
|
36
|
+
def path
|
37
|
+
spec.full_gem_path
|
34
38
|
end
|
35
39
|
|
36
40
|
def homepage_url
|
@@ -45,36 +49,25 @@ module Gemsmith
|
|
45
49
|
spec.metadata.fetch("allowed_push_host") { self.class.default_gem_host }
|
46
50
|
end
|
47
51
|
|
48
|
-
def open_gem
|
49
|
-
shell.capture2 self.class.editor, spec.full_gem_path
|
50
|
-
String spec.full_gem_path
|
51
|
-
end
|
52
|
-
|
53
|
-
def open_homepage
|
54
|
-
shell.capture2 "open", homepage_url
|
55
|
-
homepage_url
|
56
|
-
end
|
57
|
-
|
58
52
|
def version_number
|
59
|
-
|
53
|
+
version.to_s
|
60
54
|
end
|
61
55
|
|
62
56
|
def version_label
|
63
|
-
|
57
|
+
version.label
|
64
58
|
end
|
65
59
|
|
66
60
|
def package_file_name
|
67
|
-
"#{
|
61
|
+
"#{name}-#{version_number}.gem"
|
68
62
|
end
|
69
63
|
|
70
64
|
private
|
71
65
|
|
72
|
-
attr_reader :file_path, :spec, :
|
66
|
+
attr_reader :file_path, :spec, :version
|
73
67
|
|
74
68
|
def validate
|
75
|
-
|
76
|
-
|
77
|
-
end
|
69
|
+
return if spec.is_a?(self.class.specification)
|
70
|
+
fail(Errors::Specification, %(Unknown gem specification: "#{file_path}".))
|
78
71
|
end
|
79
72
|
end
|
80
73
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gemsmith
|
4
|
+
module Generators
|
5
|
+
# Abstract class from which all generators inherit from.
|
6
|
+
class Base
|
7
|
+
def initialize cli, configuration: {}
|
8
|
+
@cli = cli
|
9
|
+
@configuration = configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.run cli, configuration: {}
|
13
|
+
new(cli, configuration: configuration).run
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
fail NotImplementedError, "The method, #run, is not implemented yet."
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
attr_reader :cli, :configuration
|
23
|
+
|
24
|
+
def lib_root
|
25
|
+
File.join "%gem_name%", "lib"
|
26
|
+
end
|
27
|
+
|
28
|
+
def lib_gem_root
|
29
|
+
File.join lib_root, "%gem_path%"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gemsmith
|
4
|
+
module Generators
|
5
|
+
# Generates Bundler support.
|
6
|
+
class Bundler < Base
|
7
|
+
def run
|
8
|
+
Dir.chdir(cli.destination_root) do
|
9
|
+
cli.info "Installing gem dependencies..."
|
10
|
+
`bundle install`
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gemsmith
|
4
|
+
module Generators
|
5
|
+
# Generates Command Line Interface (CLI) support.
|
6
|
+
class CLI < Base
|
7
|
+
def run
|
8
|
+
return unless configuration.dig(:generate, :cli)
|
9
|
+
|
10
|
+
cli.template "%gem_name%/bin/%gem_name%.tt", configuration
|
11
|
+
cli.template "%gem_name%/lib/%gem_path%/cli.rb.tt", configuration
|
12
|
+
cli.template "%gem_name%/spec/lib/%gem_path%/cli_spec.rb.tt", configuration
|
13
|
+
cli.chmod "#{configuration.dig :gem, :name}/bin/#{configuration.dig :gem, :name}", 0o755
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gemsmith
|
4
|
+
module Generators
|
5
|
+
# Generates Code Climate support.
|
6
|
+
class CodeClimate < Base
|
7
|
+
def run
|
8
|
+
return unless configuration.dig(:generate, :code_climate)
|
9
|
+
|
10
|
+
cli.template "%gem_name%/.codeclimate.yml.tt", configuration
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "tocer"
|
4
|
+
|
5
|
+
module Gemsmith
|
6
|
+
module Generators
|
7
|
+
# Generates documentation support.
|
8
|
+
class Documentation < Base
|
9
|
+
def create_files
|
10
|
+
cli.template "%gem_name%/README.md.tt", configuration
|
11
|
+
cli.template "%gem_name%/CONTRIBUTING.md.tt", configuration
|
12
|
+
cli.template "%gem_name%/CODE_OF_CONDUCT.md.tt", configuration
|
13
|
+
cli.template "%gem_name%/LICENSE.md.tt", configuration
|
14
|
+
cli.template "%gem_name%/CHANGES.md.tt", configuration
|
15
|
+
end
|
16
|
+
|
17
|
+
def update_readme
|
18
|
+
file = File.join cli.destination_root, configuration.dig(:gem, :name), "README.md"
|
19
|
+
Tocer::Writer.new(file).write
|
20
|
+
end
|
21
|
+
|
22
|
+
def run
|
23
|
+
create_files
|
24
|
+
update_readme
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gemsmith
|
4
|
+
module Generators
|
5
|
+
# Generates default gem support.
|
6
|
+
class Gem < Base
|
7
|
+
def run
|
8
|
+
cli.template "%gem_name%/bin/setup.tt", configuration
|
9
|
+
cli.template "%gem_name%/Gemfile.tt", configuration
|
10
|
+
cli.template "%gem_name%/%gem_name%.gemspec.tt", configuration
|
11
|
+
cli.template "#{lib_gem_root}.rb.tt", configuration
|
12
|
+
cli.template "#{lib_gem_root}/identity.rb.tt", configuration
|
13
|
+
cli.chmod "#{configuration.dig(:gem, :name)}/bin/setup", 0o755
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,25 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Gemsmith
|
4
|
-
module
|
5
|
-
#
|
6
|
-
class
|
4
|
+
module Generators
|
5
|
+
# Generates Git support.
|
6
|
+
class Git < Base
|
7
7
|
def create_ignore_file
|
8
|
-
cli.template "%gem_name%/.gitignore.tt", configuration
|
8
|
+
cli.template "%gem_name%/.gitignore.tt", configuration
|
9
9
|
end
|
10
10
|
|
11
11
|
def create_repository
|
12
|
-
Dir.chdir(
|
12
|
+
Dir.chdir(gem_dir) do
|
13
13
|
`git init`
|
14
14
|
`git add .`
|
15
|
-
`git commit --all --no-verify --message "Added Gemsmith
|
15
|
+
`git commit --all --no-verify --message "Added Gemsmith files."`
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
19
|
+
def run
|
20
20
|
create_ignore_file
|
21
21
|
create_repository
|
22
22
|
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def gem_dir
|
27
|
+
File.join cli.destination_root, configuration.dig(:gem, :name)
|
28
|
+
end
|
23
29
|
end
|
24
30
|
end
|
25
31
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gemsmith
|
4
|
+
module Generators
|
5
|
+
# Generates GitHub support.
|
6
|
+
class GitHub < Base
|
7
|
+
def run
|
8
|
+
return unless configuration.dig(:generate, :git_hub)
|
9
|
+
cli.template "%gem_name%/.github/ISSUE_TEMPLATE.md.tt", configuration
|
10
|
+
cli.template "%gem_name%/.github/PULL_REQUEST_TEMPLATE.md.tt", configuration
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|