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
|
# File 'lib/brut/cli/apps/new/app.rb', line 87
def run
app_name = argv[0]
if !app_name
error "app_name is required"
return 1
end
if terminal.cols >= LOGO_WIDE.lines[0].length
puts theme.title.render("WELCOME TO")
puts
puts theme.title.render(LOGO_WIDE)
elsif terminal.cols >= LOGO_NARROW.lines[0].length
puts theme.title.render("WELCOME TO")
puts
puts theme.title.render(LOGO_NARROW)
else
puts theme.title.render("WELCOME TO BRUT")
end
options.set_default(:app_id, Brut::CLI::Apps::New::AppId.from_app_name(app_name))
options.set_default(:prefix, Brut::CLI::Apps::New::Prefix.from_app_id(options.app_id))
options.set_default(:organization, Brut::CLI::Apps::New::Prefix.from_app_id(options.app_id))
options.set_default(:demo, true)
options.set_default(:dir,Pathname.pwd)
options.set_default(:interactive, true)
segment_names = Set.new(options.segments)
if options.demo?
segment_names << "demo"
end
current_dir = options.dir.expand_path
versions = Brut::CLI::Apps::New::Versions.new
templates_dir = Pathname(
Gem::Specification.find_by_name("brut").gem_dir
) / "templates"
base = Brut::CLI::Apps::New::Base.new(
app_name:,
options:,
versions:,
current_dir:,
templates_dir:
)
segments = [
Brut::CLI::Apps::New::Segments::BareBones.new(
app_name:,
options:,
versions:,
current_dir:,
templates_dir:,
),
]
if options.demo?
segments << Brut::CLI::Apps::New::Segments::Demo.new(
app_name:,
options:,
versions:,
current_dir:,
templates_dir:
)
end
segment_names.each do |segment|
case segment
when "heroku"
segments << Brut::CLI::Apps::New::Segments::Heroku.new(
project_root: base.project_root,
templates_dir:
)
when "sidekiq"
segments << Brut::CLI::Apps::New::Segments::Sidekiq.new(
project_root: base.project_root,
templates_dir:
)
when "docker-deploy"
segments << Brut::CLI::Apps::New::Segments::DockerDeploy.new(
project_root: base.project_root,
templates_dir:
)
when "demo"
else
raise "Segment #{segment} is not supported"
end
end
segments.sort!
info "Creating a new Brut app with these options:"
rows = [
["App Name", app_name],
["Path to New App", current_dir / app_name],
["App Id", options.app_id ],
["Prefix", options.prefix ],
["Organization", options.organization ],
["Segments", segments.map(&:class).map(&:segment_name).join(", ") ],
]
rows.each do |(attr,val)|
info " #{attr}: #{val}"
end
if options.interactive?
puts
puts theme..render("Options for your new app:")
table = Lipgloss::Table.new.(["Attribute", "Value"]).
rows(rows).
border(:rounded).
style_func(rows: rows.size, columns: 2) do |row,column|
if row == Lipgloss::Table::HEADER_ROW
if column == 0
Lipgloss::Style.new.inherit(theme.).align_horizontal(:right).padding_right(1).padding_left(1)
else
Lipgloss::Style.new.inherit(theme.).align_horizontal(:left).padding_right(1).padding_left(1)
end
elsif column == 0
Lipgloss::Style.new.inherit(theme.).align_horizontal(:right).padding_right(1).padding_left(1)
else
Lipgloss::Style.new.inherit(theme.none).align_horizontal(:left).padding_right(1).padding_left(1)
end
end
puts table.render
puts "Proceed? (y/n): "
answer = stdin.gets.strip.downcase
if answer != "y"
puts theme.warning.render("Aborting app creation")
return 0
end
end
if options.dry_run?
info "Dry Run only"
Brut::CLI::Apps::New::Ops::BaseOp.dry_run = true
end
info "Creating Base app"
base.create!
segments.each do |segment|
info "Creating segment: #{segment.class.friendly_name}"
segment.add!
end
puts
print theme..render("Your app ")
print theme..render(app_name)
print theme..render(" was created - time to get building!")
puts
puts
in_computer = Lipgloss::List.new.items(
[
theme.code.render("cd #{current_dir / app_name}"),
theme.code.render("dx/build"),
theme.code.render("dx/start"),
"#{theme.weak.render("(in another terminal)")} #{theme.code.render('dx/exec bash')}",
]
).enumerator(:arabic).enumerator_style(theme.bullet(1))
in_docker = Lipgloss::List.new.items(
[
theme.code.render("bin/setup"),
theme.code.render("bin/dev"),
]
).enumerator(:arabic).enumerator_style(theme.bullet(1))
list = Lipgloss::List.new.items([
"On your computer:\n#{in_computer.render}",
"Inside the Docker container:\n#{in_docker.render}",
"Navigate to #{theme.url.render('http://localhost:6502')} to see your app",
"Inside the Docker container, try #{theme.code.render('bin/setup')} help to find more commands",
]).enumerator(:arabic).
enumerator_style(theme.bullet(0))
puts list.render
puts
end
|