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



76
77
78
79
80
# File 'lib/shopifydev/commands.rb', line 76

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
# File 'lib/shopifydev/commands.rb', line 44

def gitify
  porcelain = `git status --porcelain`

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

  remote_keys = modified.delete_if do |file|
    not ["assets", "snippets", "templates", "layout"].include?(file.split('/')[0].strip)
  end

  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



60
61
62
63
64
65
66
# File 'lib/shopifydev/commands.rb', line 60

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

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

#upload_glob(glob) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/shopifydev/commands.rb', line 68

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