shopify_theme 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ .project
data/README.md CHANGED
@@ -45,3 +45,9 @@ Watch the theme directory and upload any files as they change
45
45
  ````
46
46
  theme watch
47
47
  ````
48
+
49
+ Open the store in the default browser
50
+
51
+ ````
52
+ theme open
53
+ ````
@@ -1,18 +1,20 @@
1
1
  require 'thor'
2
2
  require 'yaml'
3
- YAML::ENGINE.yamler = 'syck'
3
+ YAML::ENGINE.yamler = 'syck' if defined? Syck
4
4
  require 'abbrev'
5
5
  require 'base64'
6
6
  require 'fileutils'
7
7
  require 'json'
8
8
  require 'listen'
9
+ require 'launchy'
9
10
 
10
11
  module ShopifyTheme
11
12
  class Cli < Thor
12
13
  include Thor::Actions
13
14
 
14
- BINARY_EXTENSIONS = %w(png gif jpg jpeg eot svg ttf woff swf)
15
+ BINARY_EXTENSIONS = %w(png gif jpg jpeg eot svg ttf woff swf ico)
15
16
  IGNORE = %w(config.yml)
17
+ TIMEFORMAT = "%H:%M:%S"
16
18
 
17
19
  tasks.keys.abbrev.each do |shortcut, command|
18
20
  map shortcut => command.to_sym
@@ -36,6 +38,15 @@ module ShopifyTheme
36
38
  say("Done.", :green) unless options['quiet']
37
39
  end
38
40
 
41
+ desc "open", "open the store in your browser"
42
+ def open(*keys)
43
+ config = YAML.load_file 'config.yml'
44
+ url = config[:store]
45
+ if Launchy.open url
46
+ say("Done.", :green)
47
+ end
48
+ end
49
+
39
50
  desc "upload FILE", "upload all theme assets to shop"
40
51
  method_option :quiet, :type => :boolean, :default => false
41
52
  def upload(*keys)
@@ -51,7 +62,9 @@ module ShopifyTheme
51
62
  def replace(*keys)
52
63
  say("Are you sure you want to completely replace your shop theme assets? This is not undoable.", :yellow)
53
64
  if ask("Continue? (Y/N): ") == "Y"
54
- remote_assets = keys.empty? ? ShopifyTheme.asset_list : keys
65
+ # only delete files on remote that are not present locally
66
+ # files present on remote and present locally get overridden anyway
67
+ remote_assets = keys.empty? ? (ShopifyTheme.asset_list - local_assets_list) : keys
55
68
  remote_assets.each do |asset|
56
69
  delete_asset(asset, options['quiet'])
57
70
  end
@@ -76,8 +89,8 @@ module ShopifyTheme
76
89
  method_option :quiet, :type => :boolean, :default => false
77
90
  method_option :keep_files, :type => :boolean, :default => false
78
91
  def watch
79
- puts "Watching current folder:"
80
- Listen.to('',:relative_paths => true) do |modified, added, removed|
92
+ puts "Watching current folder: #{Dir.pwd}"
93
+ Listen.to!(Dir.pwd, :relative_paths => true) do |modified, added, removed|
81
94
  modified.each do |filePath|
82
95
  send_asset(filePath, options['quiet']) if local_assets_list.include?(filePath)
83
96
  end
@@ -90,6 +103,9 @@ module ShopifyTheme
90
103
  end
91
104
  end
92
105
  end
106
+
107
+ rescue Interrupt
108
+ puts "exiting..."
93
109
  end
94
110
 
95
111
  private
@@ -107,40 +123,47 @@ module ShopifyTheme
107
123
  if asset['value']
108
124
  # For CRLF line endings
109
125
  content = asset['value'].gsub("\r", "")
126
+ format = "w"
110
127
  elsif asset['attachment']
111
128
  content = Base64.decode64(asset['attachment'])
129
+ format = "w+b"
112
130
  end
113
131
 
114
132
  FileUtils.mkdir_p(File.dirname(key))
115
- File.open(key, "w") {|f| f.write content} if content
133
+ File.open(key, format) {|f| f.write content} if content
116
134
  end
117
135
 
118
136
  def send_asset(asset, quiet=false)
137
+ time = Time.now
119
138
  data = {:key => asset}
120
139
  content = File.read(asset)
121
140
  if ShopifyTheme.is_binary_data?(content) || BINARY_EXTENSIONS.include?(File.extname(asset).gsub('.',''))
141
+ content = IO.read asset
122
142
  data.merge!(:attachment => Base64.encode64(content))
123
143
  else
124
144
  data.merge!(:value => content)
125
145
  end
126
146
 
127
147
  if (response = ShopifyTheme.send_asset(data)).success?
128
- say("Uploaded: #{asset}", :green) unless quiet
148
+ say("[" + time.strftime(TIMEFORMAT) + "] Uploaded: #{asset}", :green) unless quiet
129
149
  else
130
- say("Error: Could not upload #{asset}. #{errors_from_response(response)}", :red)
150
+ say("[" + time.strftime(TIMEFORMAT) + "] Error: Could not upload #{asset}. #{errors_from_response(response)}", :red)
131
151
  end
132
152
  end
133
153
 
134
154
  def delete_asset(key, quiet=false)
155
+ time = Time.now
135
156
  if (response = ShopifyTheme.delete_asset(key)).success?
136
- say("Removed: #{key}", :green) unless quiet
157
+ say("[" + time.strftime(TIMEFORMAT) + "] Removed: #{key}", :green) unless quiet
137
158
  else
138
- say("Error: Could not remove #{key}. #{errors_from_response(response)}", :red)
159
+ say("[" + time.strftime(TIMEFORMAT) + "] Error: Could not remove #{key}. #{errors_from_response(response)}", :red)
139
160
  end
140
161
  end
141
162
 
142
163
  def errors_from_response(response)
143
- response.parsed_response ? response.parsed_response["errors"].values.join(", ") : ""
164
+ if response.parsed_response
165
+ response.parsed_response["errors"] ? response.parsed_response["errors"].values.join(", ") : ""
166
+ end
144
167
  end
145
168
  end
146
169
  end
@@ -1,3 +1,3 @@
1
1
  module ShopifyTheme
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -13,10 +13,12 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{Command line tool to help with developing Shopify themes. Provides simple commands to download, upload and delete files from a theme. Also includes the watch command to watch a directory and upload files as they change.}
14
14
 
15
15
  s.rubyforge_project = "shopify_theme"
16
+ s.add_development_dependency 'rake'
16
17
  s.add_dependency("thor", [">= 0.14.4"])
17
18
  s.add_dependency("httparty", [">= 0.8.0"])
18
19
  s.add_dependency("json")
19
- s.add_dependency("listen")
20
+ s.add_dependency("listen", [">= 1.0.3"])
21
+ s.add_dependency("launchy")
20
22
 
21
23
  s.files = `git ls-files`.split("\n")
22
24
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -2,15 +2,31 @@
2
2
  name: shopify_theme
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.8
5
+ version: 0.0.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Duff
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-07 00:00:00.000000000 Z
12
+ date: 2013-07-20 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ none: false
21
+ name: rake
22
+ type: :development
23
+ prerelease: false
24
+ requirement: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ! '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ none: false
14
30
  - !ruby/object:Gem::Dependency
15
31
  version_requirements: !ruby/object:Gem::Requirement
16
32
  requirements:
@@ -64,11 +80,27 @@ dependencies:
64
80
  requirements:
65
81
  - - ! '>='
66
82
  - !ruby/object:Gem::Version
67
- version: '0'
83
+ version: 1.0.3
68
84
  none: false
69
85
  name: listen
70
86
  type: :runtime
71
87
  prerelease: false
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: 1.0.3
93
+ none: false
94
+ - !ruby/object:Gem::Dependency
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ none: false
101
+ name: launchy
102
+ type: :runtime
103
+ prerelease: false
72
104
  requirement: !ruby/object:Gem::Requirement
73
105
  requirements:
74
106
  - - ! '>='