Sha256: 410d4bfc6475171c4957e87cf4b9740801f9da8e5237f440f5e9fd83366fd62c

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

module ReactOnRails
  module EnsureAssetsCompiled
    def self.check_built_assets
      return if @checks_complete
      puts "Checking for existing webpack bundles before running tests."
      build_assets_for_type("client")
      build_assets_for_type("server") if ReactOnRails.configuration.server_bundle_js_file.present?
      @checks_complete = true
    end

    def self.build_assets_for_type(type)
      unless running_webpack_watch?(type)
        puts "Building Webpack #{type}-rendering assets..."
        build_output = `cd client && npm run build:#{type}`
        if build_output =~ /error/i
          fail "Error in building assets!\n#{build_output}"
        end

        puts "Webpack #{type}-rendering assets built."
      end
    end

    def self.running_webpack_watch?(type)
      running = `pgrep -fl '\\-w \\-\\-config webpack\\.#{type}\\.rails\\.build\\.config\\.js'`
      if running.present?
        puts "Webpack is running for #{type}-rendering assets, skipping rebuild => #{running.ai}"
        return true
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
react_on_rails-2.3.0 lib/react_on_rails/ensure_assets_compiled.rb
react_on_rails-2.2.0 lib/react_on_rails/ensure_assets_compiled.rb
react_on_rails-2.1.1 lib/react_on_rails/ensure_assets_compiled.rb
react_on_rails-2.1.0 lib/react_on_rails/ensure_assets_compiled.rb