Sha256: 42167714e17fb473b2fda738a090e2310af647bda652e8e8e5e02b299f8c2dc8

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 KB

Contents

# typed: true
# frozen_string_literal: true

require 'sorbet-runtime'

module Frontman
  module Builder
    class AssetPipeline
      extend T::Sig

      attr_reader :pipelines

      sig { params(external_pipelines: T::Array[Hash]).void }
      def initialize(external_pipelines)
        @pipelines = external_pipelines
      end

      sig { params(timing: Symbol).returns(T::Array[Hash]) }
      def run!(timing)
        pipelines = get_by_timing(timing)

        pipelines.each do |pipeline|
          p "Running external asset pipeline: #{pipeline[:name]}"

          `#{pipeline[:command]}`
          sleep(pipeline[:delay]) if pipeline[:delay]

          p "Finished: #{pipeline[:name]}"
        end

        pipelines
      end

      sig { params(timing: Symbol).returns(T::Array[T.nilable(Integer)]) }
      def run_in_background!(timing)
        pipelines = get_by_timing(timing)

        pipelines.map do |pipeline|
          p "Running external asset pipeline: #{pipeline[:name]}"
          pid = fork { exec(pipeline[:command]) }
          sleep(pipeline[:delay]) if pipeline[:delay]

          pid
        end
      end

      private

      sig { params(timing: Symbol).returns(T::Array[Hash]) }
      def get_by_timing(timing)
        @pipelines.filter { |pipeline| pipeline[:timing] == timing }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
frontman-ssg-0.1.1 lib/frontman/builder/asset_pipeline.rb
frontman-ssg-0.1.0 lib/frontman/builder/asset_pipeline.rb
frontman-ssg-0.0.4 lib/frontman/builder/asset_pipeline.rb
frontman-ssg-0.0.3 lib/frontman/builder/asset_pipeline.rb
frontman-ssg-0.0.2 lib/frontman/builder/asset_pipeline.rb