rails_steroids 0.6.0 → 0.7.1
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/CHANGELOG.md +19 -1
- data/bin/rails_steroids +5 -4
- data/lib/generators/steroid/controller/controller_generator.rb +6 -6
- data/lib/generators/steroid/migration/USAGE +4 -0
- data/lib/generators/steroid/migration/migration_generator.rb +142 -69
- data/lib/generators/steroid/model/model_generator.rb +6 -6
- data/lib/generators/steroid/new_project/new_project_generator.rb +16 -16
- data/lib/generators/steroid/steroid_generator.rb +1 -1
- data/lib/rails_steroids/cli.rb +6 -5
- data/lib/rails_steroids/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df4e95abc0bcd978678c7fca5b7a63daaf98f652b4e117295453cc3314df8baf
|
4
|
+
data.tar.gz: '038b916212e3c2c092825e96ebd0e8bcbf50508330542f35182008bcfd5b6807'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 678f0a8b483a2f389652f1907e9b0ec3d87a7ffb5c110b26a3332f4a8c9905ec4b9f3f74b5e928c7cf97521ec750bad6568960c30792943f2ec13ebddfe7119b
|
7
|
+
data.tar.gz: 995c17f522d05f5fef7ba4957d52d23377a4ca249310d029bd73005a52e7e00cb793378318a76c42bf629f1a7ee0152bed5d96a92fdb4d6fc0c96db03e964143
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,26 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.7.1] - 2024-02-09
|
4
|
+
|
5
|
+
- Improvement: Formatting to terminal output for all steroids
|
6
|
+
- Improvement: Formatting of `rails_steroids list` output in table format
|
7
|
+
- Fix: RailsSteroids Banner display on terminal
|
8
|
+
|
9
|
+
## [0.7.0] - 2024-02-08
|
10
|
+
|
11
|
+
- Improvement in steroid recipe: migration
|
12
|
+
- Create new migration interactively for modify table with
|
13
|
+
* add_column, remove_column
|
14
|
+
* add_index, remove_index
|
15
|
+
* add_remove, remove_reference
|
16
|
+
|
3
17
|
## [0.6.0] - 2024-02-07
|
4
18
|
|
5
|
-
- New steroid recipe: migration
|
19
|
+
- New steroid recipe: migration
|
20
|
+
- Create new migration interactively for
|
21
|
+
* Create table
|
22
|
+
* Create join table
|
23
|
+
* Drop table
|
6
24
|
|
7
25
|
## [0.5.0] - 2024-02-06
|
8
26
|
|
data/bin/rails_steroids
CHANGED
@@ -2,10 +2,11 @@
|
|
2
2
|
|
3
3
|
banner = <<-BANNER
|
4
4
|
____ _ __ _____ __ _ __
|
5
|
-
/ __
|
6
|
-
/ /_/ / __ `/ / / ___/
|
5
|
+
/ __ \\____ _(_) /____ / ___// /____ _________ (_)___/ /____
|
6
|
+
/ /_/ / __ `/ / / ___/ \\__ \\/ __/ _ \\/ ___/ __ \\/ / __ / ___/
|
7
7
|
/ _, _/ /_/ / / (__ ) ___/ / /_/ __/ / / /_/ / / /_/ (__ )
|
8
|
-
/_/ |_
|
8
|
+
/_/ |_|\\__,_/_/_/____/ /____/\\__/\\___/_/ \\____/_/\\__,_/____/
|
9
|
+
|
9
10
|
BANNER
|
10
11
|
|
11
12
|
puts banner
|
@@ -16,4 +17,4 @@ end
|
|
16
17
|
|
17
18
|
require "rails_steroids/cli"
|
18
19
|
|
19
|
-
RailsSteroids::CLI.start(ARGV)
|
20
|
+
RailsSteroids::CLI.start(ARGV)
|
@@ -8,22 +8,22 @@ module Steroid
|
|
8
8
|
source_root File.expand_path("templates", __dir__)
|
9
9
|
|
10
10
|
def add_controller
|
11
|
-
say "
|
11
|
+
say "Applying steroid: Controller", [:bold, :magenta]
|
12
12
|
cmd = ["rails generate controller"]
|
13
13
|
prompt = TTY::Prompt.new
|
14
|
-
controller_name = prompt.ask("
|
14
|
+
controller_name = prompt.ask("\nWhat is the great name of your controller?") do |q|
|
15
15
|
q.required true
|
16
16
|
q.modify :remove
|
17
17
|
end
|
18
18
|
cmd << controller_name
|
19
19
|
|
20
|
-
actions = prompt.multi_select("
|
20
|
+
actions = prompt.multi_select("\nChoose actions:", %w(index show new edit create update destroy))
|
21
21
|
cmd += actions
|
22
22
|
|
23
23
|
boolean_choices = [{name: "yes", value: true}, {name: "no", value: false}]
|
24
24
|
|
25
25
|
custom_actions = []
|
26
|
-
while prompt.select("
|
26
|
+
while prompt.select("\nWould you like to add more actions?", boolean_choices)
|
27
27
|
custom_actions << prompt.ask("Specify name of action:") do |q|
|
28
28
|
q.required true
|
29
29
|
q.modify :remove
|
@@ -31,8 +31,8 @@ module Steroid
|
|
31
31
|
end
|
32
32
|
cmd += custom_actions
|
33
33
|
|
34
|
-
cmd << "--skip-routes" if prompt.select("
|
35
|
-
cmd << "--no-helper" if prompt.select("
|
34
|
+
cmd << "--skip-routes" if prompt.select("\nSkip routes?", boolean_choices)
|
35
|
+
cmd << "--no-helper" if prompt.select("\nSkip helper?", boolean_choices)
|
36
36
|
|
37
37
|
run cmd.join(" ")
|
38
38
|
end
|
@@ -19,3 +19,7 @@ What will this do?:
|
|
19
19
|
- index and unique index
|
20
20
|
- id column, custom join table name for join table creation
|
21
21
|
- Addition to original migration generator is we can set default value as well
|
22
|
+
* Modify table with
|
23
|
+
- add_column, remove_column
|
24
|
+
- add_index, remove_index
|
25
|
+
- add_remove, remove_reference
|
@@ -13,86 +13,112 @@ module Steroid
|
|
13
13
|
include ActiveRecord::Migration::JoinTable
|
14
14
|
|
15
15
|
def add_migration
|
16
|
-
say "
|
17
|
-
cmd = ["rails generate migration"]
|
18
|
-
prompt = TTY::Prompt.new
|
19
|
-
boolean_choices = [{name: "yes", value: true}, {name: "no", value: false}]
|
16
|
+
say "Applying steroid: Migration", [:bold, :magenta]
|
20
17
|
|
21
18
|
action_choices = [
|
22
19
|
{name: 'Create table', value: 'create_table'},
|
23
20
|
{name: 'Create join table', value: 'create_join_table'},
|
24
21
|
{name: 'Drop table', value: 'drop_table'},
|
25
|
-
|
26
|
-
# {name: 'Add column', value: 'add_column'},
|
27
|
-
# {name: 'Remove column', value: 'remove_column'},
|
28
|
-
# {name: 'Add index', value: 'add_index'},
|
29
|
-
# {name: 'Remove index', value: 'remove_index'},
|
22
|
+
{name: 'Modify table columns/index', value: 'modify_table'},
|
30
23
|
]
|
31
|
-
action = prompt.select("
|
24
|
+
@action = prompt.select("\nWhat would you like to do?", action_choices)
|
32
25
|
|
33
|
-
case action
|
26
|
+
case @action
|
34
27
|
when 'create_table'
|
35
|
-
table_name = prompt.ask("
|
36
|
-
@content = content_for_create_table(table_name, collect_columns_data
|
28
|
+
table_name = prompt.ask("\nWhat is the name of table to be created?", required: true) { |q| q.modify :remove }
|
29
|
+
@content = content_for_create_table(table_name, collect_columns_data)
|
37
30
|
migration_template "migration.rb", "#{db_migrate_path}/create_#{table_name}.rb"
|
38
31
|
when 'create_join_table'
|
39
|
-
table1_name = prompt.ask("
|
40
|
-
table2_name = prompt.ask("
|
41
|
-
table_name = prompt.ask("
|
32
|
+
table1_name = prompt.ask("\nWhat is the name of first table to be joined?", required: true) { |q| q.modify :remove }
|
33
|
+
table2_name = prompt.ask("\nWhat is the name of second table to be joined?", required: true) { |q| q.modify :remove }
|
34
|
+
table_name = prompt.ask("\nWhat is the custom name for join table?", default: find_join_table_name(table1_name, table2_name), required: true) { |q| q.modify :remove }
|
42
35
|
columns_data = []
|
43
|
-
if prompt.select("
|
36
|
+
if prompt.select("\nAdd `id` column?", boolean_choices)
|
44
37
|
columns_data << {name: 'id', type: 'primary_key'}
|
45
38
|
end
|
46
|
-
if prompt.select("
|
39
|
+
if prompt.select("\nAdd index for #{table1_name} foreign_key?", boolean_choices)
|
47
40
|
columns_data << {name: "#{table1_name.singularize}_id", type: 'index'}
|
48
41
|
end
|
49
|
-
if prompt.select("
|
42
|
+
if prompt.select("\nAdd index for #{table2_name} foreign_key?", boolean_choices)
|
50
43
|
columns_data << {name: "#{table2_name.singularize}_id", type: 'index'}
|
51
44
|
end
|
52
|
-
if prompt.select("
|
45
|
+
if prompt.select("\nAdd composite index for #{table1_name} and #{table2_name} foreign_key?", boolean_choices)
|
53
46
|
uniq_index_option = prompt.select("Unique combination index?", boolean_choices) ? {meta: {unique: true}} : {}
|
54
|
-
columns_data << {name: "
|
47
|
+
columns_data << {name: ["#{table2_name.singularize}_id", "#{table2_name.singularize}_id"], type: 'index'}.merge(uniq_index_option)
|
55
48
|
end
|
56
|
-
@content = content_for_create_join_table(table1_name, table2_name, table_name, (columns_data + collect_columns_data)
|
49
|
+
@content = content_for_create_join_table(table1_name, table2_name, table_name, (columns_data + collect_columns_data))
|
57
50
|
migration_template "migration.rb", "#{db_migrate_path}/create_join_table_#{table_name}.rb"
|
58
51
|
when 'drop_table'
|
59
|
-
table_name = prompt.ask("
|
52
|
+
table_name = prompt.ask("\nWhat is the name of table to be dropped?", required: true) { |q| q.modify :remove }
|
60
53
|
@content = content_for_drop_table(table_name)
|
61
54
|
migration_template "migration.rb", "#{db_migrate_path}/drop_#{table_name}.rb"
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
55
|
+
when 'modify_table'
|
56
|
+
table_name = prompt.ask("\nWhat is the name of table to add/remove columns/index?", required: true) { |q| q.modify :remove }
|
57
|
+
modify_table_choices = [
|
58
|
+
{name: 'Add column', value: 'add_column'}, {name: 'Remove column', value: 'remove_column'},
|
59
|
+
{name: 'Add index', value: 'add_index'}, {name: 'Remove index', value: 'remove_index'},
|
60
|
+
{name: 'Add reference', value: 'add_reference'}, {name: 'Remove reference', value: 'remove_reference'},
|
61
|
+
# {name: 'Add timestamps', value: 'add_timestamps'}, {name: 'Remove timestamps', value: 'remove_timestamps'},
|
62
|
+
{name: 'Exit', value: 'exit'}
|
63
|
+
]
|
64
|
+
@content = []
|
65
|
+
file_name = []
|
66
|
+
while (modify_table_action = prompt.select("\nWhat would you like to do?", modify_table_choices)) != 'exit'
|
67
|
+
for_removal = modify_table_action.start_with?('remove_')
|
68
|
+
if modify_table_action.end_with?('_index') || modify_table_action.end_with?('_reference')
|
69
|
+
data = modify_table_action.end_with?('_index') ? ask_index_data(for_removal: for_removal) : ask_reference_data(for_removal: for_removal)
|
70
|
+
file_name << modify_table_action << data[:name]
|
71
|
+
else
|
72
|
+
data = ask_column_data(for_removal: for_removal)
|
73
|
+
file_name << (for_removal ? 'remove' : 'add') << data[:name]
|
74
|
+
end
|
75
|
+
@content << format_statement_for_modify_table(modify_table_action, table_name, data)
|
76
|
+
end
|
77
|
+
@content = content_for_modify_table(@content.join("\n "))
|
78
|
+
migration_template "migration.rb", "#{db_migrate_path}/#{file_name.join('_')}_in_#{table_name}.rb"
|
71
79
|
end
|
72
80
|
end
|
73
81
|
|
74
82
|
private
|
75
83
|
|
84
|
+
def prompt
|
85
|
+
TTY::Prompt.new
|
86
|
+
end
|
87
|
+
|
88
|
+
def boolean_choices
|
89
|
+
[{name: "yes", value: true}, {name: "no", value: false}]
|
90
|
+
end
|
91
|
+
|
76
92
|
def collect_columns_data
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
93
|
+
columns_data = []
|
94
|
+
while prompt.select("\nWould you like to add model attributes(columns)?", boolean_choices)
|
95
|
+
columns_data << ask_column_data
|
96
|
+
end
|
97
|
+
timestamps_data = ask_timestamps_data
|
98
|
+
columns_data << timestamps_data if timestamps_data
|
99
|
+
columns_data
|
100
|
+
end
|
83
101
|
|
84
|
-
|
102
|
+
def ask_column_data(for_removal: false)
|
103
|
+
column_data = { meta: {} }
|
104
|
+
column_name = prompt.ask("Specify name of column:", required: true) { |q| q.modify :remove }
|
85
105
|
|
86
|
-
|
87
|
-
|
88
|
-
|
106
|
+
column_type_choices = %w(boolean string text integer decimal float binary date time datetime primary_key digest token)
|
107
|
+
column_type_choices << 'references' unless @action == 'modify_table'
|
108
|
+
column_type = prompt.select("Choose type of column:", column_type_choices)
|
109
|
+
|
110
|
+
if column_type == 'references'
|
111
|
+
column_data[:meta][:foreign_key] = true if prompt.select("Foreign_key to be #{for_removal ? 'removed' : 'added'}?", boolean_choices)
|
112
|
+
column_data[:meta][:polymorphic] = true if prompt.select("Polymorphic association?", boolean_choices)
|
113
|
+
end
|
114
|
+
unless for_removal
|
89
115
|
if %w(integer string text binary).include?(column_type)
|
90
116
|
if prompt.select("Set limit?", boolean_choices)
|
91
117
|
limit = prompt.ask("Specify limit:", required: true) do |q|
|
92
118
|
q.modify :remove
|
93
119
|
q.convert(:int, "Invalid input! Please provide integer value.")
|
94
120
|
end
|
95
|
-
|
121
|
+
column_data[:meta][:limit] = limit
|
96
122
|
end
|
97
123
|
end
|
98
124
|
if column_type == 'decimal'
|
@@ -101,66 +127,105 @@ module Steroid
|
|
101
127
|
q.modify :remove
|
102
128
|
q.convert(:int, "Invalid input! Please provide integer value.")
|
103
129
|
end
|
104
|
-
|
130
|
+
column_data[:meta][:precision] = precision
|
105
131
|
scale = prompt.ask("Specify scale:", required: true) do |q|
|
106
132
|
q.modify :remove
|
107
133
|
q.convert(:int, "Invalid input! Please provide integer value.")
|
108
134
|
end
|
109
|
-
|
135
|
+
column_data[:meta][:scale] = scale
|
110
136
|
end
|
111
137
|
end
|
112
138
|
|
113
139
|
if %w(references primary_key digest token).exclude?(column_type) && prompt.select("Add default value?", boolean_choices)
|
114
140
|
acceptable_value_type = { 'text' => :string }[column_type] || column_type.to_sym
|
115
|
-
|
141
|
+
column_data[:meta][:default] = prompt.ask("Specify default value:", required: true) do |q|
|
116
142
|
q.modify :remove
|
117
143
|
q.convert(acceptable_value_type, "Invalid input! Please provide %{type} value.")
|
118
144
|
end
|
119
145
|
end
|
120
146
|
|
121
147
|
if prompt.select("Add index?", boolean_choices)
|
122
|
-
|
148
|
+
column_data[:meta][:index] = prompt.select("Unique index?", boolean_choices) ? :unique : true
|
123
149
|
end
|
150
|
+
end
|
151
|
+
column_data.merge!(name: column_name, type: column_type)
|
152
|
+
column_data
|
153
|
+
end
|
154
|
+
|
155
|
+
def ask_reference_data(for_removal: false)
|
156
|
+
column_data = { meta: {} }
|
157
|
+
column_data[:name] = prompt.ask("Specify name of reference:", required: true) { |q| q.modify :remove }
|
158
|
+
column_data[:meta][:foreign_key] = true if prompt.select("Foreign_key to be #{for_removal ? 'removed' : 'added'}?", boolean_choices)
|
159
|
+
column_data[:meta][:polymorphic] = true if prompt.select("Polymorphic association?", boolean_choices)
|
160
|
+
column_data
|
161
|
+
end
|
162
|
+
|
163
|
+
def ask_index_data(for_removal: false)
|
164
|
+
column_data = { meta: {} }
|
165
|
+
names = []
|
166
|
+
names << prompt.ask("Specify name of column:", required: true) { |q| q.modify :remove }
|
167
|
+
while prompt.select("Add more columns for Composite index?", boolean_choices)
|
168
|
+
names << prompt.ask("Specify name of another column:", required: true) { |q| q.modify :remove }
|
169
|
+
end
|
170
|
+
column_data[:name] = names
|
171
|
+
unless for_removal
|
172
|
+
column_data[:meta][:unique] = true if prompt.select("Unique index?", boolean_choices)
|
173
|
+
end
|
174
|
+
custom_name = prompt.ask("Specify custom name for index (optional):") { |q| q.modify :remove }
|
175
|
+
column_data[:meta][:name] = custom_name if custom_name.present?
|
176
|
+
column_data
|
177
|
+
end
|
124
178
|
|
125
|
-
|
126
|
-
|
179
|
+
def ask_timestamps_data
|
180
|
+
if prompt.select("\nAdd timestamps?", boolean_choices)
|
181
|
+
{ type: 'timestamps' }
|
127
182
|
end
|
128
|
-
columns
|
129
183
|
end
|
130
184
|
|
131
|
-
def
|
132
|
-
|
133
|
-
|
134
|
-
|
185
|
+
def format_statement_for_modify_table(modify_table_action, table_name, column_data)
|
186
|
+
statement_data = ["#{modify_table_action} :#{table_name}"]
|
187
|
+
statement_data << if column_data[:name].is_a?(Array)
|
188
|
+
col_name = column_data[:name].size > 1 ? "[#{column_data[:name].map { |n| ":#{n}" }.join(', ')}]" : ":#{column_data[:name].first}"
|
189
|
+
"column: #{col_name}" if modify_table_action == 'remove_index'
|
190
|
+
else
|
191
|
+
":#{column_data[:name]}"
|
192
|
+
end
|
193
|
+
statement_data << ":#{column_data[:type]}" if column_data[:type]
|
194
|
+
column_data[:meta].each { |key, value| statement_data << "#{key}: #{value.inspect}" }
|
195
|
+
statement_data = statement_data.join(', ')
|
135
196
|
end
|
136
197
|
|
137
|
-
def
|
138
|
-
|
139
|
-
column_row =
|
140
|
-
|
198
|
+
def format_statement_for_create_table(columns_data)
|
199
|
+
columns_data.map do |c|
|
200
|
+
column_row = if c[:name].is_a?(Array)
|
201
|
+
["t.#{c[:type]} [#{c[:name].map { |n| ":#{n}" }.join(', ')}]"]
|
202
|
+
elsif c[:name].nil?
|
203
|
+
["t.#{c[:type]}"]
|
204
|
+
else
|
205
|
+
["t.#{c[:type]} :#{c[:name]}"]
|
206
|
+
end
|
207
|
+
c[:meta].each { |key, value| column_row << "#{key}: #{value.inspect}" } if c[:meta]
|
141
208
|
column_row.join(', ')
|
142
|
-
end
|
143
|
-
|
209
|
+
end.join("\n ")
|
210
|
+
end
|
211
|
+
|
212
|
+
def content_for_create_table(table_name, columns_data)
|
213
|
+
columns_data_content = format_statement_for_create_table(columns_data)
|
144
214
|
<<-CONTENT
|
145
215
|
def change
|
146
216
|
create_table :#{table_name}#{primary_key_type} do |t|
|
147
|
-
#{columns_data_content
|
217
|
+
#{columns_data_content}
|
148
218
|
end
|
149
219
|
end
|
150
220
|
CONTENT
|
151
221
|
end
|
152
222
|
|
153
|
-
def content_for_create_join_table(table1_name, table2_name, table_name, columns_data
|
154
|
-
columns_data_content = columns_data
|
155
|
-
column_row = ["t.#{c[:type]} :#{c[:name]}"]
|
156
|
-
c[:meta]&.each { |key, value| column_row << "#{key}: #{value.inspect}" }
|
157
|
-
column_row.join(', ')
|
158
|
-
end
|
159
|
-
columns_data_content << "t.timestamps" if need_timestamps
|
223
|
+
def content_for_create_join_table(table1_name, table2_name, table_name, columns_data)
|
224
|
+
columns_data_content = format_statement_for_create_table(columns_data)
|
160
225
|
<<-CONTENT
|
161
226
|
def change
|
162
227
|
create_join_table :#{table1_name}, :#{table2_name}, table_name: :#{table_name} do |t|
|
163
|
-
#{columns_data_content
|
228
|
+
#{columns_data_content}
|
164
229
|
end
|
165
230
|
end
|
166
231
|
CONTENT
|
@@ -174,5 +239,13 @@ module Steroid
|
|
174
239
|
CONTENT
|
175
240
|
end
|
176
241
|
|
242
|
+
def content_for_modify_table(statements)
|
243
|
+
<<-CONTENT
|
244
|
+
def change
|
245
|
+
#{statements}
|
246
|
+
end
|
247
|
+
CONTENT
|
248
|
+
end
|
249
|
+
|
177
250
|
end
|
178
251
|
end
|
@@ -8,10 +8,10 @@ module Steroid
|
|
8
8
|
source_root File.expand_path("templates", __dir__)
|
9
9
|
|
10
10
|
def add_model
|
11
|
-
say "
|
11
|
+
say "Applying steroid: Model", [:bold, :magenta]
|
12
12
|
cmd = ["rails generate model"]
|
13
13
|
prompt = TTY::Prompt.new
|
14
|
-
model_name = prompt.ask("
|
14
|
+
model_name = prompt.ask("\nWhat is the great name of your model?") do |q|
|
15
15
|
q.required true
|
16
16
|
q.modify :remove
|
17
17
|
end
|
@@ -20,7 +20,7 @@ module Steroid
|
|
20
20
|
boolean_choices = [{name: "yes", value: true}, {name: "no", value: false}]
|
21
21
|
|
22
22
|
columns = []
|
23
|
-
while prompt.select("
|
23
|
+
while prompt.select("\nWould you like to add model attributes(columns)?", boolean_choices)
|
24
24
|
|
25
25
|
column_name = prompt.ask("Specify name of column:") do |q|
|
26
26
|
q.required true
|
@@ -67,9 +67,9 @@ module Steroid
|
|
67
67
|
end
|
68
68
|
cmd += columns
|
69
69
|
|
70
|
-
cmd << "--no-migration" if prompt.select("
|
71
|
-
cmd << "--no-timestamps" if prompt.select("
|
72
|
-
cmd << "--no-indexes" if prompt.select("
|
70
|
+
cmd << "--no-migration" if prompt.select("\nSkip migration?", boolean_choices)
|
71
|
+
cmd << "--no-timestamps" if prompt.select("\nSkip created_at, updated_at timestamps?", boolean_choices)
|
72
|
+
cmd << "--no-indexes" if prompt.select("\nSkip indexes?", boolean_choices)
|
73
73
|
|
74
74
|
run cmd.join(" ")
|
75
75
|
end
|
@@ -8,15 +8,15 @@ module Steroid
|
|
8
8
|
source_root File.expand_path("templates", __dir__)
|
9
9
|
|
10
10
|
def add_new_project
|
11
|
-
say "
|
11
|
+
say "Applying steroid: New Project", [:bold, :magenta]
|
12
12
|
prompt = TTY::Prompt.new
|
13
|
-
project_name = prompt.ask("
|
13
|
+
project_name = prompt.ask("\nWhat is the great name of your Rails project?") do |q|
|
14
14
|
q.required true
|
15
15
|
q.modify :remove
|
16
16
|
end
|
17
17
|
empty_directory project_name
|
18
18
|
|
19
|
-
ruby_version = prompt.ask("
|
19
|
+
ruby_version = prompt.ask("\nWhich Ruby version would you like to use?") do |q|
|
20
20
|
q.required true
|
21
21
|
q.modify :remove
|
22
22
|
end
|
@@ -26,33 +26,33 @@ module Steroid
|
|
26
26
|
|
27
27
|
cmd = ["rails"]
|
28
28
|
current_rails_version = `rails --version`.gsub('Rails ', '').strip
|
29
|
-
rails_version = prompt.ask("
|
29
|
+
rails_version = prompt.ask("\nWhich Rails version would you like to use? You can find Rails version from https://rubygems.org/gems/rails/versions.", default: current_rails_version)
|
30
30
|
cmd << "_#{rails_version}_"
|
31
31
|
cmd << "new"
|
32
32
|
cmd << project_name
|
33
33
|
|
34
34
|
database_options = %w(mysql trilogy postgresql sqlite3 oracle sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc)
|
35
|
-
database_name = prompt.select("
|
35
|
+
database_name = prompt.select("\nChoose your database:", database_options)
|
36
36
|
cmd << "--database #{database_name}"
|
37
37
|
|
38
|
-
asset_pipeline = prompt.select("
|
38
|
+
asset_pipeline = prompt.select("\nChoose your asset pipeline:", %w(sprockets propshaft))
|
39
39
|
cmd << "--asset-pipeline #{asset_pipeline}"
|
40
40
|
|
41
|
-
css = prompt.select("
|
41
|
+
css = prompt.select("\nChoose CSS processor:", %w(tailwind bootstrap bulma postcss sass))
|
42
42
|
cmd << "--css #{css}"
|
43
43
|
|
44
|
-
js = prompt.select("
|
44
|
+
js = prompt.select("\nChoose JavaScript approach:", %w(importmap bun webpack esbuild rollup))
|
45
45
|
cmd << "--javascript #{js}"
|
46
46
|
|
47
47
|
boolean_choices = [{name: "yes", value: true}, {name: "no", value: false}]
|
48
|
-
cmd << "--api" if prompt.select("
|
49
|
-
cmd << "--skip-jbuilder" if prompt.select("
|
50
|
-
cmd << "--skip-git" if prompt.select("
|
51
|
-
cmd << "--skip-docker" if prompt.select("
|
52
|
-
cmd << "--skip-action-cable" if prompt.select("
|
53
|
-
cmd << "--skip-hotwire" if prompt.select("
|
54
|
-
cmd << "--skip-test" if prompt.select("
|
55
|
-
cmd << "--skip-system-test" if prompt.select("
|
48
|
+
cmd << "--api" if prompt.select("\nAPI only application?", boolean_choices)
|
49
|
+
cmd << "--skip-jbuilder" if prompt.select("\nSkip jbuilder?", boolean_choices)
|
50
|
+
cmd << "--skip-git" if prompt.select("\nSkip git init, .gitignore and .gitattributes?", boolean_choices)
|
51
|
+
cmd << "--skip-docker" if prompt.select("\nSkip Dockerfile, .dockerignore and bin/docker-entrypoint?", boolean_choices)
|
52
|
+
cmd << "--skip-action-cable" if prompt.select("\nSkip Action Cable files?", boolean_choices)
|
53
|
+
cmd << "--skip-hotwire" if prompt.select("\nSkip Hotwire integration?", boolean_choices)
|
54
|
+
cmd << "--skip-test" if prompt.select("\nSkip test files?", boolean_choices)
|
55
|
+
cmd << "--skip-system-test" if prompt.select("\nSkip system test files?", boolean_choices)
|
56
56
|
cmd << "--no-rc" # To skip configurations from .railsrc
|
57
57
|
cmd << "--skip" # To skip overriding existing files
|
58
58
|
run cmd.join(" ")
|
@@ -13,7 +13,7 @@ class SteroidGenerator < Rails::Generators::NamedBase
|
|
13
13
|
source_root File.expand_path("templates", __dir__)
|
14
14
|
|
15
15
|
def add_#{name}
|
16
|
-
say "
|
16
|
+
say "Applying steroid: #{name.titlecase}", [:bold, :magenta]
|
17
17
|
# Add your other code here or any additional methods below this method
|
18
18
|
end
|
19
19
|
end
|
data/lib/rails_steroids/cli.rb
CHANGED
@@ -21,18 +21,19 @@ module RailsSteroids
|
|
21
21
|
|
22
22
|
desc "list", "Print list of steroids"
|
23
23
|
def list
|
24
|
-
|
25
|
-
puts "| Functionality | Command |"
|
26
|
-
puts "|---|---|"
|
24
|
+
say "RailsSteroids list", [:bold, :cyan]
|
27
25
|
steroid_names = [
|
28
26
|
'migration',
|
29
27
|
'model',
|
30
28
|
'controller',
|
31
29
|
'new_project',
|
32
30
|
]
|
31
|
+
arr = [['Functionality', 'Command']]
|
32
|
+
arr << ['===============', '================================================']
|
33
33
|
steroid_names.each do |steroid|
|
34
|
-
|
34
|
+
arr << [steroid.titlecase, "`rails_steroids inject steroid:#{steroid}`"]
|
35
35
|
end
|
36
|
+
print_table(arr, {borders: true})
|
36
37
|
# TODO: Glob all file and prepare a list of available generators
|
37
38
|
end
|
38
39
|
|
@@ -53,4 +54,4 @@ module RailsSteroids
|
|
53
54
|
"../generators/steroid/#{generator_name}/#{generator_name}_generator.rb"
|
54
55
|
end
|
55
56
|
end
|
56
|
-
end
|
57
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_steroids
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anand Bait
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|