Sha256: 77be1bc19197b3426245922764dd2bf7351d4df4c9eb6ef1ba9b96a0c6418c25

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

require 'shopify_cli'

module ShopifyCli
  module Commands
    class Connect < ShopifyCli::Command
      def call(*)
        project_type = ask_project_type unless Project.has_current?

        if Project.has_current? && Project.current && Project.current.env
          @ctx.puts @ctx.message('core.connect.already_connected_warning')
          prod_warning = @ctx.message('core.connect.production_warning')
          @ctx.puts prod_warning if [:rails, :node].include?(Project.current_project_type)
        end

        org = ShopifyCli::Tasks::EnsureEnv.call(@ctx, regenerate: true)
        api_key = Project.current.env['api_key']
        write_cli_yml(project_type, org['id']) unless Project.has_current?
        @ctx.puts(@ctx.message('core.connect.connected', get_app(org['apps'], api_key).first["title"]))
      end

      def get_app(apps, api_key)
        apps.select { |app| app["apiKey"] == api_key }
      end

      def ask_project_type
        CLI::UI::Prompt.ask(@ctx.message('core.connect.project_type_select')) do |handler|
          ShopifyCli::Commands::Create.all_visible_type.each do |type|
            handler.option(type.project_name) { type.project_type }
          end
        end
      end

      def write_cli_yml(project_type, org_id)
        ShopifyCli::Project.write(
          @ctx,
          project_type: project_type,
          organization_id: org_id,
        )
        @ctx.done(@ctx.message('core.connect.cli_yml_saved'))
      end

      def self.help
        ShopifyCli::Context.message('core.connect.help', ShopifyCli::TOOL_NAME)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shopify-cli-1.0.5 lib/shopify-cli/commands/connect.rb