Class: Rails::Commands::Create

Inherits:
ShopifyCli::SubCommand show all
Defined in:
lib/project_types/rails/commands/create.rb

Constant Summary collapse

USER_AGENT_CODE =
"module ShopifyAPI\n  class Base < ActiveResource::Base\n    self.headers['User-Agent'] << \" | ShopifyApp/\\\#{ShopifyApp::VERSION} | Shopify App CLI\"\n  end\nend\n"
DEFAULT_RAILS_FLAGS =
%w(--skip-spring)

Instance Attribute Summary

Attributes inherited from ShopifyCli::Command

#ctx, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ShopifyCli::SubCommand

call

Methods inherited from ShopifyCli::Command

call, call_help, #initialize, options, prerequisite_task, run_prerequisites, subcommand, subcommand_registry

Methods included from ShopifyCli::Feature::Set

#hidden?, #hidden_feature

Constructor Details

This class inherits a constructor from ShopifyCli::Command

Class Method Details

.helpObject



65
66
67
# File 'lib/project_types/rails/commands/create.rb', line 65

def self.help
  ShopifyCli::Context.message('rails.create.help', ShopifyCli::TOOL_NAME, ShopifyCli::TOOL_NAME)
end

Instance Method Details

#call(args, _name) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/project_types/rails/commands/create.rb', line 26

def call(args, _name)
  form = Forms::Create.ask(@ctx, args, options.flags)
  return @ctx.puts(self.class.help) if form.nil?

  @ctx.abort(@ctx.message('rails.create.error.invalid_ruby_version')) unless
    Ruby.version(@ctx).satisfies?('~>2.5')

  check_node
  check_yarn

  build(form.name, form.db)
  set_custom_ua
  ShopifyCli::Project.write(
    @ctx,
    project_type: 'rails',
    organization_id: form.organization_id,
  )

  api_client = ShopifyCli::Tasks::CreateApiClient.call(
    @ctx,
    org_id: form.organization_id,
    title: form.title,
    type: form.type,
  )

  ShopifyCli::Resources::EnvFile.new(
    api_key: api_client["apiKey"],
    secret: api_client["apiSecretKeys"].first["secret"],
    shop: form.shop_domain,
    scopes: 'write_products,write_customers,write_draft_orders',
  ).write(@ctx)

  partners_url = "https://partners.shopify.com/#{form.organization_id}/apps/#{api_client['id']}"

  @ctx.puts(@ctx.message('rails.create.info.created', form.title, partners_url))
  @ctx.puts(@ctx.message('rails.create.info.serve', form.name, ShopifyCli::TOOL_NAME))
  @ctx.puts(@ctx.message('rails.create.info.install', partners_url, form.title))
end