Class: Versacommerce::CLI::Theme

Inherits:
Thor
  • Object
show all
Defined in:
lib/versacommerce/cli/theme.rb

Instance Method Summary collapse

Instance Method Details

#downloadObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/versacommerce/cli/theme.rb', line 21

def download
  ensure_authorization!
  save_config

  path = Pathname.new(options[:path]).expand_path
  logger.info('Downloading Theme to %s' % path)

  client.files(recursive: true).each do |file|
    logger.debug('Downloading %s' % file.path)
    file.reload_content
    file_path = path.join(file.path)
    FileUtils.mkdir_p(file_path.parent)
    File.open(file_path, 'wb') { |f| f.write(file.content) }
  end

  logger.success('Finished downloading Theme')
end

#uploadObject



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/versacommerce/cli/theme.rb', line 70

def upload
  ensure_authorization!
  save_config

  theme_path = Pathname.new(options[:path]).expand_path
  validate_path!(theme_path)

  logger.info 'Uploading %s' % theme_path
  add_directory(theme_path, theme_path)
  logger.success('Uploaded %s' % theme_path)
end

#watchObject



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
# File 'lib/versacommerce/cli/theme.rb', line 41

def watch
  ensure_authorization!
  save_config

  theme_path = Pathname.new(options[:path]).expand_path
  validate_path!(theme_path)

  logger.info 'Watching %s' % theme_path

  listener = Listen.to(theme_path) do |modified, added, removed|
    removed.each { |absolute_path| delete_file(theme_path, absolute_path) }

    modified.concat(added).each do |absolute_path|
      delete_file(theme_path, absolute_path)
      add_file(theme_path, absolute_path)
    end
  end

  begin
    listener.start
    sleep
  rescue SystemExit, Interrupt
    logger.info('Stopped watching')
    exit
  end
end