Sha256: a7a1ef12c0b5b17c80cfad567134a5e68e61f1ca42c17b26d4383de7da703473

Contents?: true

Size: 1.98 KB

Versions: 20

Compression:

Stored size: 1.98 KB

Contents

# frozen_string_literal: true
require 'shopify_cli'

module Extension
  class ExtensionProject < ShopifyCli::Project
    class << self
      def write_cli_file(context:, type:)
        ShopifyCli::Project.write(
          context,
          project_type: :extension,
          organization_id: nil,
          "#{ExtensionProjectKeys::EXTENSION_TYPE_KEY}": type
        )
      end

      def write_env_file(context:, title:, api_key: '', api_secret: '', registration_id: nil)
        ShopifyCli::Resources::EnvFile.new(
          api_key: api_key,
          secret: api_secret,
          extra: {
            ExtensionProjectKeys::TITLE_KEY => title,
            ExtensionProjectKeys::REGISTRATION_ID_KEY => registration_id,
          }.compact
        ).write(context)

        current.reload unless project_empty?
      end

      private

      def project_empty?
        directory(Dir.pwd).nil?
      end
    end

    def app
      Models::App.new(api_key: env['api_key'], secret: env['secret'])
    end

    def registered?
      property_present?('api_key') && property_present?('secret') && registration_id?
    end

    def title
      get_extra_field(ExtensionProjectKeys::TITLE_KEY)
    end

    def extension_type_identifier
      config[ExtensionProjectKeys::EXTENSION_TYPE_KEY]
    end

    def registration_id?
      extra_property_present?(ExtensionProjectKeys::REGISTRATION_ID_KEY) &&
        integer?(get_extra_field(ExtensionProjectKeys::REGISTRATION_ID_KEY)) &&
        registration_id > 0
    end

    def registration_id
      get_extra_field(ExtensionProjectKeys::REGISTRATION_ID_KEY).to_i
    end

    def reload
      @env = nil
    end

    private

    def get_extra_field(key)
      extra = env[:extra] || {}
      extra[key]
    end

    def extra_property_present?(key)
      env[:extra].key?(key) && !get_extra_field(key).nil?
    end

    def property_present?(key)
      !env[key].nil? && !env[key].strip.empty?
    end

    def integer?(value)
      value.to_i.to_s == value.to_s
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
shopify-cli-1.6.0 lib/project_types/extension/extension_project.rb
shopify-cli-1.5.0 lib/project_types/extension/extension_project.rb
shopify-cli-1.4.1 lib/project_types/extension/extension_project.rb
shopify-cli-1.4.0 lib/project_types/extension/extension_project.rb
shopify-cli-1.3.1 lib/project_types/extension/extension_project.rb
shopify-cli-1.3.0 lib/project_types/extension/extension_project.rb
shopify-cli-1.2.0 lib/project_types/extension/extension_project.rb
shopify-cli-1.1.2 lib/project_types/extension/extension_project.rb
shopify-cli-1.1.1 lib/project_types/extension/extension_project.rb
shopify-cli-1.1.0 lib/project_types/extension/extension_project.rb
shopify-cli-1.0.5 lib/project_types/extension/extension_project.rb
shopify-cli-1.0.4 lib/project_types/extension/extension_project.rb
shopify-cli-1.0.3 lib/project_types/extension/extension_project.rb
shopify-cli-1.0.2 lib/project_types/extension/extension_project.rb
shopify-cli-1.0.1 lib/project_types/extension/extension_project.rb
shopify-cli-1.0.0 lib/project_types/extension/extension_project.rb
shopify-cli-0.9.3 lib/project_types/extension/extension_project.rb
shopify-cli-0.9.2 lib/project_types/extension/extension_project.rb
shopify-cli-0.9.1 lib/project_types/extension/extension_project.rb
shopify-cli-0.9.0 lib/project_types/extension/extension_project.rb