Sha256: 2dd950ea8158223ecfea6ac817605130ef81f690e2f3b49d7359af315f9afc0e

Contents?: true

Size: 1.65 KB

Versions: 5

Compression:

Stored size: 1.65 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:, metadata:, library:)
          build_file_path = file_path(script_project.id)
          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,
            metadata: metadata,
            script_config: script_project.script_config,
            library: library
          )
        end

        def get_push_package(script_project:, metadata:, library:)
          build_file_path = file_path(script_project.id)
          raise Domain::Errors::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,
            metadata: metadata,
            script_config: script_project.script_config,
            library: library
          )
        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)
          "#{path_to_script}/build/script.wasm"
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
shopify-cli-2.12.0 lib/project_types/script/layers/infrastructure/push_package_repository.rb
shopify-cli-2.11.2 lib/project_types/script/layers/infrastructure/push_package_repository.rb
shopify-cli-2.11.1 lib/project_types/script/layers/infrastructure/push_package_repository.rb
shopify-cli-2.11.0 lib/project_types/script/layers/infrastructure/push_package_repository.rb
shopify-cli-2.10.2 lib/project_types/script/layers/infrastructure/push_package_repository.rb