Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Oct 4, 2024
1 parent defb823 commit 0a501a6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/tapioca/gemfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def contains_path?(path)
sig { void }
def parse_yard_docs
files.each do |path|
YARD.parse(path.to_s, [], Logger::Severity::FATAL)
YARD.parse(path.to_s, [], ::Logger::Severity::FATAL)
rescue RangeError
# In some circumstances, YARD will raise an error when parsing a file
# that is actually valid Ruby. We don't want tapioca to halt in these
Expand Down
9 changes: 9 additions & 0 deletions lib/tapioca/internal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,12 @@
require "tapioca/dsl"
require "tapioca/commands"
require "tapioca/cli"
require "tapioca/logger"

Tapioca.configure do |config|
config.logger = if ENV["TAPIOCA_DEVELOPMENT"]
Tapioca::Logger.new
else
Tapioca::ThorLogger.new
end
end
25 changes: 14 additions & 11 deletions lib/tapioca/loaders/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def initialize(bundle:, prerequire:, postrequire:, default_command:, halt_upon_l

sig { void }
def require_gem_file
say("Requiring all gems to prepare for compiling... ")
Tapioca.configuration.logger.info("Requiring all gems to prepare for compiling... ")
begin
load_bundle(@bundle, @prerequire, @postrequire, @halt_upon_load_error)
rescue LoadError => e
Expand All @@ -68,23 +68,26 @@ def require_gem_file

Runtime::Trackers::Autoload.eager_load_all!

say(" Done", :green)
Tapioca.configuration.logger.info(" Done", :green)
unless @bundle.missing_specs.empty?
say(" completed with missing specs: ")
say(@bundle.missing_specs.join(", "), :yellow)
Tapioca.configuration.logger.info(" completed with missing specs: ")
Tapioca.configuration.logger.info(@bundle.missing_specs.join(", "), :yellow)
end
puts
end

sig { params(file: String, error: LoadError).void }
def explain_failed_require(file, error)
say_error("\n\nLoadError: #{error}", :bold, :red)
say_error("\nTapioca could not load all the gems required by your application.", :yellow)
say_error("If you populated ", :yellow)
say_error("#{file} ", :bold, :blue)
say_error("with ", :yellow)
say_error("`#{@default_command}`", :bold, :blue)
say_error("you should probably review it and remove the faulty line.", :yellow)
Tapioca.configuration.logger.error("\n\nLoadError: #{error}", :bold, :red)
Tapioca.configuration.logger.error(
"\nTapioca could not load all the gems required by your application.",
:yellow,
)
Tapioca.configuration.logger.error("If you populated ", :yellow)
Tapioca.configuration.logger.error("#{file} ", :bold, :blue)
Tapioca.configuration.logger.error("with ", :yellow)
Tapioca.configuration.logger.error("`#{@default_command}`", :bold, :blue)
Tapioca.configuration.logger.error("you should probably review it and remove the faulty line.", :yellow)
end
end
end
Expand Down
32 changes: 32 additions & 0 deletions lib/tapioca/logger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# typed: true
# frozen_string_literal: true

require "thor"

module Tapioca
class Logger
def initialize(stdout = STDOUT)
@stdout = stdout
end

def info(message = "", *_color)
@stdout.puts(message)
end

def error(message = "", *_color)
@stdout.puts(message)
end
end

class ThorLogger
include Thor::Base

def info(...)
say(...)
end

def error(...)
say_error(...)
end
end
end

0 comments on commit 0a501a6

Please sign in to comment.