lib/jim/bundler.rb in jim-0.1.2 vs lib/jim/bundler.rb in jim-0.2.0

- old
+ new

@@ -21,19 +21,22 @@ attr_accessor :jimfile, :index, :requirements, :paths, :options # create a new bundler instance passing in the Jimfile as a `Pathname` or a # string. `index` is a Jim::Index - def initialize(jimfile, index = nil, options = {}) + def initialize(jimfile, index = nil, extra_options = {}) self.jimfile = jimfile.is_a?(Pathname) ? jimfile.read : jimfile self.index = index || Jim::Index.new self.options = {} self.requirements = [] parse_jimfile - self.options.merge(options) - self.add(options[:vendor_dir]) if options[:vendor_dir] + self.options = options.merge(extra_options) self.paths = [] + if options[:vendor_dir] + logger.debug "adding vendor dir to index #{options[:vendor_dir]}" + self.index.add(options[:vendor_dir]) + end end # resove the requirements specified into Jimfile or raise a MissingFile error def resolve! self.requirements.each do |search| @@ -41,23 +44,23 @@ path = self.index.find(name, version) if !path raise(MissingFile, "Could not find #{name} #{version} in any of these paths #{index.directories.join(':')}") end - self.paths << path + self.paths << [path, name, version] end paths end # concatenate all the requirements into a single file and write to `to` or to the # path specified in the :bundled_path option def bundle!(to = nil) resolve! if paths.empty? to = options[:bundled_path] if to.nil? && options[:bundled_path] io = io_for_path(to) - logger.info "bundling to #{to}" if to - paths.each do |path| + logger.info "Bundling to #{to}" if to + paths.each do |path, name, version| io << path.read << "\n" end io end @@ -65,23 +68,23 @@ # then write to `to` or to the path specified in the :bundled_path option. # You can also use the YUI compressor by setting the option :compressor to 'yui' def compress!(to = nil) to = options[:compressed_path] if to.nil? && options[:compressed_path] io = io_for_path(to) - logger.info "compressing to #{to}" + logger.info "Compressing to #{to}" io << compress_js(bundle!(false)) io end # copy each of the requirements into the dir specified with `dir` or the path # specified with the :vendor_dir option - def vendor!(dir = nil) + def vendor!(dir = nil, force = false) resolve! if paths.empty? dir ||= options[:vendor_dir] dir ||= 'vendor' # default - logger.info "vendoring to #{dir}" - paths.each do |path| - Jim::Installer.new(path, dir, :shallow => true).install + logger.info "Vendoring to #{dir}" + paths.each do |path, name, version| + Jim::Installer.new(path, dir, :shallow => true, :force => force).install end end # Run the uncompressed test through a JS compressor (closure-compiler) by # default. Setting options[:compressor] == 'yui' will force the YUI JS Compressor \ No newline at end of file