Class: BooticCli::Commands::Themes

Inherits:
BooticCli::Command show all
Defined in:
lib/bootic_cli/commands/themes.rb

Defined Under Namespace

Classes: Prompt

Constant Summary

Constants included from BooticCli::Connectivity

BooticCli::Connectivity::DEFAULT_ENV

Instance Method Summary collapse

Methods inherited from BooticCli::Command

declare, #help

Instance Method Details

#clone(dir = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bootic_cli/commands/themes.rb', line 20

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

#compareObject



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/bootic_cli/commands/themes.rb', line 85

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?
      local_theme, public_theme = theme_selector.select_theme_pair(default_subdomain, current_dir, true)
      workflows.compare(local_theme, public_theme)
    end
  end
end

#devObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bootic_cli/commands/themes.rb', line 35

def dev
  within_theme do
    local_theme, remote_theme = theme_selector.select_theme_pair(default_subdomain, current_dir)
    unless remote_theme.public?
      prompt.say "You already have a development theme set up!", :red
      abort
    end

    local_theme = theme_selector.create_dev_theme(current_dir)
    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."
    prompt.say "Once you're ready to merge your changes back, run the `publish` command."
  end
end

#openObject



156
157
158
159
160
161
# File 'lib/bootic_cli/commands/themes.rb', line 156

def open
  within_theme do
    _, remote_theme = theme_selector.select_theme_pair(default_subdomain, current_dir, options['public'])
    Launchy.open remote_theme.path
  end
end

#pairObject



165
166
167
168
169
170
# File 'lib/bootic_cli/commands/themes.rb', line 165

def pair
  within_theme do
    local_theme = theme_selector.pair(options['shop'], current_dir)
    prompt.say "Directory #{local_theme.path} paired with shop #{options['shop']}", :green
  end
end

#publishObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/bootic_cli/commands/themes.rb', line 118

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

#pullObject



53
54
55
56
57
58
59
# File 'lib/bootic_cli/commands/themes.rb', line 53

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

#pushObject



64
65
66
67
68
69
70
71
# File 'lib/bootic_cli/commands/themes.rb', line 64

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

#syncObject



75
76
77
78
79
80
81
82
# File 'lib/bootic_cli/commands/themes.rb', line 75

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

#watchObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/bootic_cli/commands/themes.rb', line 100

def watch
  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?

    diff = BooticCli::Themes::ThemeDiff.new(source: local_theme, target: remote_theme)
    if diff.any?
      unless prompt.yes_or_no?("There are differences between the remote theme and your local copy. Continue anyway?", true)
        prompt.say "No problem. Bye."
        exit 1
      end
    end

    workflows.watch(current_dir, remote_theme)
  end
end