-
Notifications
You must be signed in to change notification settings - Fork 0
/
rails_new
executable file
·169 lines (148 loc) · 3.58 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
#!/usr/bin/env ruby
require 'optparse'
def create_rails_app(version, flag = nil)
run rails_new(version, flag)
run 'git add .'
run "git commit -m '`#{rails_new(version, flag)}`'"
run "git tag #{branch(version, flag)}"
run 'git reset HEAD^'
ensure
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.0.4.4' => %w[
skip-action-mailer
skip-action-mailbox
skip-action-text
skip-active-record
skip-active-storage
skip-puma
skip-action-cable
skip-sprockets
skip-spring
skip-listen
skip-javascript
skip-turbolinks
skip-test
skip-system-test
skip-bootsnap
api
webpacker
],
'6.1.4.4' => %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.1' => %w[
skip-action-mailer
skip-action-mailbox
skip-action-text
skip-active-record
skip-active-job
skip-active-storage
skip-action-cable
skip-asset-pipeline
asset-pipeline=sprockets
asset-pipeline=propshaft
skip-javascript
skip-hotwire
skip-jbuilder
skip-test
skip-system-test
skip-bootsnap
api
minimal
javascript=importmap
javascript=webpack
javascript=esbuild
javascript=rollup
css=tailwind
css=bootstrap
css=bulma
css=postcss
css=sass
]
}
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] = "https://github.com/#{repository}/compare/#{branch(v)}..#{branch(v, f)}"
end
end
versions = filtered_versions_flags('all').keys.sort
flags = filtered_versions_flags('all').values.flatten.uniq.sort
puts '| flag |' << versions.map { |v| " #{v} " }.join('|') << '|'
puts '| --- |' << versions.count.times.map { ' --- ' }.join('|') << '|'
diff_url = ->(url) { url ? " [🔍](#{url}) " : ' - ' }
flags.each do |f|
puts "| --#{f} |" << versions.map { |v| diff_url.call(summary.dig(f, v)) }.join('|') << '|'
end
else
puts "Usage: #{$0} [create|destroy|readme]"
end