Sha256: 7dfea0f5a0f834b2a3f847a25cb5fbc531f9e377dfe816fc1eb0eeea97bf5db3

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true
require 'sewing_kit/webpack/webpack'

module SewingKit
  module Webpack
    class Manifest
      class Base
        def initialize
          @metadata = nil
        end

        # :nodoc:
        def asset_dependencies(entrypoint_name)
          metadata['entrypoints'][entrypoint_name]
        end

        def clear_cache!
          @metadata = nil
        end

        def manifest
          metadata['assets']
        end

        def load_metadata_from_node
          begin
            stdout, stderr, status = Open3.capture3('node_modules/.bin/sewing-kit', 'manifest', "--mode=#{mode}")
          rescue => e
            raise NodeSewingKitNotRunnable.new(mode, e)
          end

          raise NodeSewingKitManifestMissing.new(mode, stderr) unless status.success?

          begin
            JSON.parse(stdout)
          rescue => e
            raise ManifestParseError, e
          end
        end

        protected

        def mode
          ENV['NODE_ENV'] || Rails.env.to_s || 'production'
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sewing_kit-0.28.0 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.27.3 lib/sewing_kit/webpack/manifest/base.rb