Sha256: f78d67bed7d6df483a71cc98f2f1ff3166928bcb565f68aadd6e7047a7ab907f

Contents?: true

Size: 1.58 KB

Versions: 16

Compression:

Stored size: 1.58 KB

Contents

require 'jsduck/options/jsb'
require 'jsduck/logger'

module JsDuck
  module Options

    # Finalizes the list of input files.
    class InputFiles
      def initialize(opts)
        @opts = opts
      end

      # Expands opts.input_files (modifying its contents):
      #
      # - When file is a directory, scans all JS, SCSS files in there.
      # - When file is a .jsb3 file, extracts list of files from it.
      # - Otherwise returns array with this same input filename.
      #
      # Then excludes the files and dirs listed in opts.exclude.
      def expand!
        @opts.input_files = expand_files(@opts.input_files)
        exclude_files!(@opts.input_files, @opts.exclude)
      end

      private

      def expand_files(unexpanded_files)
        unexpanded_files.map {|fname| expand_filename(fname) }.flatten
      end

      def expand_filename(fname)
        files = []

        if File.exists?(fname)
          if File.directory?(fname)
            Dir[fname+"/**/*.{js,scss}"].each {|f| files << f }
          elsif fname =~ /\.jsb3$/
            Options::Jsb.read(fname).each {|fn| read_filenames(fn) }
          else
            files << fname
          end
        else
          Logger.warn(nil, "File not found", {:filename => fname})
        end

        files
      end

      # Removes the files matching exclude_paths from list of files
      def exclude_files!(files, exclude_paths)
        exclude_paths.each do |exclude_path|
          exclude_re = Regexp.new('\A' + Regexp.escape(exclude_path))
          files.reject! {|f| f =~ exclude_re }
        end
      end

    end

  end
end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
solvas-jsduck-6.0.0.30539 lib/jsduck/options/input_files.rb
solvas-jsduck-6.0.0.9571 lib/jsduck/options/input_files.rb
solvas-jsduck-6.0.0.6154 lib/jsduck/options/input_files.rb
solvas-jsduck-6.0.0.4021 lib/jsduck/options/input_files.rb
solvas-jsduck-6.0.0.2554 lib/jsduck/options/input_files.rb
solvas-jsduck-6.0.0.1891 lib/jsduck/options/input_files.rb
solvas-jsduck-6.0.0.beta.1888 lib/jsduck/options/input_files.rb
jsduck-troopjs-0.0.10 lib/jsduck/options/input_files.rb
jsduck-troopjs-0.0.9 lib/jsduck/options/input_files.rb
jsduck-troopjs-0.0.8 lib/jsduck/options/input_files.rb
jsduck-troopjs-0.0.7 lib/jsduck/options/input_files.rb
jsduck-troopjs-0.0.5 lib/jsduck/options/input_files.rb
jsduck-troopjs-0.0.4 lib/jsduck/options/input_files.rb
jsduck-troopjs-0.0.3 lib/jsduck/options/input_files.rb
jsduck-troopjs-0.0.1 lib/jsduck/options/input_files.rb
jsduck-6.0.0beta lib/jsduck/options/input_files.rb