Skip to content

Commit

Permalink
Add preview to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
sskylar committed Jun 24, 2021
1 parent a0a3de1 commit c123e00
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
29 changes: 29 additions & 0 deletions bin/siteleaf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Commands:
pull Pulls files for configured site from Siteleaf
push Pushes all files in dir to configured site
publish Publish website to hosting provider
preview Generate cloud preview
help Prints this help document
version Prints the siteleaf gem version
Expand Down Expand Up @@ -191,6 +192,24 @@ def publish(site_id, quiet = true)
end
end

def preview(site_id, quiet = true)
site = Siteleaf::Site.new(id: site_id)
job = site.preview

if quiet
puts "=> Preview queued.\n"
else
last_msg = nil
job.stream do |s|
if (msg = s["message"]) && (msg != last_msg)
puts msg
last_msg = msg
end
end
puts "=> Preview completed: https://#{site_id}.cloud-preview.siteleaf.com\n"
end
end

def config(site)
Siteleaf.save_settings({site_id: site.id}, '.siteleaf.yml')
puts "=> Site configured."
Expand Down Expand Up @@ -283,6 +302,16 @@ begin
raise "Site not configured, run `siteleaf config yoursite.com`.\n"
end
end
when 'preview'
site_id = get_site_id
if auth != false
quiet = %w[-q --quiet].include?(ARGV[1]) && ARGV[1]
if site_id
preview(site_id, quiet)
else
raise "Site not configured, run `siteleaf config yoursite.com`.\n"
end
end
when 'import'
site_id = get_site_id
if auth != false
Expand Down
5 changes: 5 additions & 0 deletions lib/siteleaf/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def publish
result = Client.post "#{entity_endpoint}/publish", {}
Job.new(id: result["job_id"]) if result
end

def preview
result = Client.post "#{entity_endpoint}/preview", {}
Job.new(id: result["job_id"]) if result
end

def full_url
"http://#{domain}"
Expand Down
2 changes: 1 addition & 1 deletion lib/siteleaf/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Siteleaf
VERSION = "2.1.1"
VERSION = "2.1.2"
end

0 comments on commit c123e00

Please sign in to comment.