Sha256: 132e6c97fc408b7e0d72ba1df90887aba478a94267eb00d427fc30103dd002d4

Contents?: true

Size: 1.73 KB

Versions: 7

Compression:

Stored size: 1.73 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_project:, script_content:, compiled_type:, metadata:)
          build_file_path = file_path(script_project.id, compiled_type)
          write_to_path(build_file_path, script_content)

          Domain::PushPackage.new(
            id: build_file_path,
            uuid: script_project.uuid,
            extension_point_type: script_project.extension_point_type,
            script_content: script_content,
            compiled_type: compiled_type,
            metadata: metadata,
            script_json: script_project.script_json,
          )
        end

        def get_push_package(script_project:, compiled_type:, metadata:)
          build_file_path = file_path(script_project.id, compiled_type)
          raise Domain::PushPackageNotFoundError unless ctx.file_exist?(build_file_path)

          script_content = ctx.binread(build_file_path)
          Domain::PushPackage.new(
            id: build_file_path,
            uuid: script_project.uuid,
            extension_point_type: script_project.extension_point_type,
            script_content: script_content,
            compiled_type: compiled_type,
            metadata: metadata,
            script_json: script_project.script_json,
          )
        end

        private

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

        def file_path(path_to_script, compiled_type)
          "#{path_to_script}/build/script.#{compiled_type}"
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
shopify-cli-2.2.1 lib/project_types/script/layers/infrastructure/push_package_repository.rb
shopify-cli-2.2.0 lib/project_types/script/layers/infrastructure/push_package_repository.rb
shopify-cli-2.1.0 lib/project_types/script/layers/infrastructure/push_package_repository.rb
shopify-cli-2.0.2 lib/project_types/script/layers/infrastructure/push_package_repository.rb
shopify-cli-2.0.1 lib/project_types/script/layers/infrastructure/push_package_repository.rb
shopify-cli-2.0.0 lib/project_types/script/layers/infrastructure/push_package_repository.rb
shopify-cli-1.14.0 lib/project_types/script/layers/infrastructure/push_package_repository.rb