shopify_theme_multi_shop 0.0.8

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 ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in shopify_theme.gemspec
4
+ gemspec
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,47 @@
1
+ # Requirements
2
+
3
+ Ruby 1.9
4
+
5
+ # Installation
6
+
7
+ ````
8
+ gem install shopify_theme [optional_theme_id]
9
+ ````
10
+
11
+ # Usage
12
+
13
+ Generate the config file. Go get a valid api_key and password for your store head to https://[your store].myshopify.com/admin/api and generate a private application. Default it adds the main theme, if you want to edit one of your other themes, add the theme_id.
14
+
15
+ ````
16
+ theme configure api_key password store_url
17
+ ````
18
+
19
+ Download all the theme files
20
+
21
+ ````
22
+ theme download --env=staging
23
+ ````
24
+
25
+ Upload a theme file
26
+
27
+ ````
28
+ theme upload assets/layout.liquid --env=staging
29
+ ````
30
+
31
+ Remove a theme file
32
+
33
+ ````
34
+ theme remove assets/layout.liquid --env=staging
35
+ ````
36
+
37
+ Completely replace shop theme assets with the local assets
38
+
39
+ ````
40
+ theme replace --env=staging
41
+ ````
42
+
43
+ Watch the theme directory and upload any files as they change
44
+
45
+ ````
46
+ theme watch --env=staging
47
+ ````
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
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,57 @@
1
+ require 'httparty'
2
+ module ShopifyTheme
3
+ include HTTParty
4
+
5
+ NOOPParser = Proc.new {|data, format| {} }
6
+
7
+ def self.asset_list(env)
8
+ # HTTParty parser chokes on assest listing, have it noop
9
+ # and then use a rel JSON parser.
10
+ response = shopify(env).get(path(env), :parser => NOOPParser)
11
+ assets = JSON.parse(response.body)["assets"].collect {|a| a['key'] }
12
+ # Remove any .css files if a .css.liquid file exists
13
+ assets.reject{|a| assets.include?("#{a}.liquid") }
14
+ end
15
+
16
+ def self.get_asset(asset, env)
17
+ response = shopify(env).get(path(env), :query =>{:asset => {:key => asset}}, :parser => NOOPParser)
18
+ # HTTParty json parsing is broken?
19
+ JSON.parse(response.body)["asset"]
20
+ end
21
+
22
+ def self.send_asset(data, env)
23
+ shopify(env).put(path(env), :body =>{:asset => data})
24
+ end
25
+
26
+ def self.delete_asset(asset, env)
27
+ shopify(env).delete(path(env), :body =>{:asset => {:key => asset}})
28
+ end
29
+
30
+ def self.config
31
+ @config ||= YAML.load(File.read('config.yml'))
32
+ end
33
+
34
+ def self.path(env)
35
+ @path ||= config[:"#{env}"][:theme_id] ? "/admin/themes/#{config[:"#{env}"][:theme_id]}/assets.json" : "/admin/assets.json"
36
+ end
37
+
38
+ def self.ignore_files(env)
39
+ files_array = config[:"#{env}"][:ignore_files] || config[:ignore_files] || []
40
+ @ignore_files ||= files_array.compact.collect { |r| Regexp.new(r) }
41
+ end
42
+
43
+ def self.is_binary_data?(string)
44
+ if string.respond_to?(:encoding)
45
+ string.encoding == "US-ASCII"
46
+ else
47
+ ( string.count( "^ -~", "^\r\n" ).fdiv(string.size) > 0.3 || string.index( "\x00" ) ) unless string.empty?
48
+ end
49
+ end
50
+
51
+ private
52
+ def self.shopify(env)
53
+ basic_auth config[:"#{env}"][:api_key], config[:"#{env}"][:password]
54
+ base_uri "http://#{config[:"#{env}"][:store]}"
55
+ ShopifyTheme
56
+ end
57
+ end
@@ -0,0 +1,151 @@
1
+ require 'thor'
2
+ require 'yaml'
3
+ YAML::ENGINE.yamler = 'syck'
4
+ require 'abbrev'
5
+ require 'base64'
6
+ require 'fileutils'
7
+ require 'json'
8
+ require 'listen'
9
+
10
+ module ShopifyTheme
11
+ class Cli < Thor
12
+ include Thor::Actions
13
+
14
+ BINARY_EXTENSIONS = %w(png gif jpg jpeg eot svg ttf woff swf)
15
+ IGNORE = %w(config.yml)
16
+
17
+ tasks.keys.abbrev.each do |shortcut, command|
18
+ map shortcut => command.to_sym
19
+ end
20
+
21
+ desc "configure API_KEY PASSWORD STORE THEME_ID", "generate a config file for the store to connect to"
22
+ def configure(api_key=nil, password=nil, store=nil, theme_id=nil, env='development')
23
+ config = {:"#{env}" => {:api_key => api_key, :password => password, :store => store, :theme_id => theme_id, :ignore_files => ["README"]}}
24
+ create_file('config.yml', config.to_yaml)
25
+ end
26
+
27
+ desc "download FILE", "download the shops current theme assets"
28
+ method_option :quiet, :type => :boolean, :default => false
29
+ method_option :env, :type => :string, :default => 'development'
30
+ def download(*keys)
31
+ assets = keys.empty? ? ShopifyTheme.asset_list(env) : keys
32
+
33
+ assets.each do |asset|
34
+ download_asset(asset, options['env'])
35
+ say("Downloaded: #{asset}", :green) unless options['quiet']
36
+ end
37
+ say("Done.", :green) unless options['quiet']
38
+ end
39
+
40
+ desc "upload FILE", "upload all theme assets to shop"
41
+ method_option :quiet, :type => :boolean, :default => false
42
+ method_option :env, :type => :string, :default => 'development'
43
+ def upload(*keys)
44
+ assets = keys.empty? ? local_assets_list(options['env']) : keys
45
+ assets.each do |asset|
46
+ send_asset(asset, options['quiet'], options['env'])
47
+ end
48
+ say("Done.", :green) unless options['quiet']
49
+ end
50
+
51
+ desc "replace FILE", "completely replace shop theme assets with local theme assets"
52
+ method_option :quiet, :type => :boolean, :default => false
53
+ method_option :env, :type => :string, :default => 'development'
54
+ def replace(*keys)
55
+ say("Are you sure you want to completely replace your shop theme assets? This is not undoable.", :yellow)
56
+ if ask("Continue? (Y/N): ") == "Y"
57
+ remote_assets = keys.empty? ? ShopifyTheme.asset_list(options['env']) : keys
58
+ remote_assets.each do |asset|
59
+ delete_asset(asset, options['quiet'], options['env'])
60
+ end
61
+ local_assets = keys.empty? ? local_assets_list(options['env']) : keys
62
+ local_assets.each do |asset|
63
+ send_asset(asset, options['quiet'], options['env'])
64
+ end
65
+ say("Done.", :green) unless options['quiet']
66
+ end
67
+ end
68
+
69
+ desc "remove FILE", "remove theme asset"
70
+ method_option :quiet, :type => :boolean, :default => false
71
+ method_option :env, :type => :string, :default => 'development'
72
+ def remove(*keys)
73
+ keys.each do |key|
74
+ delete_asset(key, options['quiet'], options['env'])
75
+ end
76
+ say("Done.", :green) unless options['quiet']
77
+ end
78
+
79
+ desc "watch", "upload and delete individual theme assets as they change, use the --keep_files flag to disable remote file deletion"
80
+ method_option :quiet, :type => :boolean, :default => false
81
+ method_option :keep_files, :type => :boolean, :default => false
82
+ method_option :env, :type => :string, :default => 'development'
83
+ def watch
84
+ puts "Watching current folder:"
85
+ Listen.to('',:relative_paths => true) do |modified, added, removed|
86
+ modified.each do |filePath|
87
+ send_asset(filePath, options['quiet'], options['env']) if local_assets_list(options['env']).include?(filePath)
88
+ end
89
+ added.each do |filePath|
90
+ send_asset(filePath, options['quiet'], options['env']) if local_assets_list(options['env']).include?(filePath)
91
+ end
92
+ if !options['keep_files']
93
+ removed.each do |filePath|
94
+ delete_asset(filePath, options['quiet'], options['env']) if local_assets_list(options['env']).include?(relative)
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ private
101
+
102
+ def local_assets_list(env)
103
+ Dir.glob(File.join("**", "*")).reject do |p|
104
+ File.directory?(p) || IGNORE.include?(p) || ShopifyTheme.ignore_files(env).any? do |i|
105
+ i =~ p
106
+ end
107
+ end
108
+ end
109
+
110
+ def download_asset(key, env)
111
+ asset = ShopifyTheme.get_asset(key, env)
112
+ if asset['value']
113
+ # For CRLF line endings
114
+ content = asset['value'].gsub("\r", "")
115
+ elsif asset['attachment']
116
+ content = Base64.decode64(asset['attachment'])
117
+ end
118
+
119
+ FileUtils.mkdir_p(File.dirname(key))
120
+ File.open(key, "w") {|f| f.write content} if content
121
+ end
122
+
123
+ def send_asset(asset, quiet=false, env)
124
+ data = {:key => asset}
125
+ content = File.read(asset)
126
+ if ShopifyTheme.is_binary_data?(content) || BINARY_EXTENSIONS.include?(File.extname(asset).gsub('.',''))
127
+ data.merge!(:attachment => Base64.encode64(content))
128
+ else
129
+ data.merge!(:value => content)
130
+ end
131
+
132
+ if (response = ShopifyTheme.send_asset(data, env)).success?
133
+ say("Uploaded: #{asset}", :green) unless quiet
134
+ else
135
+ say("Error: Could not upload #{asset}. #{errors_from_response(response)}", :red)
136
+ end
137
+ end
138
+
139
+ def delete_asset(key, quiet=false, env)
140
+ if (response = ShopifyTheme.delete_asset(key, env)).success?
141
+ say("Removed: #{key}", :green) unless quiet
142
+ else
143
+ say("Error: Could not remove #{key}. #{errors_from_response(response)}", :red)
144
+ end
145
+ end
146
+
147
+ def errors_from_response(response)
148
+ response.parsed_response["errors"] ? response.parsed_response["errors"].values.join(", ") : ""
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,3 @@
1
+ module ShopifyTheme
2
+ VERSION = "0.0.8"
3
+ end
@@ -0,0 +1,25 @@
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_multi_shop"
7
+ s.version = ShopifyTheme::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Chris Hale", "John Duff"]
10
+ s.email = ["design@chrishale.co.uk", "john.duff@shopify.com"]
11
+ s.homepage = "https://github.com/chrishale/shopify_theme"
12
+ s.summary = %q{Command line tool for deploying Shopify themes to multiple enviroments. Forked from github.com/shopify/shopify_theme}
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. github.com/shopify/shopify_theme with the ability to deploy to multitple shops.}
14
+
15
+ # s.rubyforge_project = "shopify_theme"
16
+ s.add_dependency("thor", [">= 0.14.4"])
17
+ s.add_dependency("httparty", [">= 0.8.0"])
18
+ s.add_dependency("json")
19
+ s.add_dependency("listen")
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
25
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shopify_theme_multi_shop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Hale
9
+ - John Duff
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-10-10 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thor
17
+ requirement: &70269633824960 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.14.4
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70269633824960
26
+ - !ruby/object:Gem::Dependency
27
+ name: httparty
28
+ requirement: &70269633856940 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *70269633856940
37
+ - !ruby/object:Gem::Dependency
38
+ name: json
39
+ requirement: &70269633856560 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *70269633856560
48
+ - !ruby/object:Gem::Dependency
49
+ name: listen
50
+ requirement: &70269633856100 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: *70269633856100
59
+ description: Command line tool to help with developing Shopify themes. Provides simple
60
+ commands to download, upload and delete files from a theme. Also includes the watch
61
+ command to watch a directory and upload files as they change. github.com/shopify/shopify_theme
62
+ with the ability to deploy to multitple shops.
63
+ email:
64
+ - design@chrishale.co.uk
65
+ - john.duff@shopify.com
66
+ executables:
67
+ - theme
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - .gitignore
72
+ - Gemfile
73
+ - MIT-LICENSE
74
+ - README.md
75
+ - Rakefile
76
+ - bin/theme
77
+ - lib/shopify_theme.rb
78
+ - lib/shopify_theme/cli.rb
79
+ - lib/shopify_theme/version.rb
80
+ - shopify_theme.gemspec
81
+ homepage: https://github.com/chrishale/shopify_theme
82
+ licenses: []
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.15
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Command line tool for deploying Shopify themes to multiple enviroments. Forked
105
+ from github.com/shopify/shopify_theme
106
+ test_files: []