Class: ShopifyCLI::Theme::Extension::HostTheme

Inherits:
DevelopmentTheme show all
Defined in:
lib/shopify_cli/theme/extension/host_theme.rb

Instance Attribute Summary

Attributes inherited from Theme

#root

Attributes inherited from Root

#ctx, #root

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DevelopmentTheme

#exists?, find, #role

Methods inherited from Theme

all, create_unpublished, #created_at_runtime?, #current_development?, #development?, #editor_url, #foreign_development?, #initialize, live, #live?, #preview_url, #publish, #role, #shop, #theme_file?, #theme_files, #to_h

Methods inherited from Root

#[], #file?, #glob, #initialize, #json_files, #liquid_files, #static_asset_file?, #static_asset_files, #static_asset_paths

Constructor Details

This class inherits a constructor from ShopifyCLI::Theme::Theme

Class Method Details

.delete(ctx) ⇒ Object



42
43
44
# File 'lib/shopify_cli/theme/extension/host_theme.rb', line 42

def self.delete(ctx)
  new(ctx, root: nil).delete
end

.find_by_identifier(ctx, root: nil, identifier:) ⇒ Object



64
65
66
67
# File 'lib/shopify_cli/theme/extension/host_theme.rb', line 64

def self.find_by_identifier(ctx, root: nil, identifier:)
  ShopifyCLI::DB.set(host_theme_id: identifier)
  find(ctx, root: root)
end

.find_or_create!(ctx) ⇒ Object



60
61
62
# File 'lib/shopify_cli/theme/extension/host_theme.rb', line 60

def self.find_or_create!(ctx)
  new(ctx, root: nil).ensure_exists!
end

Instance Method Details

#createObject



53
54
55
56
57
58
# File 'lib/shopify_cli/theme/extension/host_theme.rb', line 53

def create
  super
  ShopifyCLI::DB.set(host_theme_id: @id)

  generate_tmp_theme
end

#deleteObject



46
47
48
49
50
51
# File 'lib/shopify_cli/theme/extension/host_theme.rb', line 46

def delete
  delete_theme if exists? # Avoid deleting any existing development theme logic

  ShopifyCLI::DB.del(:host_theme_id) if ShopifyCLI::DB.exists?(:host_theme_id)
  ShopifyCLI::DB.del(:host_theme_name) if ShopifyCLI::DB.exists?(:host_theme_name)
end

#ensure_exists!Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/shopify_cli/theme/extension/host_theme.rb', line 31

def ensure_exists!
  if exists?
    @ctx.debug("Using temporary host theme: ##{id} #{name}")
  else
    create
    @ctx.debug("Created temporary host theme: #{@id}")
  end

  self
end

#generate_tmp_themeObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/shopify_cli/theme/extension/host_theme.rb', line 69

def generate_tmp_theme
  ctx = @ctx.dup

  Dir.mktmpdir do |dir|
    @root = Pathname.new(dir)
    ctx.root = dir

    syncer = ShopifyCLI::Theme::Syncer.new(ctx, theme: self)

    begin
      syncer.start_threads
      ::CLI::UI::Frame.open(ctx.message("theme.push.info.pushing", name, id, shop)) do
        UI::HostThemeProgressBar.new(syncer, dir).progress(:upload_theme!, delete: false)
      end
    rescue Errno::ENOENT => e
      ctx.debug(e.message)
    ensure
      syncer.shutdown
    end
  end
end

#idObject



18
19
20
# File 'lib/shopify_cli/theme/extension/host_theme.rb', line 18

def id
  ShopifyCLI::DB.get(:host_theme_id)
end

#nameObject



22
23
24
25
26
27
28
29
# File 'lib/shopify_cli/theme/extension/host_theme.rb', line 22

def name
  existing_name = ShopifyCLI::DB.get(:host_theme_name)
  if existing_name.nil? || existing_name.length > API_NAME_LIMIT
    generate_host_theme_name
  else
    existing_name
  end
end