rails-new-app 0.0.2 → 0.0.3
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/README.md +16 -8
- data/lib/rails-new-app.rb +2 -1
- data/lib/rails-new-app/processors.rb +1 -1
- data/lib/rails-new-app/processors/code_coverage_processor.rb +1 -1
- data/lib/rails-new-app/processors/pagination_processor.rb +18 -0
- data/lib/rails-new-app/processors/processor.rb +2 -0
- data/lib/rails-new-app/processors/ruby_linter_processor.rb +6 -2
- data/lib/rails-new-app/processors/test_factory_processor.rb +20 -0
- data/lib/rails-new-app/processors/test_fake_data_processor.rb +11 -0
- data/lib/rails-new-app/runner.rb +140 -103
- data/lib/rails-new-app/steps.rb +1 -1
- data/lib/rails-new-app/steps/app_name_step.rb +1 -1
- data/lib/rails-new-app/steps/choice_step.rb +5 -3
- data/lib/rails-new-app/steps/code_coverage_step.rb +6 -2
- data/lib/rails-new-app/steps/database_step.rb +2 -2
- data/lib/rails-new-app/steps/form_builder_step.rb +3 -3
- data/lib/rails-new-app/steps/java_script_framework_step.rb +7 -7
- data/lib/rails-new-app/steps/pagination_step.rb +27 -0
- data/lib/rails-new-app/steps/rails_version_step.rb +17 -10
- data/lib/rails-new-app/steps/ruby_linter_step.rb +3 -3
- data/lib/rails-new-app/steps/step.rb +16 -6
- data/lib/rails-new-app/steps/template_engine_step.rb +3 -3
- data/lib/rails-new-app/steps/test_factory_step.rb +38 -0
- data/lib/rails-new-app/steps/test_fake_data.rb +34 -0
- data/lib/rails-new-app/steps/test_runner_step.rb +6 -2
- data/lib/rails-new-app/steps/yes_no_choice_step.rb +1 -1
- data/lib/rails-new-app/string_underscore.rb +9 -0
- data/lib/rails-new-app/templates/factory_bot-gemfile.rb +3 -0
- data/lib/rails-new-app/templates/factory_bot-minitest-config.rb +1 -0
- data/lib/rails-new-app/templates/factory_bot-rspec-config.rb +1 -0
- data/lib/rails-new-app/templates/faker-gemfile.rb +3 -0
- data/lib/rails-new-app/templates/kaminari-gemfile.rb +1 -0
- data/lib/rails-new-app/templates/pagy-config.rb +13 -0
- data/lib/rails-new-app/templates/pagy-gemfile.rb +1 -0
- data/lib/rails-new-app/templates/rspec-rails-config.rb +8 -8
- data/lib/rails-new-app/templates/{standardrb-minitest-gemfile.rb → rubocop-gemfile.rb} +1 -2
- data/lib/rails-new-app/templates/rubocop-minitest-gemfile.rb +0 -2
- data/lib/rails-new-app/templates/rubocop-rspec-gemfile.rb +0 -2
- data/lib/rails-new-app/templates/simplecov-minitest-config.rb +5 -4
- data/lib/rails-new-app/templates/simplecov-rspec-config.rb +5 -4
- data/lib/rails-new-app/templates/{standardrb-rspec-gemfile.rb → standardrb-gemfile.rb} +0 -1
- data/lib/rails-new-app/templates/will_paginate-gemfile.rb +1 -0
- data/lib/rails-new-app/version.rb +2 -2
- data/rails-new-app.gemspec +1 -1
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93081e6a5b8f36849c4d4a799966cefd00ca97133cfe35bef967c020fd7eff63
|
4
|
+
data.tar.gz: b629ee3815475d9917eeefedc90d8973a9d7162c5b27ab93c13625646c038df3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a2d9590d597b7ac2abe68b4d27ac09b274ee48fc52dc9bba40cfa28c3c41357bb5594e0be4fef2859df877936b20a98ecb5c1d4bb20366dc8c9d5cf69cd318f
|
7
|
+
data.tar.gz: 56bc800f44e839ae8ba63fb810890365d7963e8100c6e01fafa494a8846cc0d43039fc279bdb22820e2b6ab78e880a27f187882e14580650c4137018f8c026cf
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# rails-new-app
|
2
|
-
Command-line tool to assist the creation of new Rails 5 and 6 apps
|
2
|
+
Command-line tool to assist in the creation of new Rails 5 and 6 apps
|
3
3
|
|
4
4
|
## Installation:
|
5
5
|
|
@@ -16,12 +16,16 @@ If, for any reason, the menu navigation does not work, run `rails-new-app naviga
|
|
16
16
|
## Current configurations:
|
17
17
|
- Rails version (validate and install)
|
18
18
|
- Database: none / MySQL / PostgreSQL / SQLite
|
19
|
-
- Tests:
|
20
|
-
-
|
19
|
+
- Tests:
|
20
|
+
- - runner: none / Minitest / RSpec
|
21
|
+
- - CodeCoverage: none / Simplecov
|
22
|
+
- - Factories: none / FactoryBot
|
23
|
+
- - Fake data: none / Faker
|
21
24
|
- TemplateEngine: None (just ERB) / Slim / HAML
|
22
25
|
- RubyLinter: None / RuboCop / StandardRB
|
23
26
|
- FormBuilder: None / Simple Form / Formtastic
|
24
27
|
- JS Framework: None / ReactJS / VueJS / Angular / Elm / Stimulus
|
28
|
+
- Pagination: None / Pagy / Kaminari / WillPaginate
|
25
29
|
|
26
30
|
## TODOs and ideas:
|
27
31
|
- improve GUI and UX
|
@@ -33,7 +37,6 @@ If, for any reason, the menu navigation does not work, run `rails-new-app naviga
|
|
33
37
|
- support `rails new` flags configuration
|
34
38
|
- research requirements
|
35
39
|
- 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
40
|
- show the user the current Ruby version
|
38
41
|
- support a `rails-new-app-defaults` file at the HOME dir to set default options if empty answers
|
39
42
|
|
@@ -42,8 +45,6 @@ If, for any reason, the menu navigation does not work, run `rails-new-app naviga
|
|
42
45
|
- type of app: standard/minimal/api
|
43
46
|
- CI config? github actions / travis / circleci / bitbucket / gitlab / others
|
44
47
|
- js linter? None/ESlint/StandardJS
|
45
|
-
- factory_bot?
|
46
|
-
- faker?
|
47
48
|
- devise?
|
48
49
|
- carrierwave/paperclip/dragonfly?
|
49
50
|
- exception_notification / airbreak / other reporting tools
|
@@ -54,8 +55,8 @@ If, for any reason, the menu navigation does not work, run `rails-new-app naviga
|
|
54
55
|
- CSS framework? bootstrap/tailwind/material/spectre/bulma (this affects the form builders processor)
|
55
56
|
- add basic docker config?
|
56
57
|
- admin gems? ActiveAdmin/RailsAdmin/Trestle/others
|
57
|
-
- pagination? pagy/kaminari/will_paginate
|
58
58
|
- pre-commit hooks? overcommit
|
59
|
+
- cancancan/pundit ?
|
59
60
|
|
60
61
|
## Adding more configurations and tools:
|
61
62
|
|
@@ -75,4 +76,11 @@ If, for any reason, the menu navigation does not work, run `rails-new-app naviga
|
|
75
76
|
This is a really early Alpha version as a proof of concept.
|
76
77
|
|
77
78
|
### 0.0.2
|
78
|
-
Added navigation between
|
79
|
+
Added navigation between menus.
|
80
|
+
|
81
|
+
### 0.0.3
|
82
|
+
- Added `next_step` to configure related tools without going back to menu
|
83
|
+
- Apply linter fixes after creation
|
84
|
+
- Add a git initial commit
|
85
|
+
- Added new tools: Faker, pagination gems
|
86
|
+
- Bug fixing
|
data/lib/rails-new-app.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require_relative "rails-new-app/string_underscore"
|
1
2
|
require_relative "rails-new-app/version"
|
2
3
|
require_relative "rails-new-app/runner"
|
3
4
|
|
@@ -13,7 +14,7 @@ module RailsNewApp
|
|
13
14
|
end
|
14
15
|
end
|
15
16
|
ARGV.clear
|
16
|
-
|
17
|
+
|
17
18
|
Runner.new.run(navigation)
|
18
19
|
end
|
19
20
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module RailsNewApp
|
2
|
+
class PaginationProcessor < Processor
|
3
|
+
def update_gemfile(config)
|
4
|
+
case config[:pagination][:key]
|
5
|
+
when "pagy" then apply_template "pagy-gemfile"
|
6
|
+
when "kaminari" then apply_template "kaminari-gemfile"
|
7
|
+
when "will_paginate" then apply_template "will_paginate-gemfile"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def configure(config)
|
12
|
+
puts "Processing Pagination config"
|
13
|
+
case config[:pagination][:key]
|
14
|
+
when "pagy" then apply_template "pagy-config"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -2,8 +2,12 @@ module RailsNewApp
|
|
2
2
|
class RubyLinterProcessor < Processor
|
3
3
|
def update_gemfile(config)
|
4
4
|
case config[:ruby_linter][:key]
|
5
|
-
when "rubocop"
|
6
|
-
|
5
|
+
when "rubocop", "standardrb"
|
6
|
+
apply_template "#{config[:ruby_linter][:key]}-gemfile"
|
7
|
+
case config[:test_runner][:key]
|
8
|
+
when "minitest" then apply_template "rubocop-minitest-gemfile"
|
9
|
+
when "rspec" then apply_template "rubocop-rspec-gemfile"
|
10
|
+
end
|
7
11
|
end
|
8
12
|
end
|
9
13
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module RailsNewApp
|
2
|
+
class TestFactoryProcessor < Processor
|
3
|
+
def update_gemfile(config)
|
4
|
+
return if config[:test_runner][:key] == ""
|
5
|
+
|
6
|
+
case config[:test_factory][:key]
|
7
|
+
when "factory_bot" then apply_template "factory_bot-gemfile"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def configure(config)
|
12
|
+
return if config[:test_runner][:key] == ""
|
13
|
+
|
14
|
+
puts "Processing Test Factory config"
|
15
|
+
case config[:test_factory][:key]
|
16
|
+
when "factory_boy" then apply_template "factory_bot-#{config[:test_runner][:key]}-config"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/rails-new-app/runner.rb
CHANGED
@@ -4,36 +4,41 @@ require "readline"
|
|
4
4
|
|
5
5
|
module RailsNewApp
|
6
6
|
class Runner
|
7
|
-
|
8
|
-
|
9
|
-
"
|
10
|
-
"
|
11
|
-
"
|
12
|
-
"
|
13
|
-
"
|
14
|
-
"
|
15
|
-
"
|
16
|
-
"
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
7
|
+
# use option: nil to hide the screen from the main menu
|
8
|
+
SCREENS = [
|
9
|
+
{option: "1", class: AppNameStep},
|
10
|
+
{option: "2", class: RailsVersionStep},
|
11
|
+
{option: "3", class: DatabaseStep},
|
12
|
+
{option: "4", class: TestRunnerStep},
|
13
|
+
{option: "5", class: JavaScriptFrameworkStep},
|
14
|
+
{option: "6", class: RubyLinterStep},
|
15
|
+
{option: "7", class: TemplateEngineStep},
|
16
|
+
{option: "8", class: FormBuilderStep},
|
17
|
+
{option: "9", class: PaginationStep},
|
18
|
+
{option: nil, class: CodeCoverageStep},
|
19
|
+
{option: nil, class: TestFactoryStep},
|
20
|
+
{option: nil, class: TestFakeDataStep}
|
21
|
+
].freeze
|
22
|
+
|
23
|
+
def get_screen(option)
|
24
|
+
case option.to_s
|
25
|
+
when /\A\d+\z/
|
26
|
+
SCREENS.find { |x| x[:option] == option.to_s }
|
27
|
+
else
|
28
|
+
SCREENS.find { |x| x[:class].key == option.to_sym }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
attr_reader :config
|
33
|
+
|
23
34
|
# entry point
|
24
35
|
def run(navigation = true)
|
25
|
-
@config = {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
}
|
36
|
+
@config = {navigation: navigation}.tap do |h|
|
37
|
+
SCREENS.each do |s|
|
38
|
+
kls = s[:class]
|
39
|
+
h[kls.key] = kls.default
|
40
|
+
end
|
41
|
+
end
|
37
42
|
|
38
43
|
intro
|
39
44
|
|
@@ -60,23 +65,24 @@ module RailsNewApp
|
|
60
65
|
def clear
|
61
66
|
system("clear")
|
62
67
|
end
|
63
|
-
|
68
|
+
|
64
69
|
def intro
|
65
70
|
clear
|
66
71
|
puts "Let's create a new Rails app step by step"
|
67
72
|
end
|
68
73
|
|
69
74
|
def print_screens
|
70
|
-
SCREENS.each do |
|
71
|
-
|
72
|
-
|
75
|
+
SCREENS.each do |s|
|
76
|
+
next if s[:option].nil?
|
77
|
+
|
78
|
+
screen_name = s[:class].clean_name
|
79
|
+
puts "#{s[:option]} : #{screen_name}"
|
73
80
|
end
|
74
81
|
puts "0 : Review and confirm"
|
75
82
|
puts ""
|
76
83
|
puts "Type the number of the menu and press enter:"
|
77
84
|
end
|
78
85
|
|
79
|
-
|
80
86
|
def show_menu
|
81
87
|
print_screens
|
82
88
|
loop do
|
@@ -89,134 +95,153 @@ module RailsNewApp
|
|
89
95
|
clear
|
90
96
|
print_screens
|
91
97
|
else
|
92
|
-
|
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
|
98
|
+
show_screen(option)
|
101
99
|
end
|
102
100
|
end
|
103
101
|
end
|
104
|
-
|
102
|
+
|
103
|
+
def show_screen(option)
|
104
|
+
if (s = get_screen(option))
|
105
|
+
screen_obj = s[:class].new
|
106
|
+
config[s[:class].key] = screen_obj.run(config)
|
107
|
+
clear
|
108
|
+
screen_obj.next_step ? show_screen(screen_obj.next_step) : print_screens
|
109
|
+
else
|
110
|
+
puts "Invalid option, select a category:"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
105
114
|
def steps
|
106
115
|
config[:app_name] = AppNameStep.run(config)
|
107
|
-
config[:
|
116
|
+
config[:rails_version] = RailsVersionStep.run(config)
|
108
117
|
config[:database] = DatabaseStep.run(config)
|
109
118
|
config[:test_runner] = TestRunnerStep.run(config)
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
CodeCoverageStep.run(config)
|
118
|
-
end
|
119
|
-
|
119
|
+
|
120
|
+
if config[:test_runner][:key] != ""
|
121
|
+
config[:code_coverage] = CodeCoverageStep.run(config)
|
122
|
+
config[:test_factory] = TestFactoryStep.run(config)
|
123
|
+
config[:test_fake_data] = TestFakeDataStep.run(config)
|
124
|
+
end
|
125
|
+
|
120
126
|
config[:js_framework] = JavaScriptFrameworkStep.run(config)
|
121
127
|
config[:ruby_linter] = RubyLinterStep.run(config)
|
122
128
|
config[:template_engine] = TemplateEngineStep.run(config)
|
123
129
|
config[:form_builder] = FormBuilderStep.run(config)
|
130
|
+
config[:pagination] = PaginationStep.run(config)
|
124
131
|
end
|
125
|
-
|
132
|
+
|
126
133
|
def review_and_confirm
|
127
134
|
clear
|
128
|
-
rails_ver = config[:
|
135
|
+
rails_ver = config[:rails_version]
|
129
136
|
rails_ver = "Using latest installed Rails version" if rails_ver == ""
|
130
137
|
|
131
|
-
puts
|
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
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
138
|
+
puts <<~REVIEW
|
139
|
+
===== New Rails app config =====
|
140
|
+
|
141
|
+
App name: #{config[:app_name]}
|
142
|
+
Ruby version: #{RUBY_VERSION}
|
143
|
+
Rails version: #{rails_ver}
|
144
|
+
Database: #{config[:database]}
|
145
|
+
Test runner: #{config[:test_runner]}
|
146
|
+
Code coverage: #{config[:code_coverage]}
|
147
|
+
Test factories: #{config[:test_factory]}
|
148
|
+
Test fake data: #{config[:test_fake_data]}
|
149
|
+
JS framework: #{config[:java_script_framework]}
|
150
|
+
Ruby Linter: #{config[:ruby_linter]}
|
151
|
+
Template engine: #{config[:template_engine]}
|
152
|
+
Form builder: #{config[:form_builder]}
|
153
|
+
Pagination: #{config[:pagination]}
|
154
|
+
|
155
|
+
REVIEW
|
146
156
|
|
147
157
|
message = "Type 'Y(es)' to confirm, 'B(ack) to go back, or 'N(o)' to abort"
|
148
158
|
if config[:app_name] == ""
|
149
|
-
puts
|
150
|
-
=====================================
|
151
|
-
|
152
|
-
=====================================
|
153
|
-
|
154
|
-
WARNING
|
159
|
+
puts <<~WARNING
|
160
|
+
=====================================
|
161
|
+
App name is required
|
162
|
+
=====================================
|
163
|
+
|
164
|
+
WARNING
|
155
165
|
message.gsub!("Type 'Y(es)' to confirm, ", "Type ")
|
156
166
|
end
|
157
167
|
|
158
168
|
loop do
|
159
169
|
puts message
|
160
170
|
answer = gets.chomp.strip
|
161
|
-
return :yes if
|
162
|
-
return :back if
|
163
|
-
return :no if
|
171
|
+
return :yes if /\A*Y(es)?\z/i.match?(answer)
|
172
|
+
return :back if /\A*B(ack)?\z/i.match?(answer)
|
173
|
+
return :no if /\A*N(o)?\z/i.match?(answer)
|
164
174
|
|
165
175
|
puts "Invalid option."
|
166
176
|
end
|
167
177
|
end
|
168
|
-
|
178
|
+
|
169
179
|
def install_rails
|
170
|
-
return if config[:
|
180
|
+
return if config[:rails_version] == ""
|
171
181
|
# install the require rails version if needed
|
172
182
|
puts "Verifying and installing Rails #{config[:rails_ven]}"
|
173
|
-
`gem install rails -v#{config[:
|
183
|
+
`gem install rails -v#{config[:rails_version]}`
|
174
184
|
end
|
175
|
-
|
185
|
+
|
176
186
|
def rails_new
|
177
187
|
puts "Running Rails new"
|
178
188
|
command = build_rails_new_command
|
179
|
-
|
189
|
+
puts command
|
180
190
|
system(command)
|
181
191
|
end
|
182
|
-
|
192
|
+
|
183
193
|
def process_config
|
184
194
|
# cd into rails app
|
185
195
|
Dir.chdir(config[:app_name]) do
|
186
196
|
# add different gems
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
197
|
+
[
|
198
|
+
TestRunnerProcessor,
|
199
|
+
CodeCoverageProcessor,
|
200
|
+
TestFactoryProcessor,
|
201
|
+
TestFakeDataProcessor,
|
202
|
+
TemplateEngineProcessor,
|
203
|
+
FormBuilderProcessor,
|
204
|
+
RubyLinterProcessor,
|
205
|
+
PaginationProcessor
|
206
|
+
].each { |p| p.update_gemfile(config) }
|
192
207
|
|
193
208
|
# install gems
|
194
209
|
system("bundle install")
|
195
210
|
|
196
|
-
#configure each gem
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
211
|
+
# configure each gem
|
212
|
+
[
|
213
|
+
TestRunnerProcessor,
|
214
|
+
CodeCoverageProcessor,
|
215
|
+
TestFactoryProcessor,
|
216
|
+
FormBuilderProcessor,
|
217
|
+
RubyLinterProcessor,
|
218
|
+
PaginationProcessor
|
219
|
+
].each { |p| p.configure(config) }
|
220
|
+
|
221
|
+
after_create
|
202
222
|
end
|
203
223
|
end
|
204
|
-
|
224
|
+
|
225
|
+
def after_create
|
226
|
+
fix_code_style
|
227
|
+
initial_commit
|
228
|
+
end
|
229
|
+
|
205
230
|
def end_message
|
206
231
|
puts "Your new Rails app is ready!"
|
207
232
|
end
|
208
|
-
|
233
|
+
|
209
234
|
def aborted_message
|
210
235
|
puts "Aborted"
|
211
236
|
end
|
212
|
-
|
237
|
+
|
213
238
|
private
|
214
|
-
|
239
|
+
|
215
240
|
# final step and creation
|
216
241
|
def build_rails_new_command
|
217
242
|
["rails"].tap do |ar|
|
218
243
|
# use specific Rails version
|
219
|
-
ar << "_#{config[:
|
244
|
+
ar << "_#{config[:rails_version]}_" if config[:rails_version] != ""
|
220
245
|
# new command
|
221
246
|
ar << "new"
|
222
247
|
# use desired database
|
@@ -224,11 +249,23 @@ WARNING
|
|
224
249
|
# ignore test if not minitest
|
225
250
|
ar << "--skip_test" if config[:test_runner][:key] != "minitest"
|
226
251
|
# use desired js framework
|
227
|
-
ar << "--webpack=#{config[:
|
252
|
+
ar << "--webpack=#{config[:java_script_framework][:key]}" if config[:java_script_framework][:in_rails_new]
|
228
253
|
# ar << "--skip-javascript"
|
229
254
|
# add app name
|
230
255
|
ar << config[:app_name]
|
231
256
|
end.join(" ")
|
232
257
|
end
|
258
|
+
|
259
|
+
def fix_code_style
|
260
|
+
case config[:ruby_linter][:key]
|
261
|
+
when "rubocop" then system("rubocop -A")
|
262
|
+
when "standardrb" then system("standardrb --fix")
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
def initial_commit
|
267
|
+
system("git add .")
|
268
|
+
system("git commit -a -m 'Initial commit'")
|
269
|
+
end
|
233
270
|
end
|
234
271
|
end
|
data/lib/rails-new-app/steps.rb
CHANGED
@@ -12,15 +12,17 @@ module RailsNewApp
|
|
12
12
|
puts step_question
|
13
13
|
puts ""
|
14
14
|
|
15
|
+
current = config[self.class.key][:option_number]
|
15
16
|
options.each_with_index do |op, idx|
|
16
|
-
|
17
|
+
is_current = idx == current ? " (current)" : ""
|
18
|
+
puts "#{idx} ) #{op}#{is_current}"
|
17
19
|
end
|
18
20
|
end
|
19
|
-
|
21
|
+
|
20
22
|
def clean_input(input)
|
21
23
|
input.to_i
|
22
24
|
end
|
23
|
-
|
25
|
+
|
24
26
|
def valid?(input)
|
25
27
|
if options[input]
|
26
28
|
true
|
@@ -11,7 +11,7 @@ module RailsNewApp
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def options
|
14
|
-
["None
|
14
|
+
["None", "SimpleCov"]
|
15
15
|
end
|
16
16
|
|
17
17
|
def lowercase_keys
|
@@ -26,8 +26,12 @@ module RailsNewApp
|
|
26
26
|
{
|
27
27
|
option_number: 0,
|
28
28
|
name: "None (Default)",
|
29
|
-
key: ""
|
29
|
+
key: ""
|
30
30
|
}
|
31
31
|
end
|
32
|
+
|
33
|
+
def next_step
|
34
|
+
:test_factory
|
35
|
+
end
|
32
36
|
end
|
33
37
|
end
|
@@ -5,7 +5,7 @@ module RailsNewApp
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def options
|
8
|
-
["None", "SQLite
|
8
|
+
["None", "SQLite", "MySQL / MariaDB", "PostgreSQL"]
|
9
9
|
end
|
10
10
|
|
11
11
|
def lowercase_keys
|
@@ -29,7 +29,7 @@ module RailsNewApp
|
|
29
29
|
def self.default
|
30
30
|
{
|
31
31
|
option_number: "1",
|
32
|
-
name: "SQLite
|
32
|
+
name: "SQLite",
|
33
33
|
key: "sqlite3",
|
34
34
|
in_rails_new: true
|
35
35
|
}
|
@@ -5,7 +5,7 @@ module RailsNewApp
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def options
|
8
|
-
["None
|
8
|
+
["None", "Simple Form", "Formtastic"]
|
9
9
|
end
|
10
10
|
|
11
11
|
def lowercase_keys
|
@@ -19,8 +19,8 @@ module RailsNewApp
|
|
19
19
|
def self.default
|
20
20
|
{
|
21
21
|
option_number: 0,
|
22
|
-
name: "None
|
23
|
-
key: ""
|
22
|
+
name: "None",
|
23
|
+
key: ""
|
24
24
|
}
|
25
25
|
end
|
26
26
|
end
|
@@ -3,23 +3,23 @@ module RailsNewApp
|
|
3
3
|
def rails_new_options
|
4
4
|
%W[react vue angular elm stimulus]
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
def options
|
8
|
-
["None
|
8
|
+
["None", "ReactJS", "VueJS", "Angular", "Elm", "Stimulus"]
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def lowercase_keys
|
12
12
|
["", "react", "vue", "angular", "elm", "stimulus"]
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def step_question
|
16
16
|
"Type the option number of the JavaScript framework to use:"
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def after_valid
|
20
20
|
puts "Selected framework is: #{option}\n"
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def return_value
|
24
24
|
super.tap do |h|
|
25
25
|
h[:in_rails_new] = rails_new_options.include?(h[:key])
|
@@ -29,7 +29,7 @@ module RailsNewApp
|
|
29
29
|
def self.default
|
30
30
|
{
|
31
31
|
option_number: 0,
|
32
|
-
name: "None
|
32
|
+
name: "None",
|
33
33
|
key: "",
|
34
34
|
in_rails_new: false
|
35
35
|
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module RailsNewApp
|
2
|
+
class PaginationStep < ChoiceStep
|
3
|
+
def step_question
|
4
|
+
"Type the option number of the Pagination gem to use:"
|
5
|
+
end
|
6
|
+
|
7
|
+
def options
|
8
|
+
["None", "Pagy", "Kaminari", "WillPaginate"]
|
9
|
+
end
|
10
|
+
|
11
|
+
def lowercase_keys
|
12
|
+
["", "pagy", "kaminari", "will_paginate"]
|
13
|
+
end
|
14
|
+
|
15
|
+
def after_valid
|
16
|
+
puts "Selected pagination gem is: #{option}\n"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.default
|
20
|
+
{
|
21
|
+
option_number: 0,
|
22
|
+
name: "None",
|
23
|
+
key: ""
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,27 +1,34 @@
|
|
1
1
|
module RailsNewApp
|
2
2
|
class RailsVersionStep < Step
|
3
3
|
def valid?(ver)
|
4
|
-
if
|
5
|
-
# puts "Validating against Rubygems..."
|
4
|
+
if /\A[56].\d\z/.match?(ver)
|
6
5
|
# uncomment this to validate the input against RubyGems
|
7
|
-
|
8
|
-
|
6
|
+
puts "Validating against Rubygems..."
|
7
|
+
if `gem list -r -e -a rails | grep '[\( ]#{ver}\.'` != ""
|
8
|
+
true
|
9
|
+
else
|
10
|
+
puts "Invalid Rails version, type the version you want to use:"
|
11
|
+
end
|
9
12
|
else
|
10
13
|
puts "Invalid Rails version, type the version you want to use:"
|
11
14
|
false
|
12
15
|
end
|
13
16
|
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
17
|
|
20
|
-
|
18
|
+
def step_question
|
19
|
+
<<~QUESTION
|
20
|
+
Type the version of Rails you want to use (MAJOR.MINOR):
|
21
|
+
! Notice that Rails will use the latest patch version for a given version !
|
22
|
+
|
23
|
+
QUESTION
|
21
24
|
end
|
22
25
|
|
23
26
|
def after_valid
|
24
27
|
puts "Selected version is: #{@selection}\n"
|
25
28
|
end
|
29
|
+
|
30
|
+
def self.default
|
31
|
+
""
|
32
|
+
end
|
26
33
|
end
|
27
34
|
end
|
@@ -5,7 +5,7 @@ module RailsNewApp
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def options
|
8
|
-
["None
|
8
|
+
["None", "RuboCop", "StandardRB"]
|
9
9
|
end
|
10
10
|
|
11
11
|
def lowercase_keys
|
@@ -19,8 +19,8 @@ module RailsNewApp
|
|
19
19
|
def self.default
|
20
20
|
{
|
21
21
|
option_number: 0,
|
22
|
-
name: "None
|
23
|
-
key: ""
|
22
|
+
name: "None",
|
23
|
+
key: ""
|
24
24
|
}
|
25
25
|
end
|
26
26
|
end
|
@@ -1,18 +1,24 @@
|
|
1
1
|
module RailsNewApp
|
2
2
|
class Step
|
3
|
+
def self.clean_name
|
4
|
+
to_s.gsub("Step", "").gsub("RailsNewApp::", "")
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.key
|
8
|
+
clean_name.underscore.to_sym
|
9
|
+
end
|
10
|
+
|
3
11
|
def self.run(config)
|
4
12
|
new.run(config)
|
5
13
|
end
|
6
14
|
|
7
|
-
|
8
|
-
@config
|
9
|
-
end
|
15
|
+
attr_reader :config
|
10
16
|
|
11
17
|
def run(current_config)
|
12
18
|
@config = current_config
|
13
|
-
|
19
|
+
|
14
20
|
system("clear") if config[:navigation]
|
15
|
-
|
21
|
+
|
16
22
|
ask
|
17
23
|
read_and_validate
|
18
24
|
after_valid
|
@@ -61,5 +67,9 @@ module RailsNewApp
|
|
61
67
|
def self.default
|
62
68
|
""
|
63
69
|
end
|
70
|
+
|
71
|
+
def next_step
|
72
|
+
nil
|
73
|
+
end
|
64
74
|
end
|
65
|
-
end
|
75
|
+
end
|
@@ -5,7 +5,7 @@ module RailsNewApp
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def options
|
8
|
-
["None
|
8
|
+
["None", "Slim", "HAML"]
|
9
9
|
end
|
10
10
|
|
11
11
|
def lowercase_keys
|
@@ -19,8 +19,8 @@ module RailsNewApp
|
|
19
19
|
def self.default
|
20
20
|
{
|
21
21
|
option_number: 0,
|
22
|
-
name: "None
|
23
|
-
key: ""
|
22
|
+
name: "None",
|
23
|
+
key: ""
|
24
24
|
}
|
25
25
|
end
|
26
26
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module RailsNewApp
|
2
|
+
class TestFactoryStep < 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 test factories tool to use:"
|
11
|
+
end
|
12
|
+
|
13
|
+
def options
|
14
|
+
# TODO: add Forgery and Fabrication?
|
15
|
+
["None", "FactoryBot"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def lowercase_keys
|
19
|
+
["", "factory_bot"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def after_valid
|
23
|
+
puts "Selected test factories tool is: #{option}\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.default
|
27
|
+
{
|
28
|
+
option_number: 0,
|
29
|
+
name: "None (Default)",
|
30
|
+
key: ""
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def next_step
|
35
|
+
:test_fake_data
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module RailsNewApp
|
2
|
+
class TestFakeDataStep < 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 test fake data tool to use:"
|
11
|
+
end
|
12
|
+
|
13
|
+
def options
|
14
|
+
# TODO: add ffaker and Fake Person?
|
15
|
+
["None", "Faker"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def lowercase_keys
|
19
|
+
["", "faker"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def after_valid
|
23
|
+
puts "Selected test fake data tool is: #{option}\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.default
|
27
|
+
{
|
28
|
+
option_number: 0,
|
29
|
+
name: "None (Default)",
|
30
|
+
key: ""
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module RailsNewApp
|
2
2
|
class TestRunnerStep < ChoiceStep
|
3
3
|
def options
|
4
|
-
["None", "Minitest
|
4
|
+
["None", "Minitest", "RSpec"]
|
5
5
|
end
|
6
6
|
|
7
7
|
def lowercase_keys
|
@@ -19,10 +19,14 @@ module RailsNewApp
|
|
19
19
|
def self.default
|
20
20
|
{
|
21
21
|
option_number: 1,
|
22
|
-
name: "Minitest
|
22
|
+
name: "Minitest",
|
23
23
|
key: "minitest",
|
24
24
|
in_rails_new: true
|
25
25
|
}
|
26
26
|
end
|
27
|
+
|
28
|
+
def next_step
|
29
|
+
option == "None" ? nil : :code_coverage
|
30
|
+
end
|
27
31
|
end
|
28
32
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
run "mkdir test/support/factories"
|
@@ -0,0 +1 @@
|
|
1
|
+
run "mkdir spec/support/factories"
|
@@ -0,0 +1 @@
|
|
1
|
+
gem "kaminari"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
initializer "pagy.rb", "Check initializer options at: https://github.com/ddnexus/pagy/blob/master/lib/config/pagy.rb"
|
2
|
+
|
3
|
+
inject_into_file "app/helpers/application_helper.rb", after: "module ApplicationHelper\n" do
|
4
|
+
<<~'RUBY'
|
5
|
+
include Pagy::Frontend
|
6
|
+
RUBY
|
7
|
+
end
|
8
|
+
|
9
|
+
inject_into_file "app/controllers/application_controller.rb", after: "class ApplicationController < ActionController::Base\n" do
|
10
|
+
<<~'RUBY'
|
11
|
+
include Pagy::Backend
|
12
|
+
RUBY
|
13
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
gem "pagy"
|
@@ -1,7 +1,6 @@
|
|
1
1
|
generate "rspec:install"
|
2
2
|
|
3
3
|
# Create the spec folders for RSpec
|
4
|
-
run "mkdir spec"
|
5
4
|
run "mkdir spec/models"
|
6
5
|
run "mkdir spec/controllers"
|
7
6
|
run "mkdir spec/system"
|
@@ -13,11 +12,12 @@ run "mkdir spec/mailers"
|
|
13
12
|
run "mkdir spec/factories"
|
14
13
|
|
15
14
|
# Add `rails spec` task to run tests
|
16
|
-
inject_into_file "Rakefile", before: "Rails.application.load_tasks\n" do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
inject_into_file "Rakefile", before: "Rails.application.load_tasks\n" do
|
16
|
+
<<~'RUBY'
|
17
|
+
begin
|
18
|
+
require "rspec/core/rake_task"
|
19
|
+
RSpec::Core::RakeTask.new(:spec)
|
20
|
+
rescue LoadError
|
21
|
+
end
|
22
|
+
RUBY
|
21
23
|
end
|
22
|
-
RUBY
|
23
|
-
end
|
@@ -1,5 +1,6 @@
|
|
1
|
-
inject_into_file "spec/spec_helper.rb", before: "RSpec.configure do |config|\n" do
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
inject_into_file "spec/spec_helper.rb", before: "RSpec.configure do |config|\n" do
|
2
|
+
<<~'RUBY'
|
3
|
+
require "simplecov"
|
4
|
+
SimpleCov.start
|
5
|
+
RUBY
|
5
6
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
gem "will_paginate", "~> 3.1.0"
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module RailsNewApp
|
2
|
-
VERSION = Gem::Version.new("0.0.
|
3
|
-
end
|
2
|
+
VERSION = Gem::Version.new("0.0.3")
|
3
|
+
end
|
data/rails-new-app.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = RailsNewApp::VERSION
|
8
8
|
s.authors = ["Ariel Juodziukynas"]
|
9
9
|
s.email = ["arieljuod@gmail.com"]
|
10
|
-
s.license =
|
10
|
+
s.license = "MIT"
|
11
11
|
|
12
12
|
s.summary = "Command-line tool to assist the creation of new Rails apps"
|
13
13
|
s.homepage = "https://github.com/arielj/rails-new-app"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-new-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ariel Juodziukynas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -26,9 +26,12 @@ files:
|
|
26
26
|
- lib/rails-new-app/processors.rb
|
27
27
|
- lib/rails-new-app/processors/code_coverage_processor.rb
|
28
28
|
- lib/rails-new-app/processors/form_builder_processor.rb
|
29
|
+
- lib/rails-new-app/processors/pagination_processor.rb
|
29
30
|
- lib/rails-new-app/processors/processor.rb
|
30
31
|
- lib/rails-new-app/processors/ruby_linter_processor.rb
|
31
32
|
- lib/rails-new-app/processors/template_engine_processor.rb
|
33
|
+
- lib/rails-new-app/processors/test_factory_processor.rb
|
34
|
+
- lib/rails-new-app/processors/test_fake_data_processor.rb
|
32
35
|
- lib/rails-new-app/processors/test_runner_processor.rb
|
33
36
|
- lib/rails-new-app/runner.rb
|
34
37
|
- lib/rails-new-app/steps.rb
|
@@ -38,18 +41,30 @@ files:
|
|
38
41
|
- lib/rails-new-app/steps/database_step.rb
|
39
42
|
- lib/rails-new-app/steps/form_builder_step.rb
|
40
43
|
- lib/rails-new-app/steps/java_script_framework_step.rb
|
44
|
+
- lib/rails-new-app/steps/pagination_step.rb
|
41
45
|
- lib/rails-new-app/steps/rails_version_step.rb
|
42
46
|
- lib/rails-new-app/steps/ruby_linter_step.rb
|
43
47
|
- lib/rails-new-app/steps/step.rb
|
44
48
|
- lib/rails-new-app/steps/template_engine_step.rb
|
49
|
+
- lib/rails-new-app/steps/test_factory_step.rb
|
50
|
+
- lib/rails-new-app/steps/test_fake_data.rb
|
45
51
|
- lib/rails-new-app/steps/test_runner_step.rb
|
46
52
|
- lib/rails-new-app/steps/yes_no_choice_step.rb
|
53
|
+
- lib/rails-new-app/string_underscore.rb
|
54
|
+
- lib/rails-new-app/templates/factory_bot-gemfile.rb
|
55
|
+
- lib/rails-new-app/templates/factory_bot-minitest-config.rb
|
56
|
+
- lib/rails-new-app/templates/factory_bot-rspec-config.rb
|
57
|
+
- lib/rails-new-app/templates/faker-gemfile.rb
|
47
58
|
- lib/rails-new-app/templates/formtastic-config.rb
|
48
59
|
- lib/rails-new-app/templates/formtastic-gemfile.rb
|
49
60
|
- lib/rails-new-app/templates/haml-gemfile.rb
|
61
|
+
- lib/rails-new-app/templates/kaminari-gemfile.rb
|
62
|
+
- lib/rails-new-app/templates/pagy-config.rb
|
63
|
+
- lib/rails-new-app/templates/pagy-gemfile.rb
|
50
64
|
- lib/rails-new-app/templates/rspec-rails-config.rb
|
51
65
|
- lib/rails-new-app/templates/rspec-rails-gemfile.rb
|
52
66
|
- lib/rails-new-app/templates/rubocop-config.rb
|
67
|
+
- lib/rails-new-app/templates/rubocop-gemfile.rb
|
53
68
|
- lib/rails-new-app/templates/rubocop-minitest-gemfile.rb
|
54
69
|
- lib/rails-new-app/templates/rubocop-rspec-gemfile.rb
|
55
70
|
- lib/rails-new-app/templates/simple_form-config.rb
|
@@ -59,8 +74,8 @@ files:
|
|
59
74
|
- lib/rails-new-app/templates/simplecov-rspec-config.rb
|
60
75
|
- lib/rails-new-app/templates/slim-gemfile.rb
|
61
76
|
- lib/rails-new-app/templates/standardrb-config.rb
|
62
|
-
- lib/rails-new-app/templates/standardrb-
|
63
|
-
- lib/rails-new-app/templates/
|
77
|
+
- lib/rails-new-app/templates/standardrb-gemfile.rb
|
78
|
+
- lib/rails-new-app/templates/will_paginate-gemfile.rb
|
64
79
|
- lib/rails-new-app/version.rb
|
65
80
|
- rails-new-app.gemspec
|
66
81
|
homepage: https://github.com/arielj/rails-new-app
|