Sha256: cc9e1b26ca6042b751a6e6921cccb63b16e133b6ec88f6fabcedf5119ee7099a

Contents?: true

Size: 1.5 KB

Versions: 6

Compression:

Stored size: 1.5 KB

Contents

class Updater
  module Js
    def update_javascript_assets
      log_status 'Updating javascripts...'
      save_to  = @save_to[:js]
      contents = {}
      read_files('js/dist', bootstrap_js_files).each do |name, file|
        contents[name] = file.
            # Remove the source mapping URL comment as this gem does not bundle source maps.
            sub!(%r(^//# sourceMappingURL=#{name}.map\n\z), '') or
            fail "Cannot find source mapping URL to remove in #{name}. Last line: #{file.lines.last.inspect}"
        save_file("#{save_to}/#{name}", file)
      end
      log_processed "#{bootstrap_js_files * ' '}"

      log_status 'Updating javascript manifest'
      manifest = ''
      bootstrap_js_files.each do |name|
        name = name.gsub(/\.js$/, '')
        manifest << "//= require ./bootstrap/#{name}\n"
      end
      dist_js = read_files('dist/js', %w(bootstrap.js bootstrap.min.js))
      {
          'assets/javascripts/bootstrap-sprockets.js' => manifest,
          'assets/javascripts/bootstrap.js'           => dist_js['bootstrap.js'],
          'assets/javascripts/bootstrap.min.js'       => dist_js['bootstrap.min.js'],
      }.each do |path, content|
        save_file path, content
        log_processed path
      end
    end

    def bootstrap_js_files
      @bootstrap_js_files ||= begin
        gruntfile = get_file(file_url 'Gruntfile.js')
        JSON.parse(/concat:.*?src: (\[[^\]]+\])/m.match(gruntfile)[1].tr("'", '"')).map { |p| p.sub %r(\Ajs/src/), '' }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bootstrap-4.0.0.alpha6 tasks/updater/js.rb
bootstrap-4.0.0.alpha5 tasks/updater/js.rb
bootstrap-4.0.0.alpha4 tasks/updater/js.rb
bootstrap-4.0.0.alpha3.1 tasks/updater/js.rb
bootstrap-4.0.0.alpha3 tasks/updater/js.rb
bootstrap-4.0.0.alpha2 tasks/updater/js.rb