Class: ShopifyTheme::Cli
- Inherits:
-
Thor
- Object
- Thor
- ShopifyTheme::Cli
- Includes:
- Thor::Actions
- Defined in:
- lib/shopify_theme/cli.rb
Constant Summary collapse
- IGNORE =
%w(config.yml)
- DEFAULT_WHITELIST =
%w(layout/ assets/ config/ snippets/ templates/ locales/)
- TIMEFORMAT =
"%H:%M:%S"
Instance Method Summary collapse
- #bootstrap(api_key = nil, password = nil, store = nil, theme_name = nil, master = nil) ⇒ Object
- #check ⇒ Object
- #configure(api_key = nil, password = nil, store = nil, theme_id = nil) ⇒ Object
- #download(*keys) ⇒ Object
- #open(*keys) ⇒ Object
- #remove(*keys) ⇒ Object
- #replace(*keys) ⇒ Object
- #systeminfo ⇒ Object
- #upload(*keys) ⇒ Object
- #watch ⇒ Object
Instance Method Details
#bootstrap(api_key = nil, password = nil, store = nil, theme_name = nil, master = nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/shopify_theme/cli.rb', line 55 def bootstrap(api_key=nil, password=nil, store=nil, theme_name=nil, master=nil) ShopifyTheme.config = {:api_key => api_key, :password => password, :store => store} theme_name ||= 'Timber' say("Registering #{theme_name} theme on #{store}", :green) theme = ShopifyTheme.upload_timber(theme_name, master || false) say("Creating directory named #{theme_name}", :green) empty_directory(theme_name) say("Saving configuration to #{theme_name}", :green) ShopifyTheme.config.merge!(theme_id: theme['id']) create_file("#{theme_name}/config.yml", ShopifyTheme.config.to_yaml) say("Downloading #{theme_name} assets from Shopify") Dir.chdir(theme_name) download() end |
#check ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/shopify_theme/cli.rb', line 39 def check if ShopifyTheme.check_config say("Configuration [OK]", :green) else say("Configuration [FAIL]", :red) end end |
#configure(api_key = nil, password = nil, store = nil, theme_id = nil) ⇒ Object
48 49 50 51 |
# File 'lib/shopify_theme/cli.rb', line 48 def configure(api_key=nil, password=nil, store=nil, theme_id=nil) config = {:api_key => api_key, :password => password, :store => store, :theme_id => theme_id} create_file('config.yml', config.to_yaml) end |
#download(*keys) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/shopify_theme/cli.rb', line 77 def download(*keys) assets = keys.empty? ? ShopifyTheme.asset_list : keys if ['exclude'] assets = assets.delete_if { |asset| asset =~ Regexp.new(['exclude']) } end assets.each do |asset| download_asset(asset) say("#{ShopifyTheme.api_usage} Downloaded: #{asset}", :green) unless ['quiet'] end say("Done.", :green) unless ['quiet'] end |
#open(*keys) ⇒ Object
92 93 94 95 96 |
# File 'lib/shopify_theme/cli.rb', line 92 def open(*keys) if Launchy.open shop_theme_url say("Done.", :green) end end |
#remove(*keys) ⇒ Object
129 130 131 132 133 134 |
# File 'lib/shopify_theme/cli.rb', line 129 def remove(*keys) keys.each do |key| delete_asset(key, ['quiet']) end say("Done.", :green) unless ['quiet'] end |
#replace(*keys) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/shopify_theme/cli.rb', line 110 def replace(*keys) say("Are you sure you want to completely replace your shop theme assets? This is not undoable.", :yellow) if ask("Continue? (Y/N): ") == "Y" # only delete files on remote that are not present locally # files present on remote and present locally get overridden anyway remote_assets = keys.empty? ? (ShopifyTheme.asset_list - local_assets_list) : keys remote_assets.each do |asset| delete_asset(asset, ['quiet']) unless ShopifyTheme.ignore_files.any? { |regex| regex =~ asset } end local_assets = keys.empty? ? local_assets_list : keys local_assets.each do |asset| send_asset(asset, ['quiet']) end say("Done.", :green) unless ['quiet'] end end |
#systeminfo ⇒ Object
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/shopify_theme/cli.rb', line 158 def systeminfo ruby_version = "#{RUBY_VERSION}" ruby_version += "-p#{RUBY_PATCHLEVEL}" if RUBY_PATCHLEVEL puts "Ruby: v#{ruby_version}" puts "Operating System: #{RUBY_PLATFORM}" %w(Thor Listen HTTParty Launchy).each do |lib| require "#{lib.downcase}/version" puts "#{lib}: v" + Kernel.const_get("#{lib}::VERSION") end end |
#upload(*keys) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/shopify_theme/cli.rb', line 100 def upload(*keys) assets = keys.empty? ? local_assets_list : keys assets.each do |asset| send_asset(asset, ['quiet']) end say("Done.", :green) unless ['quiet'] end |
#watch ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/shopify_theme/cli.rb', line 139 def watch puts "Watching current folder: #{Dir.pwd}" watcher do |filename, event| filename = filename.gsub("#{Dir.pwd}/", '') next unless local_assets_list.include?(filename) action = if [:changed, :new].include?(event) :send_asset elsif event == :delete :delete_asset else raise NotImplementedError, "Unknown event -- #{event} -- #{filename}" end send(action, filename, ['quiet']) end end |