shopifly 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8db13f5f050e5aad0de97eca0c650bef7409e0e1e7e9797a30f0de940d640d1f
4
- data.tar.gz: 830e26109cc1b5d105bfcd19a2fdb946b14e4f20a99a36389ac9def97e9d4e45
3
+ metadata.gz: 35e1412518c1e2f72097e2e779189b1b840dfab15c779e7d02089a6e09bff16f
4
+ data.tar.gz: 1d7c8ac7401c9574ddbd8baf5c4fc8a2666eb0f616f8c4cbd25edf887ad80a81
5
5
  SHA512:
6
- metadata.gz: 7c5c755de2f883b5d3bde96d37760a7222ec8bd5389e9106dd659caf9345d1a1768acc48099e207b7a00c617fca6e242d79021ec3a4262cd0699ec22a63e5363
7
- data.tar.gz: 7a6ddf16f3e7f84d2ded2f6ec5e0cdc6171054f2bb0966aa7ce89c3a302de1171b75bfa2ddb74459074a363361cf71107e74c2420144560b30899faabc884b4a
6
+ metadata.gz: 91cfcd4db6f2e6bbee87c4df7d7a422edcea7bbe8eccbf0a973d58195ab76b430c7393c815b484138eaf1aae53c80c9e3cbafe2eda16314b509265a9bf712899
7
+ data.tar.gz: bed39267384acb6df58391c6aabc389ea634a0aee3e67f8106390854ef9eea0cbe1e51b4a351c2de07c547b2f1ad015e20b75975d754451ed15e650960027b46
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shopifly (0.2.0)
4
+ shopifly (0.3.0)
5
5
  json (~> 2.3.0)
6
6
  rainbow (~> 3.0.0)
7
7
  shopify_api (~> 8.1.0)
data/lib/shopifly.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "rainbow/refinement"
4
4
  require "shopifly/version"
5
5
  require "shopifly/syncer"
6
+ require "shopifly/config"
6
7
  require "shopifly/cli"
7
8
  require "thor"
8
9
 
data/lib/shopifly/cli.rb CHANGED
@@ -29,17 +29,21 @@ module Shopifly
29
29
 
30
30
  desc "open", "open the current theme in the browser"
31
31
  def open
32
- puts "not yet implemented"
32
+ `theme open`
33
33
  end
34
34
 
35
35
  desc "themes", "open the themes view for the current store"
36
36
  def themes
37
- puts "not yet implemented"
37
+ config = Shopifly::Config.new
38
+ site = config.store_url
39
+ `open "https://#{site}/admin/themes"`
38
40
  end
39
41
 
40
42
  desc "apps", "open the apps view for the current store"
41
43
  def apps
42
- puts "not yet implemented"
44
+ config = Shopifly::Config.new
45
+ site = config.store_url
46
+ `open "https://#{site}/admin/apps"`
43
47
  end
44
48
 
45
49
  desc "init", "initialize with defaults"
@@ -0,0 +1,33 @@
1
+ module Shopifly
2
+ class Config
3
+ attr_reader :current_branch, :shared_config, :store_url, :store_config, :deploy_command, :password
4
+
5
+ def initialize
6
+ file = File.read("config.stores.yml")
7
+ config = YAML.safe_load(file)
8
+
9
+ current_store = File.read(".current_store").strip
10
+ @store_config = config["stores"][current_store]
11
+ store = store_config["store"]
12
+
13
+ @shared_config = config["shared_config"]
14
+ @deploy_command = @shared_config["deploy_command"]
15
+ @current_branch = `git branch | grep \\* | cut -d ' ' -f2`.strip
16
+ @password = store_config["password"]
17
+ @store_url = "#{store}.myshopify.com"
18
+
19
+ api_key = store_config["api_key"]
20
+ api_version = "2019-10"
21
+
22
+ set_shopify_api(api_key, api_version, @password, @store_url)
23
+ end
24
+
25
+ def set_shopify_api(api_key, api_version, password, store_url)
26
+ shop_url = "https://#{api_key}:#{password}@#{store_url}"
27
+ ShopifyAPI::Base.api_version = api_version
28
+ ShopifyAPI::Base.site = shop_url
29
+ end
30
+
31
+ end
32
+ end
33
+
@@ -5,27 +5,9 @@ require "pry"
5
5
  module Shopifly
6
6
  class Syncer
7
7
  def initialize
8
- file = File.read("config.stores.yml")
9
- @config = YAML.safe_load(file)
10
-
11
- @shared_config = @config["shared_config"]
12
- @deploy_command = @shared_config["deploy_command"]
13
- @current_store = File.read(".current_store").strip
14
- @current_branch = `git branch | grep \\* | cut -d ' ' -f2`.strip
15
- store_config = @config["stores"][@current_store]
16
- api_key = store_config["api_key"]
17
- @password = store_config["password"]
18
- store = store_config["store"]
19
- @store_url = "#{store}.myshopify.com"
20
- @api_version = "2019-10"
21
-
22
- set_shopify_api(api_key, @password, @store_url)
23
- end
24
-
25
- def set_shopify_api(api_key, password, store_url)
26
- shop_url = "https://#{api_key}:#{password}@#{store_url}"
27
- ShopifyAPI::Base.api_version = @api_version
28
- ShopifyAPI::Base.site = shop_url
8
+ @config = Shopifly::Config.new
9
+ @store_config = @config.store_config
10
+ @shared_config = @config.shared_config
29
11
  end
30
12
 
31
13
  def sync
@@ -34,12 +16,12 @@ module Shopifly
34
16
  themes_array = ShopifyAPI::Theme.find(:all)
35
17
 
36
18
  current_theme = themes_array.select do |theme|
37
- theme.attributes["name"] == @current_branch
19
+ theme.attributes["name"] == @config.current_branch
38
20
  end.first
39
21
 
40
22
  if current_theme.nil?
41
23
  p "Theme doesn't exist, creating..."
42
- current_theme = create_theme(@current_branch)
24
+ current_theme = create_theme(@config.current_branch)
43
25
 
44
26
  if current_theme.errors.present?
45
27
  return p "Errors: #{current_theme.errors.first}"
@@ -49,7 +31,7 @@ module Shopifly
49
31
  deploy_theme if set_config_for(current_theme, true)
50
32
  end
51
33
  else
52
- p "Theme already exists: #{@current_branch}, #{@store_url}"
34
+ p "Theme already exists: #{@config.current_branch}, #{@config.store_url}"
53
35
  if with_settings
54
36
  with_settings_json(current_theme, default_theme) do
55
37
  set_config_for(current_theme, false)
@@ -62,7 +44,7 @@ module Shopifly
62
44
 
63
45
  def deploy_theme
64
46
  p "Uploading theme!"
65
- system @deploy_command
47
+ system @config.deploy_command
66
48
  end
67
49
 
68
50
  def with_settings_json(current_theme, default_theme)
@@ -116,33 +98,33 @@ module Shopifly
116
98
  end
117
99
 
118
100
  def set_config_for(theme, allow_config_override = false)
119
- p "Setting config to point to #{theme.attributes[:name]}, #{@store_url}"
101
+ p "Setting config to point to #{theme.attributes[:name]}, #{@config.store_url}"
120
102
 
121
103
  ignore_files = allow_config_override ? "[]" : @shared_config["ignore_files"]
122
104
 
123
105
  File.open("config.yml", "w") do |file|
124
106
  file.write <<~CONFIG
125
107
  build:
126
- password: #{@password}
108
+ password: #{@config.password}
127
109
  theme_name: "#{theme.attributes[:name]}"
128
110
  theme_id: #{theme.attributes[:id]}
129
- store: #{@store_url}
111
+ store: #{@config.store_url}
130
112
  directory: #{@shared_config['directory']}
131
113
  ignore_files: #{ignore_files}
132
114
 
133
115
  development:
134
- password: #{@password}
116
+ password: #{@config.password}
135
117
  theme_name: "#{theme.attributes[:name]}"
136
118
  theme_id: #{theme.attributes[:id]}
137
- store: #{@store_url}
119
+ store: #{@config.store_url}
138
120
  directory: #{@shared_config['directory']}
139
121
  ignore_files: #{ignore_files}
140
122
 
141
123
  production:
142
- password: #{@password}
124
+ password: #{@config.password}
143
125
  theme_name: "#{theme.attributes[:name]}"
144
126
  theme_id: #{theme.attributes[:id]}
145
- store: #{@store_url}
127
+ store: #{@config.store_url}
146
128
  directory: #{@shared_config['directory']}
147
129
  ignore_files: #{ignore_files}
148
130
  CONFIG
@@ -1,3 +1,3 @@
1
1
  module Shopifly
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopifly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Pender
@@ -137,6 +137,7 @@ files:
137
137
  - exe/shopifly
138
138
  - lib/shopifly.rb
139
139
  - lib/shopifly/cli.rb
140
+ - lib/shopifly/config.rb
140
141
  - lib/shopifly/syncer.rb
141
142
  - lib/shopifly/version.rb
142
143
  - shopifly.gemspec