lib/nanoc/cli/commands/compile.rb in nanoc-2.1.6 vs lib/nanoc/cli/commands/compile.rb in nanoc-2.2

- old
+ new

@@ -1,8 +1,8 @@ module Nanoc::CLI - class CompileCommand < Command # :nodoc: + class CompileCommand < Cri::Command # :nodoc: def name 'compile' end @@ -29,21 +29,43 @@ [ # --all { :long => 'all', :short => 'a', :argument => :forbidden, :desc => 'compile all pages and assets, even those that aren\'t outdated' - } + }, + # --pages + { + :long => 'pages', :short => 'P', :argument => :forbidden, + :desc => 'only compile pages (no assets)' + }, + # --assets + { + :long => 'assets', :short => 'A', :argument => :forbidden, + :desc => 'only compile assets (no pages)' + }, + # --only-outdated + { + :long => 'only-outdated', :short => 'o', :argument => :forbidden, + :desc => 'only compile outdated pages and assets' + }, ] end def run(options, arguments) # Make sure we are in a nanoc site directory @base.require_site # Find object with given path if arguments.size == 0 - objs = nil + # Find all pages and/or assets + if options.has_key?(:pages) + objs = @base.site.pages + elsif options.has_key?(:assets) + objs = @base.site.assets + else + objs = nil + end else objs = arguments.map do |path| # Find object path = path.cleaned_path obj = @base.site.pages.find { |page| page.path == path } @@ -68,14 +90,22 @@ time_before = Time.now @filter_times ||= {} @times_stack ||= [] setup_notifications + # Parse all/only-outdated options + if options.has_key?(:all) + warn "WARNING: The --all option is no longer necessary as nanoc " + + "2.2 compiles all pages and assets by default. To change this " + + "behaviour, use the --only-outdated option." + end + compile_all = options.has_key?(:'only-outdated') ? false : true + # Compile @base.site.compiler.run( objs, - :even_when_not_outdated => options.has_key?(:all) + :even_when_not_outdated => compile_all ) # Find reps page_reps = @base.site.pages.map { |p| p.reps }.flatten asset_reps = @base.site.assets.map { |a| a.reps }.flatten @@ -85,10 +115,16 @@ reps.select { |r| !r.compiled? }.each do |rep| duration = @rep_times[rep.disk_path] Nanoc::CLI::Logger.instance.file(:low, :skip, rep.disk_path, duration) end + # Show non-written reps + reps.select { |r| r.compiled? && r.attribute_named(:skip_output) }.each do |rep| + duration = @rep_times[rep.disk_path] + Nanoc::CLI::Logger.instance.file(:low, :'not written', rep.disk_path, duration) + end + # Give general feedback puts puts "No objects were modified." unless reps.any? { |r| r.modified? } puts "#{objs.nil? ? 'Site' : 'Object'} compiled in #{format('%.2f', Time.now - time_before)}s." @@ -120,21 +156,23 @@ end end def print_state_feedback(reps) # Categorise reps - rest = reps - created, rest = *rest.partition { |r| r.created? } - modified, rest = *rest.partition { |r| r.modified? } - skipped, rest = *rest.partition { |r| !r.compiled? } - identical = rest + rest = reps + created, rest = *rest.partition { |r| r.created? } + modified, rest = *rest.partition { |r| r.modified? } + skipped, rest = *rest.partition { |r| !r.compiled? } + not_written, rest = *rest.partition { |r| r.compiled? && r.attribute_named(:skip_output) } + identical = rest # Print puts - puts format(' %4d created', created.size) - puts format(' %4d modified', modified.size) - puts format(' %4d skipped', skipped.size) - puts format(' %4d identical', identical.size) + puts format(' %4d created', created.size) + puts format(' %4d modified', modified.size) + puts format(' %4d skipped', skipped.size) + puts format(' %4d not written', not_written.size) + puts format(' %4d identical', identical.size) end def print_profiling_feedback(reps) # Get max filter length max_filter_name_length = @filter_times.keys.map { |k| k.to_s.size }.max