Sha256: ea8c19264babc67b17736cce6a2b77f5c907cd16d4c711139f8f0ce032f6cbe2

Contents?: true

Size: 1.91 KB

Versions: 40

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

module ReactOnRails
  module TestHelper
    class EnsureAssetsCompiled
      class << self
        attr_accessor :has_been_run
        @has_been_run = false
      end

      attr_reader :webpack_assets_status_checker,
                  :webpack_assets_compiler

      def initialize(webpack_assets_status_checker: nil,
                     webpack_assets_compiler: nil)
        @webpack_assets_status_checker = webpack_assets_status_checker
        @webpack_assets_compiler = webpack_assets_compiler
      end

      # Several Scenarios:
      # 1. No webpack watch processes for static assets and files are mising or out of date.
      # 2. Only webpack watch process for server bundle as we're the  hot reloading setup.
      # 3. For whatever reason, the watch processes are running, but some clean script removed
      #    the generated bundles.
      def call
        # Only check this ONCE during a test run
        return if self.class.has_been_run

        # Be sure we don't do this again.
        self.class.has_been_run = true

        ReactOnRails::LocalesToJs.new

        stale_gen_files = webpack_assets_status_checker.stale_generated_webpack_files

        # All done if no stale files!
        return if stale_gen_files.empty?

        # Inform the developer that we're ensuring gen assets are ready.
        puts_start_compile_check_message(stale_gen_files)

        webpack_assets_compiler.compile_assets
      end

      def puts_start_compile_check_message(stale_files)
        # rubocop:disable Layout/IndentHeredoc
        puts <<-MSG

Detected the following stale generated files:
  #{stale_files.join("\n  ")}

React on Rails will ensure your JavaScript generated files are up to date, using your
`#{ReactOnRails::Utils.prepend_cd_node_modules_directory(ReactOnRails.configuration.build_test_command)}` command.

        MSG
        # rubocop:enable Layout/IndentHeredoc
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
react_on_rails-11.3.1 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.3.1.beta.0 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.3.0 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.2.2 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.2.1 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.1.8 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.1.7 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.1.6 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.1.5 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.1.4 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.1.3 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.1.2 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.1.1 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.1.0 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.1.0.beta.1 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.0.10 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.0.9 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.0.8 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.0.7 lib/react_on_rails/test_helper/ensure_assets_compiled.rb
react_on_rails-11.0.6 lib/react_on_rails/test_helper/ensure_assets_compiled.rb