class BooticCli::Commands::Themes
Constants
- DEFAULT_LOCKFILE
Public Instance Methods
clone(dir = nil)
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 19 def clone(dir = nil) logged_in_action do local_theme, remote_theme = theme_selector.setup_theme_pair(options['shop'], dir, options['public'], options['dev']) if File.exist?(local_theme.path) prompt.say "Directory already exists! (#{local_theme.path})", :red else prompt.say "Cloning theme files into #{local_theme.path}" workflows.pull(local_theme, remote_theme) local_theme.write_subdomain end end end
compare()
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 119 def compare within_theme do local_theme, remote_theme = theme_selector.select_theme_pair(default_subdomain, current_dir) workflows.compare(local_theme, remote_theme) # if we just compared against the dev theme, redo the mumbo-jumbo but with the public one unless remote_theme.public? prompt.pause "Comparing againt public theme now. Press any key to continue.", :cyan local_theme, public_theme = theme_selector.select_theme_pair(default_subdomain, current_dir, true) workflows.compare(local_theme, public_theme) end end end
dev()
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 36 def dev within_theme do # shop = theme_selector.find_remote_shop(options['shop']) local_theme = theme_selector.select_local_theme(current_dir) shop = theme_selector.find_remote_shop(local_theme.subdomain) remote_theme = theme_selector.select_remote_theme(shop) if options['delete'] if remote_theme.public? return prompt.say("No development theme found!", :red) end unless prompt.yes_or_no?("Are you ABSOLUTELY sure you want to delete your development theme?", false) return prompt.say "No worries, mate." end if remote_theme.delete! prompt.say "No problem! The development theme was removed." else prompt.say "Whoops! Couldn't delete theme dev theme." end else # create unless remote_theme.public? return prompt.say("You already have a development theme set up. If you want to delete it, please pass the --delete flag.", :red) end unless shop.themes.can?(:create_dev_theme) return prompt.say('Dev theme not available!') end unless prompt.yes_or_no?("This will create a development copy of your current public theme. Proceed?", true) return prompt.say "Ok, bye." end result = shop.themes.create_dev_theme if result.has?(:errors) prompt.say "Couldn't create dev theme: #{result.errors.map(&:field).join(', ')}" else prompt.say "Success! You're now working on a development copy of your theme." prompt.say "Any changes you push or sync won't appear on your public website, but on the development version (in /preview/dev)." prompt.say "Once you're ready to merge your changes back, run the `publish` command." end end end end
local_pull(dir)
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 218 def local_pull(dir) within_theme do unless File.directory?(dir) and contains_theme?(dir) prompt.say("Path doesn't exist or doesn't contain theme: #{dir}") abort end dirname = File.dirname(dir) local_theme = theme_selector.select_local_theme(current_dir) parent_theme = theme_selector.select_local_theme(dir) prompt.say "Pulling changes from parent theme at #{dirname}", :green delete_removed = options['delete'].nil? ? false : options['delete'] workflows.pull(local_theme, parent_theme, delete: delete_removed) prompt.say "Synced changes from parent theme at #{dirname} with local one.", :cyan end end
pair()
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 208 def pair within_theme do local_theme = theme_selector.pair(options['shop'], current_dir) prompt.say "Directory #{File.dirname(local_theme.path)} paired with shop #{options['shop']}", :green end end
publish()
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 162 def publish within_theme do local_theme, remote_theme = theme_selector.select_theme_pair(default_subdomain, current_dir) if remote_theme.public? prompt.say "You don't seem to have a development theme set up, so there's nothing to publish. :)", :red prompt.say "To push your local changes directly to your public theme, either run the `push` or `sync` commands.", :red else # check if there are any differences between the dev and public themes local_theme, public_theme = theme_selector.select_theme_pair(default_subdomain, current_dir, true) diff = BooticCli::Themes::ThemeDiff.new(source: remote_theme, target: public_theme) unless diff.any? unless prompt.yes_or_no?("Your public and development themes seem to be in sync (no differences). Publish anyway?", false) prompt.say "Okeysay. Bye." exit 1 end end # prompt.say("Publishing means all your public theme's templates and assets will be replaced and lost.") if prompt.yes_or_no?("Would you like to make a local copy of your current public theme before publishing?", diff.any?) # default to true if changes exist backup_path = File.join(local_theme.path, "public-theme-backup-#{Time.now.to_i}") backup_theme = theme_selector.select_local_theme(backup_path, local_theme.subdomain) prompt.say("Gotcha. Backing up your public theme into #{prompt.highlight(backup_theme.path)}") workflows.pull(backup_theme, public_theme) prompt.say "Done! Existing public theme was saved to #{prompt.highlight(File.basename(backup_theme.path))}", :cyan end workflows.publish(local_theme, remote_theme) end end end
pull()
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 87 def pull within_theme do local_theme, remote_theme = theme_selector.select_theme_pair(default_subdomain, current_dir, options['public']) workflows.pull(local_theme, remote_theme, delete: options['delete'] || true) prompt.say "Done! Preview this theme at #{remote_theme.path}", :cyan end end
push()
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 98 def push within_theme do local_theme, remote_theme = theme_selector.select_theme_pair(default_subdomain, current_dir, options['public']) warn_about_public if remote_theme.public? and options['public'].nil? workflows.push(local_theme, remote_theme, delete: options['delete'] || true) prompt.say "Done! View updated version at #{remote_theme.path}", :cyan end end
sync()
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 109 def sync within_theme do local_theme, remote_theme = theme_selector.select_theme_pair(default_subdomain, current_dir, options['public']) warn_about_public if remote_theme.public? and options['public'].nil? workflows.sync(local_theme, remote_theme) prompt.say "Synced! Preview this theme at #{remote_theme.path}", :cyan end end
watch()
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 136 def watch within_theme do if options['force'].nil? && has_lockfile? prompt.say("Looks like there's another process already watching this dir.") prompt.say("If this is not the case, please run this command with --force (or -f)") abort end local_theme, remote_theme = theme_selector.select_theme_pair(default_subdomain, current_dir, options['public']) warn_about_public if remote_theme.public? and options['public'].nil? diff = BooticCli::Themes::ThemeDiff.new(source: local_theme, target: remote_theme) if diff.any? if prompt.yes_or_no?("There are differences between the remote theme and your local copy. Sync now?", true) workflows.sync(local_theme, remote_theme) prompt.say "Synced!", :cyan end end write_lockfile at_exit { remove_lockfile } workflows.watch(current_dir, remote_theme) end end
Private Instance Methods
contains_theme?(path)
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 271 def contains_theme?(path) File.exist?(File.join(path, 'settings.json')) || File.exist?(File.join(path, 'layout.html')) end
current_dir()
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 279 def current_dir '.' end
current_expanded_dir()
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 283 def current_expanded_dir File.expand_path(current_dir) end
default_subdomain()
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 287 def default_subdomain nil end
has_lockfile?(dir = current_dir, filename = DEFAULT_LOCKFILE)
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 241 def has_lockfile?(dir = current_dir, filename = DEFAULT_LOCKFILE) File.exist?(File.join(dir, filename)) end
is_within_theme?()
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 275 def is_within_theme? contains_theme?(current_expanded_dir) end
prompt()
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 291 def prompt @prompt ||= Prompt.new end
remove_lockfile(dir = current_dir, filename = DEFAULT_LOCKFILE)
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 249 def remove_lockfile(dir = current_dir, filename = DEFAULT_LOCKFILE) FileUtils.rm_f(File.join(dir, filename)) end
theme_selector()
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 299 def theme_selector @theme_selector ||= BooticCli::Themes::ThemeSelector.new(root, prompt: prompt) end
warn_about_public()
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 253 def warn_about_public unless prompt.yes_or_no?("You're pushing changes directly to your public theme. Are you sure?", true) prompt.say("Ok, sure. You can skip the above warning prompt by passing a `--public` flag.") abort end end
within_theme() { || ... }
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 260 def within_theme(&block) unless is_within_theme? prompt.say "This directory doesn't look like a Bootic theme! (#{current_expanded_dir})", :magenta abort end logged_in_action do yield end end
workflows()
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 295 def workflows BooticCli::Themes::Workflows.new(prompt: prompt) end
write_lockfile(dir = current_dir, filename = DEFAULT_LOCKFILE)
click to toggle source
# File lib/bootic_cli/commands/themes.rb, line 245 def write_lockfile(dir = current_dir, filename = DEFAULT_LOCKFILE) File.open(File.join(dir, filename), 'w') { |f| f.write($$) } end