Class: BooticCli::Themes::Workflows
- Inherits:
-
Object
- Object
- BooticCli::Themes::Workflows
- Defined in:
- lib/bootic_cli/themes/workflows.rb
Constant Summary collapse
- CONCURRENCY =
10
Instance Method Summary collapse
- #compare(local_theme, remote_theme) ⇒ Object
-
#initialize(prompt: NullPrompt) ⇒ Workflows
constructor
A new instance of Workflows.
- #publish(local_theme, remote_theme) ⇒ Object
- #pull(local_theme, remote_theme, destroy: true) ⇒ Object
- #push(local_theme, remote_theme, destroy: true) ⇒ Object
- #sync(local_theme, remote_theme) ⇒ Object
- #watch(dir, remote_theme, watcher: Listen) ⇒ Object
Constructor Details
#initialize(prompt: NullPrompt) ⇒ Workflows
Returns a new instance of Workflows.
30 31 32 |
# File 'lib/bootic_cli/themes/workflows.rb', line 30 def initialize(prompt: NullPrompt) @prompt = prompt end |
Instance Method Details
#compare(local_theme, remote_theme) ⇒ Object
117 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 |
# File 'lib/bootic_cli/themes/workflows.rb', line 117 def compare(local_theme, remote_theme) diff = ThemeDiff.new(source: local_theme, target: remote_theme) notice 'Comparing local and remote copies of theme...' notice "Local <--- Remote" diff.updated_in_target.templates.each do |t| puts "Updated in remote: #{t.file_name}" end diff.missing_in_source.templates.each do |t| puts "Remote template not in local dir: #{t.file_name}" end diff.missing_in_source.assets.each do |t| puts "Remote asset not in local dir: #{t.file_name}" end notice "Local ---> Remote" diff.updated_in_source.templates.each do |t| puts "Updated locally: #{t.file_name}" end diff.missing_in_target.templates.each do |f| puts "Local template not in remote: #{f.file_name}" end diff.missing_in_target.assets.each do |f| puts "Local asset not in remote: #{f.file_name}" end end |
#publish(local_theme, remote_theme) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/bootic_cli/themes/workflows.rb', line 187 def publish(local_theme, remote_theme) keep_old_theme = prompt.yes_or_no?("Do you want to keep your old public theme as your dev theme?", false) # first push local files to dev theme prompt.say "Pushing local changes to development theme" push local_theme, remote_theme, destroy: true # now publish remote dev theme # let it fail if remote_theme doesn't respond to #publish prompt.notice "Publishing development theme" remote_theme.publish(!keep_old_theme) # swap remote themes prompt.notice "Published to #{remote_theme.href}", :yellow end |
#pull(local_theme, remote_theme, destroy: true) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bootic_cli/themes/workflows.rb', line 34 def pull(local_theme, remote_theme, destroy: true) diff = ThemeDiff.new(source: local_theme, target: remote_theme) check_dupes!(local_theme.assets) download_opts = { overwrite: false, interactive: true } notice 'Updating local templates...' maybe_update(diff.updated_in_target.templates, 'remote', 'local') do |t| local_theme.add_template t.file_name, t.body end if destroy notice 'Removing local files that were removed on remote...' remove_all(diff.missing_in_target, local_theme) else notice 'Not removing local files that were removed on remote.' end notice 'Pulling missing files from remote...' copy_templates(diff.missing_in_source, local_theme, download_opts) # lets copy all of them and let user decide to overwrite existing copy_assets(remote_theme, local_theme, download_opts) end |
#push(local_theme, remote_theme, destroy: true) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/bootic_cli/themes/workflows.rb', line 61 def push(local_theme, remote_theme, destroy: true) diff = ThemeDiff.new(source: local_theme, target: remote_theme) check_dupes!(local_theme.assets) notice 'Pushing local changes to remote...' # update existing templates notice 'Updating remote templates...' maybe_update(diff.updated_in_source.templates, 'local', 'remote') do |t| remote_theme.add_template t.file_name, t.body end notice 'Pushing files that are missing in remote...' copy_assets(diff.missing_in_target, remote_theme, overwrite: true) copy_templates(diff.missing_in_target, remote_theme) if destroy notice 'Removing remote files that were removed locally...' remove_all(diff.missing_in_source, remote_theme) else notice 'Not removing remote files that were removed locally.' end end |
#sync(local_theme, remote_theme) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/bootic_cli/themes/workflows.rb', line 85 def sync(local_theme, remote_theme) diff = ThemeDiff.new(source: local_theme, target: remote_theme) check_dupes!(local_theme.assets) notice 'Syncing local copy with remote...' download_opts = { overwrite: false, interactive: false } # first, update existing templates in each side notice 'Updating local templates...' maybe_update(diff.updated_in_target.templates, 'remote', 'local') do |t| local_theme.add_template t.file_name, t.body end notice 'Updating remote templates...' maybe_update(diff.updated_in_source.templates, 'local', 'remote') do |t| remote_theme.add_template t.file_name, t.body end # now, download missing files on local end notice 'Downloading missing local templates & assets...' copy_templates(diff.missing_in_source, local_theme, download_opts) copy_assets(diff.missing_in_source, local_theme, overwrite: true) # now, upload missing files on remote notice 'Uploading missing remote templates & assets...' copy_templates(diff.missing_in_target, remote_theme, download_opts) copy_assets(diff.missing_in_target, remote_theme, overwrite: true) end |
#watch(dir, remote_theme, watcher: Listen) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/bootic_cli/themes/workflows.rb', line 150 def watch(dir, remote_theme, watcher: Listen) listener = watcher.to(dir) do |modified, added, removed| if modified.any? modified.each do |path| upsert_file remote_theme, path end end if added.any? added.each do |path| upsert_file remote_theme, path end end if removed.any? removed.each do |path| delete_file remote_theme, path end end # update local cache remote_theme.reload! end notice "Watching #{File.expand_path(dir)} for changes..." listener.start # ctrl-c Signal.trap('INT') { listener.stop puts 'See you in another lifetime, brotha.' exit } Kernel.sleep end |