Skip to content

Commit

Permalink
Spinner & run DSL in child process
Browse files Browse the repository at this point in the history
  • Loading branch information
KaanOzkan committed Dec 16, 2024
1 parent 0a9c83f commit 198d358
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
26 changes: 23 additions & 3 deletions lib/tapioca/commands/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def init_execute
Press #{set_color("enter", :yellow)} to run #{set_color("bin/tapioca gem --all", :yellow)}. Note: This might take long depending on the number of gems.
GEM
STDIN.gets
call(:gem) # TODO: all
show_wait_spinner { call(:gem) } # TODO: all
say("To continue to the next step, press #{set_color("enter", :yellow)}")
STDIN.gets

Expand All @@ -69,10 +69,13 @@ def init_execute
Press #{set_color("enter", :yellow)} to run #{set_color("bin/tapioca dsl", :yellow)}.
DSL
STDIN.gets
begin
call(:dsl)
# $gem_loader.unload
# call(:dsl)
system("bin/tapioca dsl")
rescue
say(set_color("Error: Couldn't generate DSL RBIs", :red))
say(set_color("Error: Couldn't generate DSL RBIs. Ensure your app can be booted locally", :red))
end

say("To continue to the next step, press #{set_color("enter", :yellow)}")
Expand Down Expand Up @@ -100,6 +103,23 @@ def call(name)
invoke(name, [], {})
end

def show_wait_spinner(fps=10)
chars = %w[| / - \\]
delay = 1.0/fps
iter = 0
spinner = Thread.new do
while iter do # Keep spinning until told otherwise
print chars[(iter+=1) % chars.length]
sleep delay
print "\b"
end
end
yield.tap{ # After yielding to the block, save the return value
iter = false # Tell the thread to exit, cleaning up after itself…
spinner.join # …and wait for it to do so.
} # Use the block's return value as the method's
end

# def print_init_next_steps
# say(<<~OUTPUT)
# #{set_color("This project is now set up for use with Sorbet and Tapioca", :bold)}
Expand Down
6 changes: 6 additions & 0 deletions lib/tapioca/loaders/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def load_application(bundle:, prerequire:, postrequire:, default_command:, halt_
halt_upon_load_error: halt_upon_load_error,
)
loader.load
$gem_loader = loader
end
end

Expand All @@ -35,6 +36,11 @@ def load
require_gem_file
end

def unload
puts "Unloading"
$autoloader.unload if $autoloader
end

protected

sig do
Expand Down
6 changes: 3 additions & 3 deletions lib/tapioca/loaders/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def load_engines_in_zeitwerk_mode
managed_dirs = Zeitwerk::Registry.loaders.flat_map(&:dirs).to_set
# We use a fresh loader to load the engine directories, so that we don't interfere with
# any of the existing loaders.
autoloader = Zeitwerk::Loader.new
$autoloader = Zeitwerk::Loader.new

engines.each do |engine|
eager_load_paths(engine).each do |path|
Expand All @@ -125,11 +125,11 @@ def load_engines_in_zeitwerk_mode
# We should not add directories that are already managed by a Zeitwerk loader.
next if managed_dirs.member?(path)

autoloader.push_dir(path)
$autoloader.push_dir(path)
end
end

autoloader.setup
$autoloader.setup
end

sig { void }
Expand Down

0 comments on commit 198d358

Please sign in to comment.