Class: JsDuck::OutputDir

Inherits:
Object
  • Object
show all
Defined in:
lib/jsduck/output_dir.rb

Overview

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.

Class Method Summary collapse

Class Method Details

.cache_dir_needs_preserving(opts) ⇒ Object



24
25
26
# File 'lib/jsduck/output_dir.rb', line 24

def self.cache_dir_needs_preserving(opts)
  opts.cache_dir == opts.output_dir + "/.cache" && File.exists?(opts.cache_dir)
end

.clean(opts) ⇒ Object

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



11
12
13
14
15
16
17
18
19
20
21
22
# 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_dir + "/*"].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_dir)
    FileUtils.mkdir(opts.output_dir)
  end
end