shopify_theme 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/bin/theme +24 -0
- data/lib/shopify_theme.rb +35 -0
- data/lib/shopify_theme/cli.rb +118 -0
- data/lib/shopify_theme/version.rb +3 -0
- data/shopify_theme.gemspec +24 -0
- metadata +120 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Shopify
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Useage
|
2
|
+
|
3
|
+
Generate the config file
|
4
|
+
|
5
|
+
````
|
6
|
+
theme configure api_key password store_url
|
7
|
+
````
|
8
|
+
|
9
|
+
Download all the theme files
|
10
|
+
|
11
|
+
````
|
12
|
+
theme download
|
13
|
+
````
|
14
|
+
|
15
|
+
Upload a theme file
|
16
|
+
|
17
|
+
````
|
18
|
+
theme upload assets/layout.liquid
|
19
|
+
````
|
20
|
+
|
21
|
+
Remove a theme file
|
22
|
+
|
23
|
+
````
|
24
|
+
theme remove assets/layout.liquid
|
25
|
+
````
|
26
|
+
|
27
|
+
Watch the theme directory and upload any files as they change
|
28
|
+
|
29
|
+
````
|
30
|
+
theme watch
|
31
|
+
````
|
data/Rakefile
ADDED
data/bin/theme
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This allows shopify_them to run easily from a git checkout without install.
|
4
|
+
# Hat tip to chriseppstein of Compass fame for the code for this
|
5
|
+
def fallback_load_path(path)
|
6
|
+
retried = false
|
7
|
+
begin
|
8
|
+
yield
|
9
|
+
rescue LoadError
|
10
|
+
unless retried
|
11
|
+
$: << path
|
12
|
+
retried = true
|
13
|
+
retry
|
14
|
+
end
|
15
|
+
raise
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
fallback_load_path(File.join(File.dirname(__FILE__), '..', 'lib')) do
|
20
|
+
require 'shopify_theme'
|
21
|
+
require 'shopify_theme/cli'
|
22
|
+
end
|
23
|
+
|
24
|
+
ShopifyTheme::Cli.start(ARGV)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
module ShopifyTheme
|
3
|
+
class ShopifyParty
|
4
|
+
include HTTParty
|
5
|
+
|
6
|
+
def self.asset_list
|
7
|
+
response = shopify.get("/admin/assets.json")
|
8
|
+
assets = JSON.parse(response.body)["assets"].collect {|a| a['key'] }
|
9
|
+
# Remove any .css files if a .css.liquid file exists
|
10
|
+
assets.reject{|a| assets.include?("#{a}.liquid") }
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.get_asset(asset)
|
14
|
+
response = shopify.get("/admin/assets.json", :query =>{:asset => {:key => asset}})
|
15
|
+
# HTTParty json parsing is broken?
|
16
|
+
JSON.parse(response.body)["asset"]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.send_asset(data)
|
20
|
+
shopify.put("/admin/assets.json", :body =>{:asset => data})
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.delete_asset(asset)
|
24
|
+
shopify.delete("/admin/assets.json", :body =>{:asset => {:key => asset}})
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def self.shopify
|
29
|
+
@config = YAML.load(File.read('config.yml'))
|
30
|
+
basic_auth @config[:api_key], @config[:password]
|
31
|
+
base_uri "http://#{@config[:store]}"
|
32
|
+
ShopifyParty
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'yaml'
|
3
|
+
require 'abbrev'
|
4
|
+
require 'base64'
|
5
|
+
require 'ftools'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
module ShopifyTheme
|
9
|
+
class Cli < Thor
|
10
|
+
include Thor::Actions
|
11
|
+
|
12
|
+
BINARY_EXTENSIONS = %w(png gif jpg jpeg eot svg ttf woff swf)
|
13
|
+
IGNORE = %w(config.yml)
|
14
|
+
|
15
|
+
tasks.keys.abbrev.each do |shortcut, command|
|
16
|
+
map shortcut => command.to_sym
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "configure API_KEY PASSWORD STORE", "generate a config file for the store to connect to"
|
20
|
+
def generate(api_key=nil, password=nil, store=nil)
|
21
|
+
config = {:api_key => api_key, :password => password, :store => store}
|
22
|
+
create_file('config.yml', config.to_yaml)
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "download FILE", "download the shops current theme assets"
|
26
|
+
method_option :quiet, :type => :boolean, :default => false
|
27
|
+
def download(*keys)
|
28
|
+
assets = keys.empty? ? ShopifyParty.asset_list : keys
|
29
|
+
|
30
|
+
assets.each do |asset|
|
31
|
+
download_asset(asset)
|
32
|
+
puts "Downloaded: #{asset}" unless options['quiet']
|
33
|
+
end
|
34
|
+
puts "\nDone." unless options['quiet']
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "upload FILE", "upload all theme assets to shop"
|
38
|
+
method_option :quiet, :type => :boolean, :default => false
|
39
|
+
def upload(*keys)
|
40
|
+
assets = keys.empty? ? local_assets_list : keys
|
41
|
+
assets.each do |a|
|
42
|
+
send_asset(a, options['quiet'])
|
43
|
+
end
|
44
|
+
puts "Done." unless options['quiet']
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "remove FILE", "remove theme asset"
|
48
|
+
method_option :quiet, :type => :boolean, :default => false
|
49
|
+
def remove(*keys)
|
50
|
+
keys.each do |key|
|
51
|
+
if ShopifyParty.delete_asset(key).success?
|
52
|
+
puts "Removed: #{key}" unless options['quiet']
|
53
|
+
else
|
54
|
+
puts "Error: Could not remove #{key} from #{@config['store']}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
puts "Done." unless options['quiet']
|
58
|
+
end
|
59
|
+
|
60
|
+
desc "watch", "upload individual theme assets as they change"
|
61
|
+
method_option :quiet, :type => :boolean, :default => false
|
62
|
+
def watch
|
63
|
+
loop do
|
64
|
+
modified_files.each do |a|
|
65
|
+
send_asset(a, options['quiet'])
|
66
|
+
end
|
67
|
+
sleep(1)
|
68
|
+
end
|
69
|
+
rescue Interrupt
|
70
|
+
puts ""
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def local_assets_list
|
76
|
+
Dir.glob(File.join("**", "*")).reject{ |p| File.directory?(p) || IGNORE.include?(p)}
|
77
|
+
end
|
78
|
+
|
79
|
+
def download_asset(key)
|
80
|
+
asset = ShopifyParty.get_asset(key)
|
81
|
+
if asset['value']
|
82
|
+
# For CRLF line endings
|
83
|
+
content = asset['value'].gsub("\r", "")
|
84
|
+
elsif asset['attachment']
|
85
|
+
content = Base64.decode64(asset['attachment'])
|
86
|
+
end
|
87
|
+
|
88
|
+
File.makedirs(File.dirname(key))
|
89
|
+
File.open(key, "w") {|f| f.write content} if content
|
90
|
+
end
|
91
|
+
|
92
|
+
def send_asset(asset, quiet=false)
|
93
|
+
data = {:key => asset}
|
94
|
+
if (content = File.read(asset)).is_binary_data? || BINARY_EXTENSIONS.include?(File.extname(asset).gsub('.',''))
|
95
|
+
data.merge!(:attachment => Base64.encode64(content))
|
96
|
+
else
|
97
|
+
data.merge!(:value => content)
|
98
|
+
end
|
99
|
+
|
100
|
+
if ShopifyParty.send_asset(data).success?
|
101
|
+
puts "Uploaded: #{asset}" unless quiet
|
102
|
+
else
|
103
|
+
puts "Error: Could not upload #{asset} to #{@config['store']}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def modified_files
|
108
|
+
@reference_time ||= Time.now
|
109
|
+
checked = Time.now
|
110
|
+
|
111
|
+
files = local_assets_list.select do |asset|
|
112
|
+
File.mtime(asset) > @reference_time
|
113
|
+
end
|
114
|
+
@reference_time = checked unless files.empty?
|
115
|
+
files
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "shopify_theme/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "shopify_theme"
|
7
|
+
s.version = ShopifyTheme::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["John Duff"]
|
10
|
+
s.email = ["john.duff@shopify.com"]
|
11
|
+
s.homepage = "https://github.com/Shopify/shopify_theme"
|
12
|
+
s.summary = %q{Command line tool for developing themes}
|
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
|
+
|
15
|
+
s.rubyforge_project = "shopify_theme"
|
16
|
+
s.add_dependency("thor", [">= 0.14.4"])
|
17
|
+
s.add_dependency("httparty")
|
18
|
+
s.add_dependency("json")
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shopify_theme
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- John Duff
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-21 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: thor
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 47
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 14
|
33
|
+
- 4
|
34
|
+
version: 0.14.4
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: httparty
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: json
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
type: :runtime
|
64
|
+
version_requirements: *id003
|
65
|
+
description: 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.
|
66
|
+
email:
|
67
|
+
- john.duff@shopify.com
|
68
|
+
executables:
|
69
|
+
- theme
|
70
|
+
extensions: []
|
71
|
+
|
72
|
+
extra_rdoc_files: []
|
73
|
+
|
74
|
+
files:
|
75
|
+
- .gitignore
|
76
|
+
- Gemfile
|
77
|
+
- MIT-LICENSE
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- bin/theme
|
81
|
+
- lib/shopify_theme.rb
|
82
|
+
- lib/shopify_theme/cli.rb
|
83
|
+
- lib/shopify_theme/version.rb
|
84
|
+
- shopify_theme.gemspec
|
85
|
+
has_rdoc: true
|
86
|
+
homepage: https://github.com/Shopify/shopify_theme
|
87
|
+
licenses: []
|
88
|
+
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
hash: 3
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
version: "0"
|
112
|
+
requirements: []
|
113
|
+
|
114
|
+
rubyforge_project: shopify_theme
|
115
|
+
rubygems_version: 1.6.2
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: Command line tool for developing themes
|
119
|
+
test_files: []
|
120
|
+
|