-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrails_new
executable file
·281 lines (259 loc) · 6.06 KB
/
rails_new
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/usr/bin/env ruby
require 'optparse'
def create_rails_app(version, flag = nil)
run "gem install rails -v #{version} --no-document"
run rails_new(version, flag)
run 'echo config/credentials.yml.enc >> .gitignore'
run 'git add .'
run "git -c commit.gpgsign=false commit -m '`#{rails_new(version, flag)}`'"
run "git tag --no-sign #{branch(version, flag)}"
run 'git reset HEAD^'
ensure
# 2回実行しないと config/, log/, node_modules/, tmp/ が削除されないため
run 'git clean -fd'
run 'git clean -fd'
end
def rails_new(version, flag)
return "rails _#{version}_ new . --#{flag}" if flag
"rails _#{version}_ new ."
end
def run(command)
lcyan = "\e[1;36m"
nocolor = "\e[0m"
puts "#{lcyan}> #{command}#{nocolor}"
# -- for debugging
# print 'press any key to continue...'
# $stdin.getc
ret = system(command)
raise "command failed: #{command}" unless ret
end
def filtered_versions_flags(target)
versions_flags = {
'6.1.7.8' => %w[
skip-action-mailer
skip-action-mailbox
skip-action-text
skip-active-record
skip-active-job
skip-active-storage
skip-puma
skip-action-cable
skip-sprockets
skip-spring
skip-listen
skip-javascript
skip-turbolinks
skip-jbuilder
skip-test
skip-system-test
skip-bootsnap
api
minimal
webpacker
],
'7.0.8.4' => %w[
skip-action-cable
skip-action-mailbox
skip-action-mailer
skip-action-text
skip-active-job
skip-active-record
skip-active-storage
skip-asset-pipeline
skip-bootsnap
skip-hotwire
skip-javascript
skip-jbuilder
skip-system-test
skip-test
asset-pipeline=propshaft
asset-pipeline=sprockets
css=bootstrap
css=bulma
css=postcss
css=sass
css=tailwind
javascript=esbuild
javascript=importmap
javascript=rollup
javascript=webpack
api
minimal
],
'7.1.4' => %w[
skip-action-cable
skip-action-mailbox
skip-action-mailer
skip-action-text
skip-active-job
skip-active-record
skip-active-storage
skip-asset-pipeline
skip-bootsnap
skip-dev-gems
skip-hotwire
skip-javascript
skip-jbuilder
skip-system-test
skip-test
skip-docker
skip-git
asset-pipeline=propshaft
asset-pipeline=sprockets
css=bootstrap
css=bulma
css=postcss
css=sass
css=tailwind
javascript=bun
javascript=esbuild
javascript=importmap
javascript=rollup
javascript=webpack
api
minimal
],
'7.2.1' => %w[
skip-action-cable
skip-action-mailbox
skip-action-mailer
skip-action-text
skip-active-job
skip-active-record
skip-active-storage
skip-asset-pipeline
skip-bootsnap
skip-dev-gems
skip-hotwire
skip-javascript
skip-jbuilder
skip-system-test
skip-test
skip-docker
skip-git
skip-rubocop
skip-brakeman
skip-ci
skip-devcontainer
devcontainer
asset-pipeline=propshaft
asset-pipeline=sprockets
css=bootstrap
css=bulma
css=postcss
css=sass
css=tailwind
javascript=bun
javascript=esbuild
javascript=importmap
javascript=rollup
javascript=webpack
api
minimal
],
'8.0.0.beta1' => %w[
skip-action-cable
skip-action-mailbox
skip-action-mailer
skip-action-text
skip-active-job
skip-active-record
skip-active-storage
skip-asset-pipeline
skip-bootsnap
skip-dev-gems
skip-hotwire
skip-javascript
skip-jbuilder
skip-system-test
skip-test
skip-docker
skip-git
skip-rubocop
skip-brakeman
skip-ci
skip-devcontainer
skip-thruster
skip-kamal
skip-solid
devcontainer
asset-pipeline=propshaft
asset-pipeline=sprockets
css=bootstrap
css=bulma
css=postcss
css=sass
css=tailwind
javascript=bun
javascript=esbuild
javascript=importmap
javascript=rollup
javascript=webpack
api
minimal
]
}
return versions_flags if target == 'all'
versions_flags.select { |k, _| k.start_with?(target) }
end
def branch(version, flag = nil)
return [ version, flag.gsub('=', '-') ].compact.join('-') if flag
version
end
target = 'all'
opt = OptionParser.new
opt.on('-t', '--target [TARGET]') do |t|
target = t
end
opt.parse!(ARGV)
sub_command = ARGV.shift
case sub_command
when 'create'
filtered_versions_flags(target).each do |v, flags|
create_rails_app(v)
flags.each do |f|
create_rails_app(v, f)
end
end
when 'destroy'
filtered_versions_flags(target).each do |v, flags|
system "git tag -d #{branch(v)}"
flags.each do |f|
system "git tag -d #{branch(v, f)}"
end
end
when 'readme'
repository = 'snaka/rails_new_flags'
summary = {}
filtered_versions_flags('all').each do |v, flags|
flags.each do |f|
summary[f] ||= {}
summary[f][v] = true
end
end
versions = filtered_versions_flags('all').keys.sort
flags = filtered_versions_flags('all').values.flatten.uniq.sort
puts '| flag |' << versions.map { |v| " [🔎 #{v}](https://github.com/#{repository}/tree/#{branch(v)}) " }.join('|') << '|'
puts '| --- |' << versions.count.times.map { ' --- ' }.join('|') << '|'
browse_icon_link = lambda do |flag, ver|
if summary.dig(flag, ver)
"[🔎](https://github.com/#{repository}/tree/#{branch(ver)})"
else
''
end
end
diff_icon_link = lambda do |flag, ver|
if summary.dig(flag, ver)
" [↔️](https://github.com/#{repository}/compare/#{branch(ver)}..#{branch(ver, flag)}) "
else
' - '
end
end
flags.each do |f|
puts "| --#{f} |" << versions.map { |v|
diff_icon_link.call(f, v) + " #{browse_icon_link.call(f, v)}"
}.join('|') << '|'
end
else
puts "Usage: #{$0} [create|destroy|readme]"
end