Class: ShopifyCLI::Services::App::Create::NodeService

Inherits:
BaseService
  • Object
show all
Defined in:
lib/shopify_cli/services/app/create/node_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseService

call

Constructor Details

#initialize(name:, organization_id:, store_domain:, type:, verbose:, context:) ⇒ NodeService

Returns a new instance of NodeService.



10
11
12
13
14
15
16
17
18
# File 'lib/shopify_cli/services/app/create/node_service.rb', line 10

def initialize(name:, organization_id:, store_domain:, type:, verbose:, context:)
  @name = name
  @organization_id = organization_id
  @store_domain = store_domain
  @type = type
  @verbose = verbose
  @context = context
  super()
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



8
9
10
# File 'lib/shopify_cli/services/app/create/node_service.rb', line 8

def context
  @context
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/shopify_cli/services/app/create/node_service.rb', line 8

def name
  @name
end

#organization_idObject (readonly)

Returns the value of attribute organization_id.



8
9
10
# File 'lib/shopify_cli/services/app/create/node_service.rb', line 8

def organization_id
  @organization_id
end

#store_domainObject (readonly)

Returns the value of attribute store_domain.



8
9
10
# File 'lib/shopify_cli/services/app/create/node_service.rb', line 8

def store_domain
  @store_domain
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/shopify_cli/services/app/create/node_service.rb', line 8

def type
  @type
end

#verboseObject (readonly)

Returns the value of attribute verbose.



8
9
10
# File 'lib/shopify_cli/services/app/create/node_service.rb', line 8

def verbose
  @verbose
end

Instance Method Details

#callObject



20
21
22
23
24
25
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
64
65
66
67
68
69
70
71
72
73
# File 'lib/shopify_cli/services/app/create/node_service.rb', line 20

def call
  form = form_data({
    name: name,
    organization_id: organization_id,
    shop_domain: store_domain,
    type: type,
    verbose: verbose,
  })

  raise ShopifyCLI::AbortSilent if form.nil?

  check_node
  check_npm
  build(form.name)

  ShopifyCLI::Project.write(
    context,
    project_type: "node",
    organization_id: form.organization_id,
  )

  api_client = if ShopifyCLI::Environment.acceptance_test?
    {
      "apiKey" => "public_api_key",
      "apiSecretKeys" => [
        {
          "secret" => "api_secret_key",
        },
      ],
    }
  else
    ShopifyCLI::Tasks::CreateApiClient.call(
      context,
      org_id: form.organization_id,
      title: form.name,
      type: form.type,
    )
  end

  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(context)

  partners_url = ShopifyCLI::PartnersAPI.partners_url_for(form.organization_id, api_client["id"])

  context.puts(context.message("apps.create.info.created", form.name, partners_url))
  context.puts(context.message("apps.create.info.serve", form.name, ShopifyCLI::TOOL_NAME))
  unless ShopifyCLI::Shopifolk.acting_as_shopify_organization?
    context.puts(context.message("apps.create.info.install", partners_url, form.name))
  end
end