Sha256: cbdd0252ec4a24a1cfcc504977d7892b6fbdde7777c7bd07130afd670742a3c3

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 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)
          current_metadata = metadata
          if current_metadata.key?('development')
            current_metadata['development']['hangTight']
          else
            current_metadata['entrypoints'][entrypoint_name]
          end
        end

        def clear_cache!
          @metadata = nil
        end

        def manifest
          metadata['assets']
        end

        def self.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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sewing_kit-0.32.0.pre.beta.pre.4 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.32.0.pre.beta.pre.3 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.32.0.pre.beta.pre.1 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.31.2 lib/sewing_kit/webpack/manifest/base.rb
sewing_kit-0.31.1 lib/sewing_kit/webpack/manifest/base.rb