Class: Shopifydev::CommandRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/shopifydev/commands.rb

Instance Method Summary collapse

Constructor Details

#initializeCommandRunner

Returns a new instance of CommandRunner.



8
9
10
# File 'lib/shopifydev/commands.rb', line 8

def initialize
  @devshop = Shopifydev::Shop.new(credentials)
end

Instance Method Details

#credentialsObject



12
13
14
15
16
17
18
19
# File 'lib/shopifydev/commands.rb', line 12

def credentials
  unless @credentials
    @credentials = YAML::load(
      File.open('.shopifydev.yaml'))
  end

  @credentials
end

#download(options = {}) ⇒ Object



81
82
83
84
85
# File 'lib/shopifydev/commands.rb', line 81

def download(options={})
  # Download the whole template

  @devshop.template.download
end

#gitifyObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/shopifydev/commands.rb', line 44

def gitify
  porcelain = `git status --porcelain`

  modified = porcelain.scan(/^[ AM][M](.*)/).flatten.each {|f| f.strip!}

  puts modified.inspect

  top_level = ["assets", "snippets", "templates", "layout"]
  remote_keys = modified.select do |file|
      file.split('/').any? { |f| top_level.include?(f) }
  end

  puts remote_keys.inspect

  remote_keys.each do |file|
    `git add #{file}`
  end

  upload(remote_keys)
end

#patchify(patch_dir) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/shopifydev/commands.rb', line 34

def patchify(patch_dir)

  ENV['PATCHIFY_ROOT'] = patch_dir # temporarily set an environment variable

  Dir.glob(File.join(ENV['PATCHIFY_ROOT'], "*/*")).reverse.each do |file|

    self.upload(Array.wrap(File.join(file.split('/')[-2..-1])))
  end
end

#upload(remote_keys) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/shopifydev/commands.rb', line 21

def upload(remote_keys)
  # upload one asset or directory
  raise "no shopify files were specified" if remote_keys.empty?

  remote_keys.each do |remote_key|
    if File.directory?(remote_key) then
      self.upload_dir(remote_key)
    else
      @devshop.asset(remote_key).upload
    end
  end
end

#upload_dir(upload_dir) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/shopifydev/commands.rb', line 65

def upload_dir(upload_dir)
  # upload all assets in the given dir

  Dir[upload_dir + "/**/*"].each do |remote_key|
    self.upload([remote_key].squeeze("/"))
  end
end

#upload_glob(glob) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/shopifydev/commands.rb', line 73

def upload_glob(glob)
  # upload all assets in the given dir matching a given pattern

  glob.each do |remote_key|
    self.upload(remote_key)
  end
end