gemfather-cli 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c80850beac849658b418983fb4fa7b7b6310dcefcdd95e3b365a68402b42bda2
4
+ data.tar.gz: dccb5039ec85d1341983f96aa55825eed1b52815e76ef12383662cc2dfdbfcc0
5
+ SHA512:
6
+ metadata.gz: 5ed22014acd490e9fc6d48be0e5edfafee9a749ef34c102f2d86e0275e2ad89dfce92770dc845acb9646209157e5508c6ea15bf71ebd2cadc9a3d4adc85b6852
7
+ data.tar.gz: ba2da66bb91df273f1e7422188d599b1d8f88feb4142f6552ddedfe09956bb71e7fc04219f7ee0a9067556681fb5bcb9e7c49acf0f2a6e0c90ea155568cfa855
data/exe/gemfather ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "gemfather/cli"
6
+
7
+ Gemfather::Cli::Runner.new.call
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tty-prompt"
4
+
5
+ module Gemfather
6
+ module Cli
7
+ # Class responsible to collect user input and build settings hash
8
+ class SettingsReader
9
+ def call # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
10
+ settings = {}
11
+ prompt = TTY::Prompt.new
12
+
13
+ settings[:name] = prompt.ask("Gem name:", default: "awesome-new-gem")
14
+ settings[:summary] = prompt.ask("Summary", default: "awesome-new-gem")
15
+ settings[:description] = prompt.ask("Description", default: "awesome-new-gem")
16
+ settings[:homepage] = prompt.ask("Home page(URL)", default: "awesome-new-gem")
17
+
18
+ settings[:linter] = prompt.select("Select linter") do |menu|
19
+ menu.choice "Rubocop"
20
+ menu.choice "Standard"
21
+ menu.choice "N/A"
22
+ end
23
+
24
+ settings[:test] = prompt.select("Select test tool:") do |menu|
25
+ menu.choice "RSpec"
26
+ menu.choice "Minitest"
27
+ menu.choice "TestUnit"
28
+ menu.choice "N/A"
29
+ end
30
+
31
+ settings[:ci] = prompt.select("Select CI tool:") do |menu|
32
+ menu.choice "GitHub"
33
+ menu.choice "Gitlab"
34
+ menu.choice "Travis"
35
+ menu.choice "Circle"
36
+ end
37
+
38
+ settings[:makefile?] = prompt.yes?("Do you need Makefile?")
39
+ settings[:coc] = prompt.yes?("Do you need Code Of Conduct?")
40
+
41
+ settings[:debugger] = prompt.select("Select debugger tool:") do |menu|
42
+ menu.choice "IRB"
43
+ menu.choice "Pry"
44
+ end
45
+
46
+ settings
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gemfather
4
+ module Cli
5
+ VERSION = "0.1.1"
6
+ end
7
+ end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "cli/settings_reader"
4
+ require "fileutils"
5
+
6
+ module Gemfather
7
+ module Cli
8
+ class Error < StandardError; end
9
+
10
+ # Entrypoint of the gem
11
+ class Runner
12
+ attr_accessor :settings
13
+
14
+ def initialize(settings_reader = ::Gemfather::Cli::SettingsReader.new)
15
+ @settings_reader = settings_reader
16
+ end
17
+
18
+ def call
19
+ populate_settings
20
+ init_gem
21
+ update_gem_info
22
+ copy_templates
23
+ end
24
+
25
+ private
26
+
27
+ def populate_settings
28
+ @settings = @settings_reader.call
29
+ end
30
+
31
+ def build_bundle_options
32
+ linter_options = build_linter_options
33
+ test_options = build_test_options
34
+ coc_options = build_coc_options
35
+ ci_options = build_ci_options
36
+
37
+ [
38
+ linter_options,
39
+ test_options,
40
+ coc_options,
41
+ ci_options
42
+ ].join(" ")
43
+ end
44
+
45
+ def build_linter_options
46
+ case settings[:linter]
47
+ when "Rubocop"
48
+ "--linter=rubocop"
49
+ when "Standard"
50
+ "--linter=standard"
51
+ else
52
+ ""
53
+ end
54
+ end
55
+
56
+ def build_test_options
57
+ case settings[:test]
58
+ when "Minitest"
59
+ "--test=minitest"
60
+ when "RSpec"
61
+ "--test=rspec"
62
+ when "TestUnit"
63
+ "--test=test-unit"
64
+ else
65
+ ""
66
+ end
67
+ end
68
+
69
+ def build_coc_options
70
+ settings[:coc] ? "--coc" : "--no-coc"
71
+ end
72
+
73
+ def build_ci_options
74
+ cis = { "Github" => "github", "Gitlab" => "gitlab", "Travis" => "travis", "Circle" => "circle" }
75
+ ci_name = cis[settings[:ci]]
76
+ ci_name ? "--ci=#{ci_name}" : ""
77
+ end
78
+
79
+ def init_gem
80
+ bundle_options = build_bundle_options
81
+ `bundle gem #{settings[:name]} #{bundle_options} > /dev/null 2>&1 && cd #{settings[:name]}`
82
+ end
83
+
84
+ def update_gem_info
85
+ gemspec_path = File.join(Dir.pwd, settings[:name], "#{settings[:name]}.gemspec")
86
+ updated_gemspec_lines = update_gemspec_lines(gemspec_path)
87
+
88
+ File.open(gemspec_path, "w") do |f|
89
+ f.write(updated_gemspec_lines.join)
90
+ f.close
91
+ end
92
+ end
93
+
94
+ def update_gemspec_lines(gemspec_path) # rubocop:disable Metrics/MethodLength
95
+ IO.readlines(gemspec_path).map do |line| # rubocop:disable Metrics/BlockLength
96
+ case line
97
+ when /spec\.summary =.*/
98
+ line.gsub(/=\s".*"/, "= \"#{settings[:summary]}\"")
99
+ when /spec\.description =.*/
100
+ line.gsub(/=\s".*"/, "= \"#{settings[:description]}\"")
101
+ when /spec\.homepage =.*/
102
+ line.gsub(/=\s".*"/, "= \"#{settings[:homepage]}\"")
103
+ else
104
+ line
105
+ end
106
+ end
107
+ end
108
+
109
+ def copy_templates
110
+ return unless settings[:makefile]
111
+
112
+ puts File.join(File.dirname(__dir__))
113
+ new_gem_root = File.join(Dir.pwd, settings[:name])
114
+ FileUtils.cp(File.join(File.dirname(__dir__), "../templates/Makefile"), new_gem_root)
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "gemfather/cli"
@@ -0,0 +1,13 @@
1
+ .PHONY: test
2
+
3
+ install:
4
+ bundle install
5
+
6
+ cons:
7
+ bin/console
8
+
9
+ test:
10
+ bundle exec rspec
11
+
12
+ lint:
13
+ bundle exec rubocop
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gemfather-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - k0va1
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tty-prompt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.23'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.23'
27
+ description: Ask some questions & create a new gem template
28
+ email:
29
+ - al3xander.koval@gmail.com
30
+ executables:
31
+ - gemfather
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - exe/gemfather
36
+ - lib/gemfather/cli.rb
37
+ - lib/gemfather/cli/settings_reader.rb
38
+ - lib/gemfather/cli/version.rb
39
+ - lib/gemfather_cli.rb
40
+ - templates/Makefile
41
+ homepage: https://gitlab.com/k0va1/gemfather-cli
42
+ licenses:
43
+ - MIT
44
+ metadata:
45
+ homepage_uri: https://gitlab.com/k0va1/gemfather-cli
46
+ source_code_uri: https://gitlab.com/k0va1/gemfather-cli
47
+ changelog_uri: https://gitlab.com/k0va1/gemfather-cli
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 2.6.0
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubygems_version: 3.3.3
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Gem for creating other gems
67
+ test_files: []