class JsDuck::OutputDir

Cleans up the output dir from previous JSDuck run. If the output dir contains a .cache directory (and this dir is currently used for caching), it gets preserved, otherwise just an empty output dir is created.

Public Class Methods

cache_dir_needs_preserving(opts) click to toggle source
# File lib/jsduck/output_dir.rb, line 24
def self.cache_dir_needs_preserving(opts)
  opts.cache_dir == opts.output + "/.cache" && File.exists?(opts.cache_dir)
end
clean(opts) click to toggle source

Initializes empty output directory (with optional .cache inside).

# File lib/jsduck/output_dir.rb, line 11
def self.clean(opts)
  if opts.cache && cache_dir_needs_preserving(opts)
    # Remove all files inside <output-dir> except .cache/
    Dir[opts.output + "/*"].each do |file|
      FileUtils.rm_rf(file) unless file =~ /\/.cache\z/
    end
  else
    # Remove and recreate the entire <output-dir>
    FileUtils.rm_rf(opts.output)
    FileUtils.mkdir(opts.output)
  end
end