Sha256: 7808c2eafcc98df90728c840d59b671af7edc3985c89a7305060fde8c8ef647f

Contents?: true

Size: 1.68 KB

Versions: 14

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

usage 'prune'
summary 'remove files not managed by Nanoc from the output directory'
description <<~EOS
  Find all files in the output directory that do not correspond to an item
  managed by Nanoc and remove them. Since this is a hazardous operation, an
  additional `--yes` flag is needed as confirmation.

  Also see the `auto_prune` configuration option in `nanoc.yaml` (`config.yaml`
  for older Nanoc sites), which will automatically prune after compilation.
EOS

flag :y, :yes,       'confirm deletion'
flag :n, :'dry-run', 'print files to be deleted instead of actually deleting them'

module Nanoc::CLI::Commands
  class Prune < ::Nanoc::CLI::CommandRunner
    def run
      @site = load_site
      res = Nanoc::Int::Compiler.new_for(@site).run_until_reps_built
      reps = res.fetch(:reps)

      if options.key?(:yes)
        Nanoc::Pruner.new(@site.config, reps, exclude: prune_config_exclude).run
      elsif options.key?(:'dry-run')
        Nanoc::Pruner.new(@site.config, reps, exclude: prune_config_exclude, dry_run: true).run
      else
        $stderr.puts 'WARNING: Since the prune command is a destructive command, it requires an additional --yes flag in order to work.'
        $stderr.puts
        $stderr.puts 'Please ensure that the output directory does not contain any files (such as images or stylesheets) that are necessary but are not managed by Nanoc. If you want to get a list of all files that would be removed, pass --dry-run.'
        exit 1
      end
    end

    protected

    def prune_config
      @site.config[:prune] || {}
    end

    def prune_config_exclude
      prune_config[:exclude] || {}
    end
  end
end

runner Nanoc::CLI::Commands::Prune

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
nanoc-4.9.3 lib/nanoc/cli/commands/prune.rb
nanoc-4.9.2 lib/nanoc/cli/commands/prune.rb
nanoc-4.9.1 lib/nanoc/cli/commands/prune.rb
nanoc-4.9.0 lib/nanoc/cli/commands/prune.rb
nanoc-4.8.19 lib/nanoc/cli/commands/prune.rb
nanoc-4.8.18 lib/nanoc/cli/commands/prune.rb
nanoc-4.8.17 lib/nanoc/cli/commands/prune.rb
nanoc-4.8.16 lib/nanoc/cli/commands/prune.rb
nanoc-4.8.15 lib/nanoc/cli/commands/prune.rb
nanoc-4.8.14 lib/nanoc/cli/commands/prune.rb
nanoc-4.8.13 lib/nanoc/cli/commands/prune.rb
nanoc-4.8.12 lib/nanoc/cli/commands/prune.rb
nanoc-4.8.11 lib/nanoc/cli/commands/prune.rb
nanoc-4.8.10 lib/nanoc/cli/commands/prune.rb