Sha256: ef3c7411f7e114f78a63e1c14f5caa5c01d5b4acdf7f03282a4ce8eee2b89f0b

Contents?: true

Size: 756 Bytes

Versions: 6

Compression:

Stored size: 756 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 "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

6 entries across 6 versions & 1 rubygems

Version Path
opal-1.5.1 lib/opal/util.rb
opal-1.5.0 lib/opal/util.rb
opal-1.5.0.rc1 lib/opal/util.rb
opal-1.4.1 lib/opal/util.rb
opal-1.4.0 lib/opal/util.rb
opal-1.4.0.alpha1 lib/opal/util.rb