Class: Extension::ExtensionProject

Inherits:
ShopifyCLI::Project show all
Defined in:
lib/project_types/extension/extension_project.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ShopifyCLI::Project

at, clear, #config, current, current_project_type, #env, has_current?, project_name, write

Class Method Details

.generate_temporary_uuidObject



117
118
119
# File 'lib/project_types/extension/extension_project.rb', line 117

def self.generate_temporary_uuid
  "dev-#{SecureRandom.uuid}"
end

.reloadObject



61
62
63
# File 'lib/project_types/extension/extension_project.rb', line 61

def reload
  current.reload unless project_empty?
end

.update_env_file(context:, **updates) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/project_types/extension/extension_project.rb', line 18

def update_env_file(context:, **updates)
  current_config = {
    title: current.title,
    shop: current.env.shop,
    api_key: current.app.api_key,
    api_secret: current.app.secret,
    registration_id: current.registration_id,
    registration_uuid: current.registration_uuid,
    resource_url: current.resource_url,
  }

  write_env_file(
    context: context,
    **current_config,
    **updates
  )
end

.write_cli_file(context:, type:) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/project_types/extension/extension_project.rb', line 9

def write_cli_file(context:, type:)
  ShopifyCLI::Project.write(
    context,
    project_type: :extension,
    organization_id: nil,
    "#{ExtensionProjectKeys::SPECIFICATION_IDENTIFIER_KEY}": type
  )
end

.write_env_file(context:, title:, api_key: "", api_secret: "", registration_id: nil, registration_uuid: nil, resource_url: nil, shop: nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/project_types/extension/extension_project.rb', line 36

def write_env_file(
  context:,
  title:,
  api_key: "",
  api_secret: "",
  registration_id: nil,
  registration_uuid: nil,
  resource_url: nil,
  shop: nil
)
  ShopifyCLI::Resources::EnvFile.new(
    api_key: api_key,
    secret: api_secret,
    shop: shop,
    extra: {
      ExtensionProjectKeys::TITLE_KEY => title,
      ExtensionProjectKeys::REGISTRATION_ID_KEY => registration_id,
      ExtensionProjectKeys::REGISTRATION_UUID_KEY => registration_uuid || generate_temporary_uuid,
      ExtensionProjectKeys::RESOURCE_URL_KEY => resource_url,
    }.compact
  ).write(context)

  reload
end

Instance Method Details

#appObject



72
73
74
75
# File 'lib/project_types/extension/extension_project.rb', line 72

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

#registered?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/project_types/extension/extension_project.rb', line 77

def registered?
  registration_id?
end

#registration_idObject



101
102
103
# File 'lib/project_types/extension/extension_project.rb', line 101

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

#registration_id?Boolean

Returns:

  • (Boolean)


95
96
97
98
99
# File 'lib/project_types/extension/extension_project.rb', line 95

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

#registration_uuidObject



105
106
107
# File 'lib/project_types/extension/extension_project.rb', line 105

def registration_uuid
  get_extra_field(ExtensionProjectKeys::REGISTRATION_UUID_KEY)
end

#reloadObject



113
114
115
# File 'lib/project_types/extension/extension_project.rb', line 113

def reload
  @env = nil
end

#resource_urlObject



109
110
111
# File 'lib/project_types/extension/extension_project.rb', line 109

def resource_url
  get_extra_field(ExtensionProjectKeys::RESOURCE_URL_KEY)
end

#specification_identifierObject



85
86
87
88
89
90
91
92
93
# File 'lib/project_types/extension/extension_project.rb', line 85

def specification_identifier
  key = ExtensionProjectKeys::SPECIFICATION_IDENTIFIER_KEY

  if ShopifyCLI::Environment.run_as_subprocess?
    get_extra_field(key)
  else
    config[key]
  end
end

#titleObject



81
82
83
# File 'lib/project_types/extension/extension_project.rb', line 81

def title
  get_extra_field(ExtensionProjectKeys::TITLE_KEY)
end