lib/nanoc/cli/commands/compile.rb in nanoc-4.8.9 vs lib/nanoc/cli/commands/compile.rb in nanoc-4.8.10
- old
+ new
@@ -9,67 +9,28 @@
module Nanoc::CLI::Commands
class Compile < ::Nanoc::CLI::CommandRunner
attr_accessor :listener_classes
- def initialize(options, arguments, command)
- super
- @listener_classes = default_listener_classes
- end
-
def run
time_before = Time.now
@site = load_site
puts 'Compiling siteā¦'
- run_listeners_while do
- @site.compile
+ compiler = Nanoc::Int::Compiler.new_for(@site)
+ listener = Nanoc::CLI::Commands::CompileListeners::Aggregate.new(
+ command_runner: self,
+ site: @site,
+ compiler: compiler,
+ )
+ listener.run_while do
+ compiler.run_until_end
end
time_after = Time.now
puts
puts "Site compiled in #{format('%.2f', time_after - time_before)}s."
- end
-
- protected
-
- def default_listener_classes
- [
- Nanoc::CLI::Commands::CompileListeners::DiffGenerator,
- Nanoc::CLI::Commands::CompileListeners::DebugPrinter,
- Nanoc::CLI::Commands::CompileListeners::TimingRecorder,
- Nanoc::CLI::Commands::CompileListeners::FileActionPrinter,
- ]
- end
-
- def setup_listeners
- @listeners =
- @listener_classes
- .select { |klass| klass.enable_for?(self, @site) }
- .map { |klass| klass.new(reps: reps) }
-
- @listeners.each(&:start_safely)
- end
-
- def listeners
- @listeners
- end
-
- def run_listeners_while
- setup_listeners
- yield
- ensure
- teardown_listeners
- end
-
- def teardown_listeners
- return unless @listeners
- @listeners.reverse_each(&:stop_safely)
- end
-
- def reps
- @site.compiler.reps
end
end
end
runner Nanoc::CLI::Commands::Compile