rails-new-app 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +56 -0
  3. data/LICENSE +21 -0
  4. data/README.md +78 -0
  5. data/exe/rails-new-app +7 -0
  6. data/lib/rails-new-app.rb +19 -0
  7. data/lib/rails-new-app/processors.rb +5 -0
  8. data/lib/rails-new-app/processors/code_coverage_processor.rb +20 -0
  9. data/lib/rails-new-app/processors/form_builder_processor.rb +18 -0
  10. data/lib/rails-new-app/processors/processor.rb +23 -0
  11. data/lib/rails-new-app/processors/ruby_linter_processor.rb +18 -0
  12. data/lib/rails-new-app/processors/template_engine_processor.rb +10 -0
  13. data/lib/rails-new-app/processors/test_runner_processor.rb +16 -0
  14. data/lib/rails-new-app/runner.rb +234 -0
  15. data/lib/rails-new-app/steps.rb +7 -0
  16. data/lib/rails-new-app/steps/app_name_step.rb +20 -0
  17. data/lib/rails-new-app/steps/choice_step.rb +43 -0
  18. data/lib/rails-new-app/steps/code_coverage_step.rb +33 -0
  19. data/lib/rails-new-app/steps/database_step.rb +38 -0
  20. data/lib/rails-new-app/steps/form_builder_step.rb +27 -0
  21. data/lib/rails-new-app/steps/java_script_framework_step.rb +38 -0
  22. data/lib/rails-new-app/steps/rails_version_step.rb +27 -0
  23. data/lib/rails-new-app/steps/ruby_linter_step.rb +27 -0
  24. data/lib/rails-new-app/steps/step.rb +65 -0
  25. data/lib/rails-new-app/steps/template_engine_step.rb +27 -0
  26. data/lib/rails-new-app/steps/test_runner_step.rb +28 -0
  27. data/lib/rails-new-app/steps/yes_no_choice_step.rb +7 -0
  28. data/lib/rails-new-app/templates/formtastic-config.rb +1 -0
  29. data/lib/rails-new-app/templates/formtastic-gemfile.rb +1 -0
  30. data/lib/rails-new-app/templates/haml-gemfile.rb +1 -0
  31. data/lib/rails-new-app/templates/rspec-rails-config.rb +23 -0
  32. data/lib/rails-new-app/templates/rspec-rails-gemfile.rb +3 -0
  33. data/lib/rails-new-app/templates/rubocop-config.rb +2 -0
  34. data/lib/rails-new-app/templates/rubocop-minitest-gemfile.rb +5 -0
  35. data/lib/rails-new-app/templates/rubocop-rspec-gemfile.rb +5 -0
  36. data/lib/rails-new-app/templates/simple_form-config.rb +1 -0
  37. data/lib/rails-new-app/templates/simple_form-gemfile.rb +1 -0
  38. data/lib/rails-new-app/templates/simplecov-gemfile.rb +3 -0
  39. data/lib/rails-new-app/templates/simplecov-minitest-config.rb +5 -0
  40. data/lib/rails-new-app/templates/simplecov-rspec-config.rb +5 -0
  41. data/lib/rails-new-app/templates/slim-gemfile.rb +1 -0
  42. data/lib/rails-new-app/templates/standardrb-config.rb +3 -0
  43. data/lib/rails-new-app/templates/standardrb-minitest-gemfile.rb +5 -0
  44. data/lib/rails-new-app/templates/standardrb-rspec-gemfile.rb +5 -0
  45. data/lib/rails-new-app/version.rb +3 -0
  46. data/rails-new-app.gemspec +21 -0
  47. metadata +89 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cb1c777fb2609943a68f60119dfb6ce2f64023951c5610e8de0cd56f3b451241
4
+ data.tar.gz: ce22e54efe411c78d3e8f993213ba39fc00eceabfb0aa3519e05a4c8eccbaf2f
5
+ SHA512:
6
+ metadata.gz: 20a5aa1c836fa51c1676dd48fce5a2abd736a782965ccee4d72444873d3336e90a758b06700569bf4ac28af5f9ae2828664a5a04d7f7dfa61a690b3fa2bd2711
7
+ data.tar.gz: bd31660941e502f74a8c164628aa71acfbcc6b4ab1a5fe72f58ab05e87d143e6bc8593538c6b117879e60b2ee7c0d98df04226ece36dbf407e44aee0d86a3eb3
data/.gitignore ADDED
@@ -0,0 +1,56 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Ariel Juodziukynas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # rails-new-app
2
+ Command-line tool to assist the creation of new Rails 5 and 6 apps
3
+
4
+ ## Installation:
5
+
6
+ Run `gem install "rails-new-app"`
7
+
8
+ ## Usage:
9
+
10
+ Run `rails-new-app` command and follow the step by step wizard.
11
+
12
+ ### Alternative
13
+
14
+ If, for any reason, the menu navigation does not work, run `rails-new-app navigation=false`.
15
+
16
+ ## Current configurations:
17
+ - Rails version (validate and install)
18
+ - Database: none / MySQL / PostgreSQL / SQLite
19
+ - Tests: none / Minitest / RSpec
20
+ - CodeCoverage: none / Simplecov
21
+ - TemplateEngine: None (just ERB) / Slim / HAML
22
+ - RubyLinter: None / RuboCop / StandardRB
23
+ - FormBuilder: None / Simple Form / Formtastic
24
+ - JS Framework: None / ReactJS / VueJS / Angular / Elm / Stimulus
25
+
26
+ ## TODOs and ideas:
27
+ - improve GUI and UX
28
+ - - toggle options using arrow keys?
29
+ - - describe steps better
30
+ - - add links to the different tools
31
+ - add tests
32
+ - add more tools
33
+ - support `rails new` flags configuration
34
+ - research requirements
35
+ - improve validations (check rails version, ruby version, if gems are compatible with rails, etc)
36
+ - make sure the `rails-new-app` command is available globally
37
+ - show the user the current Ruby version
38
+ - support a `rails-new-app-defaults` file at the HOME dir to set default options if empty answers
39
+
40
+ #### Ideas for other tools:
41
+ - support other databases like MongoDB that require more config
42
+ - type of app: standard/minimal/api
43
+ - CI config? github actions / travis / circleci / bitbucket / gitlab / others
44
+ - js linter? None/ESlint/StandardJS
45
+ - factory_bot?
46
+ - faker?
47
+ - devise?
48
+ - carrierwave/paperclip/dragonfly?
49
+ - exception_notification / airbreak / other reporting tools
50
+ - dotenv/figaro
51
+ - redis?
52
+ - memcached/dalli/other?
53
+ - resque/sideqik/suckerpunch/other?
54
+ - CSS framework? bootstrap/tailwind/material/spectre/bulma (this affects the form builders processor)
55
+ - add basic docker config?
56
+ - admin gems? ActiveAdmin/RailsAdmin/Trestle/others
57
+ - pagination? pagy/kaminari/will_paginate
58
+ - pre-commit hooks? overcommit
59
+
60
+ ## Adding more configurations and tools:
61
+
62
+ 1. Add a new step at `lib/rails-new-app/steps` (or modify an existing one)
63
+ 2. Collect step config in the `config` hash
64
+ 3. Update configuration details before confirmation
65
+ 4. Add a new preocessor at `lib/rails-new-app/processors` (or modify an existing one)
66
+ 5. Add a template to ONLY modify the gemfile at `lib/rails-new-app/templates`
67
+ 6. Add another template to ONLY modify the code/configuration at `lib/rails-new-app/templates`
68
+ 7. Update Runner to run the `update_gemfile` and `configure` methods
69
+
70
+ * Steps 5 and 6 are split so we can run `bundle install` once.
71
+
72
+ ## Changelogs
73
+
74
+ ### 0.0.1
75
+ This is a really early Alpha version as a proof of concept.
76
+
77
+ ### 0.0.2
78
+ Added navigation between menues.
data/exe/rails-new-app ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+
5
+ require "rails-new-app"
6
+
7
+ exit RailsNewApp.run
@@ -0,0 +1,19 @@
1
+ require_relative "rails-new-app/version"
2
+ require_relative "rails-new-app/runner"
3
+
4
+ module RailsNewApp
5
+ def self.run
6
+ navigation = true
7
+ ARGV.each do |arg|
8
+ case arg
9
+ when "navigation=false" then navigation = false
10
+ when "-v", "--version"
11
+ puts "rails-new-app #{RailsNewApp::VERSION}"
12
+ exit(0)
13
+ end
14
+ end
15
+ ARGV.clear
16
+
17
+ Runner.new.run(navigation)
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ # require generic steps first
2
+ path = File.expand_path("../processors", __FILE__)
3
+ require "#{path}/processor"
4
+ # require the rest
5
+ Dir.glob("#{path}/*").each { |f| require f }
@@ -0,0 +1,20 @@
1
+ module RailsNewApp
2
+ class CodeCoverageProcessor < Processor
3
+ def udpate_gemfile(config)
4
+ return if config[:test_runner][:key] == ""
5
+
6
+ case config[:code_coverage][:key]
7
+ when "simplecov" then apply_template "simplecov-gemfile"
8
+ end
9
+ end
10
+
11
+ def configure(config)
12
+ return if config[:test_runner][:key] == ""
13
+
14
+ puts "Processing Code Coverage config"
15
+ case config[:code_coverage][:key]
16
+ when "simplecov" then apply_template "simplecov-#{config[:test_runner][:key]}-config"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ module RailsNewApp
2
+ class FormBuilderProcessor < Processor
3
+ def update_gemfile(config)
4
+ case config[:form_builder][:key]
5
+ when "simple_form" then apply_template "simple_form-gemfile"
6
+ when "formtastic" then apply_template "formtastic-gemfile"
7
+ end
8
+ end
9
+
10
+ def configure(config)
11
+ puts "Processing Form Builder config"
12
+ case config[:form_builder][:key]
13
+ when "simple_form" then apply_template "simple_form-config"
14
+ when "formtastic" then apply_template "formtastic-config"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ module RailsNewApp
2
+ class Processor
3
+ PATH = File.expand_path("../../templates", __FILE__)
4
+
5
+ def self.update_gemfile(config)
6
+ new.update_gemfile(config)
7
+ end
8
+
9
+ def self.configure(config)
10
+ new.configure(config)
11
+ end
12
+
13
+ def update_gemfile(config)
14
+ end
15
+
16
+ def configure(config)
17
+ end
18
+
19
+ def apply_template(template)
20
+ system("rails app:template LOCATION=#{PATH}/#{template}.rb")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ module RailsNewApp
2
+ class RubyLinterProcessor < Processor
3
+ def update_gemfile(config)
4
+ case config[:ruby_linter][:key]
5
+ when "rubocop" then apply_template "rubocop-#{config[:test_runner][:key]}-gemfile"
6
+ when "standardrb" then apply_template "standardrb-#{config[:test_runner][:key]}-gemfile"
7
+ end
8
+ end
9
+
10
+ def configure(config)
11
+ puts "Processing Ruby Linter config"
12
+ case config[:ruby_linter][:key]
13
+ when "rubocop" then apply_template "rubocop-config"
14
+ when "standardrb" then apply_template "standardrb-config"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ module RailsNewApp
2
+ class TemplateEngineProcessor < Processor
3
+ def update_gemfile(config)
4
+ case config[:template_engine][:key]
5
+ when "slim" then apply_template "slim-gemfile"
6
+ when "haml" then apply_template "haml-gemfile"
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ module RailsNewApp
2
+ class TestRunnerProcessor < Processor
3
+ def update_gemfile(config)
4
+ case config[:test_runner][:key]
5
+ when "rspec" then apply_template "rspec-rails-gemfile"
6
+ end
7
+ end
8
+
9
+ def configure(config)
10
+ puts "Processing test runner config"
11
+ case config[:test_runner][:key]
12
+ when "rspec" then apply_template "rspec-rails-config"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,234 @@
1
+ require_relative "steps"
2
+ require_relative "processors"
3
+ require "readline"
4
+
5
+ module RailsNewApp
6
+ class Runner
7
+ SCREENS = {
8
+ "1" => [:app_name, AppNameStep],
9
+ "2" => [:rails_ver, RailsVersionStep],
10
+ "3" => [:database, DatabaseStep],
11
+ "4" => [:test_runner, TestRunnerStep],
12
+ "5" => [:code_coverage, CodeCoverageStep],
13
+ "6" => [:js_framework, JavaScriptFrameworkStep],
14
+ "7" => [:ruby_linter, RubyLinterStep],
15
+ "8" => [:template_engine, TemplateEngineStep],
16
+ "9" => [:form_builder, FormBuilderStep]
17
+ }.freeze
18
+
19
+ def config
20
+ @config
21
+ end
22
+
23
+ # entry point
24
+ def run(navigation = true)
25
+ @config = {
26
+ navigation: navigation,
27
+ app_name: AppNameStep.default,
28
+ rails_ver: RailsVersionStep.default,
29
+ database: DatabaseStep.default,
30
+ test_runner: TestRunnerStep.default,
31
+ code_coverage: CodeCoverageStep.default,
32
+ js_framework: JavaScriptFrameworkStep.default,
33
+ ruby_linter: RubyLinterStep.default,
34
+ template_engine: TemplateEngineStep.default,
35
+ form_builder: FormBuilderStep.default
36
+ }
37
+
38
+ intro
39
+
40
+ confirmed =
41
+ if navigation
42
+ show_menu
43
+ else
44
+ steps
45
+ review_and_confirm
46
+ end
47
+
48
+ if confirmed
49
+ install_rails
50
+ rails_new
51
+ process_config
52
+ end_message
53
+ 0
54
+ else
55
+ aborted_message
56
+ 1
57
+ end
58
+ end
59
+
60
+ def clear
61
+ system("clear")
62
+ end
63
+
64
+ def intro
65
+ clear
66
+ puts "Let's create a new Rails app step by step"
67
+ end
68
+
69
+ def print_screens
70
+ SCREENS.each do |index, screen_meta|
71
+ screen = screen_meta[1].to_s.gsub("Step", "").gsub("RailsNewApp::", "")
72
+ puts "#{index} : #{screen}"
73
+ end
74
+ puts "0 : Review and confirm"
75
+ puts ""
76
+ puts "Type the number of the menu and press enter:"
77
+ end
78
+
79
+
80
+ def show_menu
81
+ print_screens
82
+ loop do
83
+ option = gets.chomp.strip
84
+ if option == "0"
85
+ case review_and_confirm
86
+ when :yes then return true
87
+ when :no then return false
88
+ end
89
+ clear
90
+ print_screens
91
+ else
92
+ screen_meta = SCREENS[option]
93
+ if screen_meta
94
+ key, screen = screen_meta
95
+ config[key] = screen.run(config)
96
+ clear
97
+ print_screens
98
+ else
99
+ puts "Invalid option, select a category:"
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ def steps
106
+ config[:app_name] = AppNameStep.run(config)
107
+ config[:rails_ver] = RailsVersionStep.run(config)
108
+ config[:database] = DatabaseStep.run(config)
109
+ config[:test_runner] = TestRunnerStep.run(config)
110
+
111
+ # ignore test coverage if no tests
112
+ config[:code_coverage] =
113
+ if config[:test_runner][:key] == ""
114
+ puts "Skipping Simplecov config, no test runner"
115
+ {key: ""}
116
+ else
117
+ CodeCoverageStep.run(config)
118
+ end
119
+
120
+ config[:js_framework] = JavaScriptFrameworkStep.run(config)
121
+ config[:ruby_linter] = RubyLinterStep.run(config)
122
+ config[:template_engine] = TemplateEngineStep.run(config)
123
+ config[:form_builder] = FormBuilderStep.run(config)
124
+ end
125
+
126
+ def review_and_confirm
127
+ clear
128
+ rails_ver = config[:rails_ver]
129
+ rails_ver = "Using latest installed Rails version" if rails_ver == ""
130
+
131
+ puts <<-REVIEW
132
+ ===== New Rails app config =====
133
+
134
+ App name: #{config[:app_name]}
135
+ Ruby version: #{RUBY_VERSION}
136
+ Rails version: #{rails_ver}
137
+ Database: #{config[:database]}
138
+ Test runner: #{config[:test_runner]}
139
+ Code coverage: #{config[:code_coverage]}
140
+ JS framework: #{config[:js_framework]}
141
+ Ruby Linter: #{config[:ruby_linter]}
142
+ Template engine: #{config[:template_engine]}
143
+ Form builder: #{config[:form_builder]}
144
+
145
+ REVIEW
146
+
147
+ message = "Type 'Y(es)' to confirm, 'B(ack) to go back, or 'N(o)' to abort"
148
+ if config[:app_name] == ""
149
+ puts <<-WARNING
150
+ =====================================
151
+ App name is required
152
+ =====================================
153
+
154
+ WARNING
155
+ message.gsub!("Type 'Y(es)' to confirm, ", "Type ")
156
+ end
157
+
158
+ loop do
159
+ puts message
160
+ answer = gets.chomp.strip
161
+ return :yes if answer =~ /\A*Y(es)?\z/i
162
+ return :back if answer =~ /\A*B(ack)?\z/i
163
+ return :no if answer =~ /\A*N(o)?\z/i
164
+
165
+ puts "Invalid option."
166
+ end
167
+ end
168
+
169
+ def install_rails
170
+ return if config[:rails_ver] == ""
171
+ # install the require rails version if needed
172
+ puts "Verifying and installing Rails #{config[:rails_ven]}"
173
+ `gem install rails -v#{config[:rails_ver]}`
174
+ end
175
+
176
+ def rails_new
177
+ puts "Running Rails new"
178
+ command = build_rails_new_command
179
+ # puts command
180
+ system(command)
181
+ end
182
+
183
+ def process_config
184
+ # cd into rails app
185
+ Dir.chdir(config[:app_name]) do
186
+ # add different gems
187
+ TestRunnerProcessor.update_gemfile(config)
188
+ CodeCoverageProcessor.update_gemfile(config)
189
+ TemplateEngineProcessor.update_gemfile(config)
190
+ FormBuilderProcessor.update_gemfile(config)
191
+ RubyLinterProcessor.update_gemfile(config)
192
+
193
+ # install gems
194
+ system("bundle install")
195
+
196
+ #configure each gem
197
+ TestRunnerProcessor.configure(config)
198
+ CodeCoverageProcessor.configure(config)
199
+ TemplateEngineProcessor.configure(config)
200
+ FormBuilderProcessor.configure(config)
201
+ RubyLinterProcessor.configure(config)
202
+ end
203
+ end
204
+
205
+ def end_message
206
+ puts "Your new Rails app is ready!"
207
+ end
208
+
209
+ def aborted_message
210
+ puts "Aborted"
211
+ end
212
+
213
+ private
214
+
215
+ # final step and creation
216
+ def build_rails_new_command
217
+ ["rails"].tap do |ar|
218
+ # use specific Rails version
219
+ ar << "_#{config[:rails_ver]}_" if config[:rails_ver] != ""
220
+ # new command
221
+ ar << "new"
222
+ # use desired database
223
+ ar << "--database=#{config[:database][:key]}" if config[:database][:in_rails_new]
224
+ # ignore test if not minitest
225
+ ar << "--skip_test" if config[:test_runner][:key] != "minitest"
226
+ # use desired js framework
227
+ ar << "--webpack=#{config[:js_framework][:key]}" if config[:js_framework][:in_rails_new]
228
+ # ar << "--skip-javascript"
229
+ # add app name
230
+ ar << config[:app_name]
231
+ end.join(" ")
232
+ end
233
+ end
234
+ end
@@ -0,0 +1,7 @@
1
+ # require generic steps first
2
+ path = File.expand_path("../steps", __FILE__)
3
+ require "#{path}/step"
4
+ require "#{path}/choice_step"
5
+ require "#{path}/yes_no_choice_step"
6
+ # require the rest
7
+ Dir.glob("#{path}/*").each { |f| require f }
@@ -0,0 +1,20 @@
1
+ module RailsNewApp
2
+ class AppNameStep < Step
3
+ def step_question
4
+ "Type the name of the app:"
5
+ end
6
+
7
+ def after_valid
8
+ puts "Your app is: #{@selection}\n"
9
+ end
10
+
11
+ def valid?(input)
12
+ if input.strip =~ /\A[a-z_]+\z/i
13
+ true
14
+ else
15
+ puts "Invalid app name"
16
+ false
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,43 @@
1
+ module RailsNewApp
2
+ class ChoiceStep < Step
3
+ def options
4
+ []
5
+ end
6
+
7
+ def option
8
+ options[@selection]
9
+ end
10
+
11
+ def ask
12
+ puts step_question
13
+ puts ""
14
+
15
+ options.each_with_index do |op, idx|
16
+ puts "#{idx} ) #{op}"
17
+ end
18
+ end
19
+
20
+ def clean_input(input)
21
+ input.to_i
22
+ end
23
+
24
+ def valid?(input)
25
+ if options[input]
26
+ true
27
+ else
28
+ puts "Invalid option, choose again:"
29
+ false
30
+ end
31
+ end
32
+
33
+ def return_value
34
+ lower = lowercase_keys[@selection]
35
+
36
+ {
37
+ option_number: @selection,
38
+ name: option,
39
+ key: lower
40
+ }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,33 @@
1
+ module RailsNewApp
2
+ class CodeCoverageStep < ChoiceStep
3
+ def step_question
4
+ warning =
5
+ if config[:test_runner][:key] == ""
6
+ "This configuration will be ignored because you selected no test runner\n"
7
+ else
8
+ ""
9
+ end
10
+ "#{warning}Type the option number of the code coverage tool to use:"
11
+ end
12
+
13
+ def options
14
+ ["None (Default)", "SimpleCov"]
15
+ end
16
+
17
+ def lowercase_keys
18
+ ["", "simplecov"]
19
+ end
20
+
21
+ def after_valid
22
+ puts "Selected code coverage tool is: #{option}\n"
23
+ end
24
+
25
+ def self.default
26
+ {
27
+ option_number: 0,
28
+ name: "None (Default)",
29
+ key: "",
30
+ }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,38 @@
1
+ module RailsNewApp
2
+ class DatabaseStep < ChoiceStep
3
+ def rails_new_options
4
+ %W[mysql postgresql sqlite3 oracle sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc]
5
+ end
6
+
7
+ def options
8
+ ["None", "SQLite (Default)", "MySQL / MariaDB", "PostgreSQL"]
9
+ end
10
+
11
+ def lowercase_keys
12
+ ["", "sqlite3", "mysql", "postgresql"]
13
+ end
14
+
15
+ def step_question
16
+ "Type the option number of the database to use:"
17
+ end
18
+
19
+ def after_valid
20
+ puts "Selected database is: #{option}\n"
21
+ end
22
+
23
+ def return_value
24
+ super.tap do |h|
25
+ h[:in_rails_new] = rails_new_options.include?(h[:key])
26
+ end
27
+ end
28
+
29
+ def self.default
30
+ {
31
+ option_number: "1",
32
+ name: "SQLite (Default)",
33
+ key: "sqlite3",
34
+ in_rails_new: true
35
+ }
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ module RailsNewApp
2
+ class FormBuilderStep < ChoiceStep
3
+ def step_question
4
+ "Type the option number of the Form Builder gem to use:"
5
+ end
6
+
7
+ def options
8
+ ["None (Default)", "Simple Form", "Formtastic"]
9
+ end
10
+
11
+ def lowercase_keys
12
+ ["", "simple_form", "formtastic"]
13
+ end
14
+
15
+ def after_valid
16
+ puts "Selected Form builder is: #{option}\n"
17
+ end
18
+
19
+ def self.default
20
+ {
21
+ option_number: 0,
22
+ name: "None (Default)",
23
+ key: "",
24
+ }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,38 @@
1
+ module RailsNewApp
2
+ class JavaScriptFrameworkStep < ChoiceStep
3
+ def rails_new_options
4
+ %W[react vue angular elm stimulus]
5
+ end
6
+
7
+ def options
8
+ ["None (Default)", "ReactJS", "VueJS", "Angular", "Elm", "Stimulus"]
9
+ end
10
+
11
+ def lowercase_keys
12
+ ["", "react", "vue", "angular", "elm", "stimulus"]
13
+ end
14
+
15
+ def step_question
16
+ "Type the option number of the JavaScript framework to use:"
17
+ end
18
+
19
+ def after_valid
20
+ puts "Selected framework is: #{option}\n"
21
+ end
22
+
23
+ def return_value
24
+ super.tap do |h|
25
+ h[:in_rails_new] = rails_new_options.include?(h[:key])
26
+ end
27
+ end
28
+
29
+ def self.default
30
+ {
31
+ option_number: 0,
32
+ name: "None (Default)",
33
+ key: "",
34
+ in_rails_new: false
35
+ }
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ module RailsNewApp
2
+ class RailsVersionStep < Step
3
+ def valid?(ver)
4
+ if ver =~ /\A[56].\d.\d\z/
5
+ # puts "Validating against Rubygems..."
6
+ # uncomment this to validate the input against RubyGems
7
+ # `gem list -r -e -a rails | grep '#{ver}'` != false
8
+ true
9
+ else
10
+ puts "Invalid Rails version, type the version you want to use:"
11
+ false
12
+ end
13
+ end
14
+
15
+ def step_question
16
+ <<-QUESTION
17
+ Type the version of Rails you want to use:
18
+ ! Notice that Rails will use the latest patch version for a given version !
19
+
20
+ QUESTION
21
+ end
22
+
23
+ def after_valid
24
+ puts "Selected version is: #{@selection}\n"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ module RailsNewApp
2
+ class RubyLinterStep < ChoiceStep
3
+ def step_question
4
+ "Type the option number of the Ruby Linter gem to use:"
5
+ end
6
+
7
+ def options
8
+ ["None (Default)", "RuboCop", "StandardRB"]
9
+ end
10
+
11
+ def lowercase_keys
12
+ ["", "rubocop", "standardrb"]
13
+ end
14
+
15
+ def after_valid
16
+ puts "Selected Ruby linter is: #{option}\n"
17
+ end
18
+
19
+ def self.default
20
+ {
21
+ option_number: 0,
22
+ name: "None (Default)",
23
+ key: "",
24
+ }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,65 @@
1
+ module RailsNewApp
2
+ class Step
3
+ def self.run(config)
4
+ new.run(config)
5
+ end
6
+
7
+ def config
8
+ @config
9
+ end
10
+
11
+ def run(current_config)
12
+ @config = current_config
13
+
14
+ system("clear") if config[:navigation]
15
+
16
+ ask
17
+ read_and_validate
18
+ after_valid
19
+ return_value
20
+ end
21
+
22
+ def step_title
23
+ "Generic step question"
24
+ end
25
+
26
+ # describe the current step
27
+ def ask
28
+ puts step_question
29
+ end
30
+
31
+ # loop until the input is valid, sets @selection
32
+ def read_and_validate
33
+ loop do
34
+ input = clean_input(gets.chomp)
35
+ if valid?(input)
36
+ @selection = input
37
+ return true
38
+ end
39
+ end
40
+ end
41
+
42
+ # clean the input if needed before validations
43
+ def clean_input(input)
44
+ input.strip
45
+ end
46
+
47
+ # validate the input
48
+ def valid?(input)
49
+ true
50
+ end
51
+
52
+ # after valid message
53
+ def after_valid
54
+ end
55
+
56
+ # process @selection to return a different value
57
+ def return_value
58
+ @selection
59
+ end
60
+
61
+ def self.default
62
+ ""
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,27 @@
1
+ module RailsNewApp
2
+ class TemplateEngineStep < ChoiceStep
3
+ def step_question
4
+ "Type the option number of the Template Engine gem to use:"
5
+ end
6
+
7
+ def options
8
+ ["None (Default)", "Slim", "HAML"]
9
+ end
10
+
11
+ def lowercase_keys
12
+ ["", "slim", "haml"]
13
+ end
14
+
15
+ def after_valid
16
+ puts "Selected template engine is: #{option}\n"
17
+ end
18
+
19
+ def self.default
20
+ {
21
+ option_number: 0,
22
+ name: "None (Default)",
23
+ key: "",
24
+ }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ module RailsNewApp
2
+ class TestRunnerStep < ChoiceStep
3
+ def options
4
+ ["None", "Minitest (Default)", "RSpec"]
5
+ end
6
+
7
+ def lowercase_keys
8
+ ["", "minitest", "rspec"]
9
+ end
10
+
11
+ def step_question
12
+ "Type the option number of the test runner gem to use:"
13
+ end
14
+
15
+ def after_valid
16
+ "Selected test runner is: #{option}\n"
17
+ end
18
+
19
+ def self.default
20
+ {
21
+ option_number: 1,
22
+ name: "Minitest (Default)",
23
+ key: "minitest",
24
+ in_rails_new: true
25
+ }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,7 @@
1
+ module RailsNewApp
2
+ class YesNoChoiceStep < ChoiceStep
3
+ def options
4
+ ["Yes", "No"]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ generate "formtastic:install"
@@ -0,0 +1 @@
1
+ gem "formtastic", "~> 4.0"
@@ -0,0 +1 @@
1
+ gem "haml"
@@ -0,0 +1,23 @@
1
+ generate "rspec:install"
2
+
3
+ # Create the spec folders for RSpec
4
+ run "mkdir spec"
5
+ run "mkdir spec/models"
6
+ run "mkdir spec/controllers"
7
+ run "mkdir spec/system"
8
+ run "mkdir spec/views"
9
+ run "mkdir spec/routes"
10
+ run "mkdir spec/jobs"
11
+ run "mkdir spec/helpers"
12
+ run "mkdir spec/mailers"
13
+ run "mkdir spec/factories"
14
+
15
+ # Add `rails spec` task to run tests
16
+ inject_into_file "Rakefile", before: "Rails.application.load_tasks\n" do <<-'RUBY'
17
+ begin
18
+ require "rspec/core/rake_task"
19
+ RSpec::Core::RakeTask.new(:spec)
20
+ rescue LoadError
21
+ end
22
+ RUBY
23
+ end
@@ -0,0 +1,3 @@
1
+ gem_group :test do
2
+ gem "rspec-rails"
3
+ end
@@ -0,0 +1,2 @@
1
+ # apply automatic style fixes
2
+ run "bundle exec rubocop -a"
@@ -0,0 +1,5 @@
1
+ gem_group :development, :test do
2
+ gem "rubocop"
3
+ gem "rubocop-rails"
4
+ gem "rubocop-minitest"
5
+ end
@@ -0,0 +1,5 @@
1
+ gem_group :development, :test do
2
+ gem "rubocop"
3
+ gem "rubocop-rails"
4
+ gem "rubocop-rspec"
5
+ end
@@ -0,0 +1 @@
1
+ generate "simple_form:install"
@@ -0,0 +1 @@
1
+ gem "simple_form"
@@ -0,0 +1,3 @@
1
+ gem_group :development, :test do
2
+ gem "simplecov", require: false
3
+ end
@@ -0,0 +1,5 @@
1
+ prepend_file "test/test_helper.rb" do <<-'RUBY'
2
+ require "simplecov"
3
+ SimpleCov.start
4
+ RUBY
5
+ end
@@ -0,0 +1,5 @@
1
+ inject_into_file "spec/spec_helper.rb", before: "RSpec.configure do |config|\n" do <<-'RUBY'
2
+ require "simplecov"
3
+ SimpleCov.start
4
+ RUBY
5
+ end
@@ -0,0 +1 @@
1
+ gem "slim"
@@ -0,0 +1,3 @@
1
+ # apply automatic style fixes
2
+ # debug this, it's failing
3
+ # rake "standard:fix"
@@ -0,0 +1,5 @@
1
+ gem_group :development, :test do
2
+ gem "standard"
3
+ gem "rubocop-rails"
4
+ gem "rubocop-minitest"
5
+ end
@@ -0,0 +1,5 @@
1
+ gem_group :development, :test do
2
+ gem "standard"
3
+ gem "rubocop-rails"
4
+ gem "rubocop-rspec"
5
+ end
@@ -0,0 +1,3 @@
1
+ module RailsNewApp
2
+ VERSION = Gem::Version.new("0.0.2")
3
+ end
@@ -0,0 +1,21 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "rails-new-app/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rails-new-app"
7
+ s.version = RailsNewApp::VERSION
8
+ s.authors = ["Ariel Juodziukynas"]
9
+ s.email = ["arieljuod@gmail.com"]
10
+ s.license = 'MIT'
11
+
12
+ s.summary = "Command-line tool to assist the creation of new Rails apps"
13
+ s.homepage = "https://github.com/arielj/rails-new-app"
14
+
15
+ s.files = Dir.chdir(File.expand_path("..", __FILE__)) do
16
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ end
18
+ s.bindir = "exe"
19
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-new-app
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Ariel Juodziukynas
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-05-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - arieljuod@gmail.com
16
+ executables:
17
+ - rails-new-app
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - LICENSE
23
+ - README.md
24
+ - exe/rails-new-app
25
+ - lib/rails-new-app.rb
26
+ - lib/rails-new-app/processors.rb
27
+ - lib/rails-new-app/processors/code_coverage_processor.rb
28
+ - lib/rails-new-app/processors/form_builder_processor.rb
29
+ - lib/rails-new-app/processors/processor.rb
30
+ - lib/rails-new-app/processors/ruby_linter_processor.rb
31
+ - lib/rails-new-app/processors/template_engine_processor.rb
32
+ - lib/rails-new-app/processors/test_runner_processor.rb
33
+ - lib/rails-new-app/runner.rb
34
+ - lib/rails-new-app/steps.rb
35
+ - lib/rails-new-app/steps/app_name_step.rb
36
+ - lib/rails-new-app/steps/choice_step.rb
37
+ - lib/rails-new-app/steps/code_coverage_step.rb
38
+ - lib/rails-new-app/steps/database_step.rb
39
+ - lib/rails-new-app/steps/form_builder_step.rb
40
+ - lib/rails-new-app/steps/java_script_framework_step.rb
41
+ - lib/rails-new-app/steps/rails_version_step.rb
42
+ - lib/rails-new-app/steps/ruby_linter_step.rb
43
+ - lib/rails-new-app/steps/step.rb
44
+ - lib/rails-new-app/steps/template_engine_step.rb
45
+ - lib/rails-new-app/steps/test_runner_step.rb
46
+ - lib/rails-new-app/steps/yes_no_choice_step.rb
47
+ - lib/rails-new-app/templates/formtastic-config.rb
48
+ - lib/rails-new-app/templates/formtastic-gemfile.rb
49
+ - lib/rails-new-app/templates/haml-gemfile.rb
50
+ - lib/rails-new-app/templates/rspec-rails-config.rb
51
+ - lib/rails-new-app/templates/rspec-rails-gemfile.rb
52
+ - lib/rails-new-app/templates/rubocop-config.rb
53
+ - lib/rails-new-app/templates/rubocop-minitest-gemfile.rb
54
+ - lib/rails-new-app/templates/rubocop-rspec-gemfile.rb
55
+ - lib/rails-new-app/templates/simple_form-config.rb
56
+ - lib/rails-new-app/templates/simple_form-gemfile.rb
57
+ - lib/rails-new-app/templates/simplecov-gemfile.rb
58
+ - lib/rails-new-app/templates/simplecov-minitest-config.rb
59
+ - lib/rails-new-app/templates/simplecov-rspec-config.rb
60
+ - lib/rails-new-app/templates/slim-gemfile.rb
61
+ - lib/rails-new-app/templates/standardrb-config.rb
62
+ - lib/rails-new-app/templates/standardrb-minitest-gemfile.rb
63
+ - lib/rails-new-app/templates/standardrb-rspec-gemfile.rb
64
+ - lib/rails-new-app/version.rb
65
+ - rails-new-app.gemspec
66
+ homepage: https://github.com/arielj/rails-new-app
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubygems_version: 3.0.9
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Command-line tool to assist the creation of new Rails apps
89
+ test_files: []