lib/nanoc/cli/commands/compile.rb in nanoc-3.8.0 vs lib/nanoc/cli/commands/compile.rb in nanoc-4.0.0a1
- old
+ new
@@ -20,11 +20,11 @@
option :a, :all, '(ignored)'
option :f, :force, '(ignored)'
module Nanoc::CLI::Commands
class Compile < ::Nanoc::CLI::CommandRunner
- extend Nanoc::Memoization
+ extend Nanoc::Int::Memoization
# Listens to compilation events and reacts to them. This abstract class
# does not have a real implementation; subclasses should override {#start}
# and set up notifications to listen to.
#
@@ -68,15 +68,15 @@
# @see Listener#start
def start
require 'tempfile'
setup_diffs
old_contents = {}
- Nanoc::NotificationCenter.on(:will_write_rep) do |rep, snapshot|
+ Nanoc::Int::NotificationCenter.on(:will_write_rep) do |rep, snapshot|
path = rep.raw_path(snapshot: snapshot)
old_contents[rep] = File.file?(path) ? File.read(path) : nil
end
- Nanoc::NotificationCenter.on(:rep_written) do |rep, path, _is_created, _is_modified|
+ Nanoc::Int::NotificationCenter.on(:rep_written) do |rep, path, _is_created, _is_modified|
unless rep.binary?
new_contents = File.file?(path) ? File.read(path) : nil
if old_contents[rep] && new_contents
generate_diff_for(rep, old_contents[rep], new_contents)
end
@@ -151,24 +151,24 @@
# @see Listener#enable_for?
def self.enable_for?(command_runner)
command_runner.options.fetch(:verbose, false)
end
- # @option params [Array<Nanoc::ItemRep>] :reps The list of item representations in the site
+ # @option params [Array<Nanoc::Int::ItemRep>] :reps The list of item representations in the site
def initialize(params = {})
@times = {}
@reps = params.fetch(:reps)
end
# @see Listener#start
def start
- Nanoc::NotificationCenter.on(:filtering_started) do |_rep, filter_name|
+ Nanoc::Int::NotificationCenter.on(:filtering_started) do |_rep, filter_name|
@times[filter_name] ||= []
@times[filter_name] << { start: Time.now }
end
- Nanoc::NotificationCenter.on(:filtering_ended) do |_rep, filter_name|
+ Nanoc::Int::NotificationCenter.on(:filtering_ended) do |_rep, filter_name|
@times[filter_name].last[:stop] = Time.now
end
end
# @see Listener#stop
@@ -259,11 +259,11 @@
@gc_count = 0
end
# @see Listener#start
def start
- Nanoc::NotificationCenter.on(:compilation_started) do |_rep|
+ Nanoc::Int::NotificationCenter.on(:compilation_started) do |_rep|
if @gc_count % 20 == 0
GC.enable
GC.start
GC.disable
end
@@ -285,56 +285,56 @@
command_runner.debug?
end
# @see Listener#start
def start
- Nanoc::NotificationCenter.on(:compilation_started) do |rep|
+ Nanoc::Int::NotificationCenter.on(:compilation_started) do |rep|
puts "*** Started compilation of #{rep.inspect}"
end
- Nanoc::NotificationCenter.on(:compilation_ended) do |rep|
+ Nanoc::Int::NotificationCenter.on(:compilation_ended) do |rep|
puts "*** Ended compilation of #{rep.inspect}"
puts
end
- Nanoc::NotificationCenter.on(:compilation_failed) do |rep, e|
+ Nanoc::Int::NotificationCenter.on(:compilation_failed) do |rep, e|
puts "*** Suspended compilation of #{rep.inspect}: #{e.message}"
end
- Nanoc::NotificationCenter.on(:cached_content_used) do |rep|
+ Nanoc::Int::NotificationCenter.on(:cached_content_used) do |rep|
puts "*** Used cached compiled content for #{rep.inspect} instead of recompiling"
end
- Nanoc::NotificationCenter.on(:filtering_started) do |rep, filter_name|
+ Nanoc::Int::NotificationCenter.on(:filtering_started) do |rep, filter_name|
puts "*** Started filtering #{rep.inspect} with #{filter_name}"
end
- Nanoc::NotificationCenter.on(:filtering_ended) do |rep, filter_name|
+ Nanoc::Int::NotificationCenter.on(:filtering_ended) do |rep, filter_name|
puts "*** Ended filtering #{rep.inspect} with #{filter_name}"
end
- Nanoc::NotificationCenter.on(:visit_started) do |item|
+ Nanoc::Int::NotificationCenter.on(:visit_started) do |item|
puts "*** Started visiting #{item.inspect}"
end
- Nanoc::NotificationCenter.on(:visit_ended) do |item|
+ Nanoc::Int::NotificationCenter.on(:visit_ended) do |item|
puts "*** Ended visiting #{item.inspect}"
end
- Nanoc::NotificationCenter.on(:dependency_created) do |src, dst|
+ Nanoc::Int::NotificationCenter.on(:dependency_created) do |src, dst|
puts "*** Dependency created from #{src.inspect} onto #{dst.inspect}"
end
end
end
# Prints file actions (created, updated, deleted, identical, skipped)
class FileActionPrinter < Listener
- # @option params [Array<Nanoc::ItemRep>] :reps The list of item representations in the site
+ # @option params [Array<Nanoc::Int::ItemRep>] :reps The list of item representations in the site
def initialize(params = {})
@start_times = {}
@reps = params.fetch(:reps)
end
# @see Listener#start
def start
- Nanoc::NotificationCenter.on(:compilation_started) do |rep|
+ Nanoc::Int::NotificationCenter.on(:compilation_started) do |rep|
@start_times[rep.raw_path] = Time.now
end
- Nanoc::NotificationCenter.on(:rep_written) do |_rep, path, is_created, is_modified|
+ Nanoc::Int::NotificationCenter.on(:rep_written) do |_rep, path, is_created, is_modified|
duration = path && @start_times[path] ? Time.now - @start_times[path] : nil
action =
case
when is_created then :create
when is_modified then :update
@@ -374,11 +374,10 @@
def run
time_before = Time.now
load_site
- check_for_deprecated_usage
puts 'Compiling site…'
run_listeners_while do
site.compile
prune
@@ -433,23 +432,9 @@
def reps
site.items.map(&:reps).flatten
end
memoize :reps
-
- def check_for_deprecated_usage
- # Check presence of --all option
- if options.key?(:all) || options.key?(:force)
- $stderr.puts 'Warning: the --force option (and its deprecated --all alias) are, as of nanoc 3.2, no longer supported and have no effect.'
- end
-
- # Warn if trying to compile a single item
- if arguments.size == 1
- $stderr.puts '-' * 80
- $stderr.puts 'Note: As of nanoc 3.2, it is no longer possible to compile a single item. When invoking the “compile” command, all items in the site will be compiled.'
- $stderr.puts '-' * 80
- end
- end
def prune_config
site.config[:prune] || {}
end