Sha256: 13c7e98360fe86316c6d51800c85fdff786c44a848bab8978dc1b5249f5b49dc

Contents?: true

Size: 1.14 KB

Versions: 6

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

require "wasmify-rails"

require "ruby_wasm"
require "ruby_wasm/cli"

module Wasmify
  module Rails
    # A wrapper for rbwasm build command
    class Builder
      ORIGINAL_EXCLUDED_GEMS = RubyWasm::Packager::EXCLUDED_GEMS.dup.freeze

      attr_reader :output_dir

      def initialize(output_dir: Wasmify::Rails.config.tmp_dir)
        @output_dir = output_dir
      end

      def run(name:, exclude_gems: [])
        # Reset excluded gems
        RubyWasm::Packager::EXCLUDED_GEMS.replace(ORIGINAL_EXCLUDED_GEMS)

        # Add configured excluded gems
        Wasmify::Rails.config.exclude_gems.each do |gem_name|
          RubyWasm::Packager::EXCLUDED_GEMS << gem_name
        end

        # Add additional excluded gems
        exclude_gems.each do |gem_name|
          RubyWasm::Packager::EXCLUDED_GEMS << gem_name
        end

        args = %W(
          build
          --ruby-version #{Wasmify::Rails.config.short_ruby_version}
          -o #{File.join(output_dir, name)}
        )

        FileUtils.mkdir_p(output_dir)
        RubyWasm::CLI.new(stdout: $stdout, stderr: $stderr).run(args)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
wasmify-rails-0.1.5 lib/wasmify/rails/builder.rb
wasmify-rails-0.1.4 lib/wasmify/rails/builder.rb
wasmify-rails-0.1.3 lib/wasmify/rails/builder.rb
wasmify-rails-0.1.2 lib/wasmify/rails/builder.rb
wasmify-rails-0.1.1 lib/wasmify/rails/builder.rb
wasmify-rails-0.1.0 lib/wasmify/rails/builder.rb