Sha256: 5b99d80d819590b2616450e6a6aa13f016c22de2dc1338381eaa3d78d0e2a494

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module Script
  module Layers
    module Infrastructure
      class PushPackageRepository
        include SmartProperties
        property! :ctx, accepts: ShopifyCli::Context

        def create_push_package(script, script_content, compiled_type)
          build_file_path = file_path(script.name, compiled_type)
          write_to_path(build_file_path, script_content)

          Domain::PushPackage.new(
            build_file_path,
            script,
            script_content,
            compiled_type,
          )
        end

        def get_push_package(script, compiled_type)
          build_file_path = file_path(script.name, compiled_type)

          raise Domain::PushPackageNotFoundError unless File.exist?(build_file_path)

          script_content = File.read(build_file_path)

          Domain::PushPackage.new(
            build_file_path,
            script,
            script_content,
            compiled_type,
          )
        end

        private

        def write_to_path(path, content)
          ctx.mkdir_p(File.dirname(path))
          ctx.write(path, content)
        end

        def file_path(script_name, compiled_type)
          "#{ScriptProject.current.directory}/build/#{script_name}.#{compiled_type}"
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
shopify-cli-1.0.1 lib/project_types/script/layers/infrastructure/push_package_repository.rb
shopify-cli-1.0.0 lib/project_types/script/layers/infrastructure/push_package_repository.rb
shopify-cli-0.9.3 lib/project_types/script/layers/infrastructure/push_package_repository.rb
shopify-cli-0.9.2 lib/project_types/script/layers/infrastructure/push_package_repository.rb