Sha256: d293995726e9dd310c6c4b5d3df6e70b941264bd42db38916742a76488bd8411

Contents?: true

Size: 1.01 KB

Versions: 8

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require "refinements/pathname"

module Hanamismith
  module Extensions
    # Ensures assets are compiled.
    class Asset
      include Import[:kernel, :logger]

      using Refinements::Pathname

      def self.call(...) = new(...).call

      def initialize(configuration, **)
        super(**)
        @configuration = configuration
      end

      def call
        logger.error { "Unable to compile assets. Try: `hanami assets compile`." } unless run
        configuration
      end

      private

      attr_reader :configuration

      def run
        success = false
        configuration.project_root.change_dir { success = compile_app && compile_home }
        success
      end

      def compile_app
        kernel.system "node config/assets.js -- --path=app --dest=public/assets > /dev/null 2>&1"
      end

      def compile_home
        kernel.system(
          "node config/assets.js -- --path=slices/home --dest=public/assets/_home > /dev/null 2>&1"
        )
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hanamismith-0.38.0 lib/hanamismith/extensions/asset.rb
hanamismith-0.37.0 lib/hanamismith/extensions/asset.rb
hanamismith-0.34.0 lib/hanamismith/extensions/asset.rb
hanamismith-0.33.0 lib/hanamismith/extensions/asset.rb
hanamismith-0.32.0 lib/hanamismith/extensions/asset.rb
hanamismith-0.31.0 lib/hanamismith/extensions/asset.rb
hanamismith-0.30.0 lib/hanamismith/extensions/asset.rb
hanamismith-0.29.0 lib/hanamismith/extensions/asset.rb