Sha256: 81112884a6589e3bb87c2b74f659862a36381eecc2e9f213c4c562fc301ee92f

Contents?: true

Size: 787 Bytes

Versions: 16

Compression:

Stored size: 787 Bytes

Contents

# frozen_string_literal: true

require 'open3'

module Opal
  module Util
    extend self

    ExitStatusError = Class.new(StandardError)

    # Used for uglifying source to minify.
    #
    #     Opal::Util.uglify("javascript contents")
    #
    # @param str [String] string to minify
    # @return [String]
    def uglify(source, mangle: false)
      sh "#{'ruby ' if Gem.win_platform?}bin/yarn -s run terser -c #{'-m' if mangle}", data: source
    end

    # Gzip code to check file size.
    def gzip(source)
      sh 'gzip -f', data: source
    end

    private

    def sh(command, data:)
      out, _err, status = Open3.capture3(command, stdin_data: data)
      raise ExitStatusError, "exited with status #{status.exitstatus}" unless status.success?
      out
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 lib/opal/util.rb
opal-1.8.2 lib/opal/util.rb
opal-1.8.1 lib/opal/util.rb
opal-1.8.0 lib/opal/util.rb
opal-1.8.0.beta1 lib/opal/util.rb
opal-1.7.4 lib/opal/util.rb
opal-1.8.0.alpha1 lib/opal/util.rb
opal-1.7.3 lib/opal/util.rb
opal-1.7.2 lib/opal/util.rb
opal-1.7.1 lib/opal/util.rb
opal-1.7.0 lib/opal/util.rb
opal-1.7.0.rc1 lib/opal/util.rb
opal-1.6.1 lib/opal/util.rb
opal-1.6.0 lib/opal/util.rb
opal-1.6.0.rc1 lib/opal/util.rb
opal-1.6.0.alpha1 lib/opal/util.rb