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/)
- 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
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/shopify_theme/cli.rb', line 43 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
27 28 29 30 31 32 33 |
# File 'lib/shopify_theme/cli.rb', line 27 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
36 37 38 39 |
# File 'lib/shopify_theme/cli.rb', line 36 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
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/shopify_theme/cli.rb', line 65 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
80 81 82 83 84 |
# File 'lib/shopify_theme/cli.rb', line 80 def open(*keys) if Launchy.open shop_theme_url say("Done.", :green) end end |
#remove(*keys) ⇒ Object
117 118 119 120 121 122 |
# File 'lib/shopify_theme/cli.rb', line 117 def remove(*keys) keys.each do |key| delete_asset(key, ['quiet']) end say("Done.", :green) unless ['quiet'] end |
#replace(*keys) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/shopify_theme/cli.rb', line 98 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']) 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
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/shopify_theme/cli.rb', line 146 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
88 89 90 91 92 93 94 |
# File 'lib/shopify_theme/cli.rb', line 88 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
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/shopify_theme/cli.rb', line 127 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 |