Sha256: c00522b069b9af1bbe3e53bd425cf06273350ec8e594dcb2119a1992bf20a648

Contents?: true

Size: 1.21 KB

Versions: 8

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

usage 'compile [options]'
summary 'compile items of this site'
description <<~EOS
  Compile all items of the current site.
EOS

flag nil, :diff, 'generate diff'
if Nanoc::Feature.enabled?(Nanoc::Feature::LIVE_CMD)
  flag :w, :watch, 'watch for changes and recompile when needed'
end

module Nanoc::CLI::Commands
  class Compile < ::Nanoc::CLI::CommandRunner
    attr_accessor :listener_classes

    def run
      self.class.enter_site_dir

      if options[:watch]
        run_repeat
      else
        run_once
      end
    end

    def run_repeat
      require 'nanoc/live'
      Nanoc::Live::LiveRecompiler.new(command_runner: self).run
    end

    def run_once
      time_before = Time.now

      @site = load_site

      puts 'Compiling siteā€¦'
      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
  end
end

runner Nanoc::CLI::Commands::Compile

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
nanoc-4.9.3 lib/nanoc/cli/commands/compile.rb
nanoc-4.9.2 lib/nanoc/cli/commands/compile.rb
nanoc-4.9.1 lib/nanoc/cli/commands/compile.rb
nanoc-4.9.0 lib/nanoc/cli/commands/compile.rb
nanoc-4.8.19 lib/nanoc/cli/commands/compile.rb
nanoc-4.8.18 lib/nanoc/cli/commands/compile.rb
nanoc-4.8.17 lib/nanoc/cli/commands/compile.rb
nanoc-4.8.16 lib/nanoc/cli/commands/compile.rb