class Agave::Cli
Public Instance Methods
check()
click to toggle source
# File lib/agave/cli.rb, line 57 def check exit 0 if ENV['AGAVE_API_TOKEN'] say 'Site token is not specified!' token = ask "Please paste your AgaveCMS site read-only API token:\n>" if !token || token.empty? puts 'Missing token' exit 1 end File.open('.env', 'a') do |file| file.puts "AGAVE_API_TOKEN=#{token}" end say 'Token added to .env file.' exit 0 end
dump()
click to toggle source
# File lib/agave/cli.rb, line 18 def dump if !ENV['AGAVE_API_TOKEN'] say 'Site token is not specified! Please configure AGAVE_API_TOKEN.' exit 0 end config_file = File.expand_path(options[:config]) watch_mode = options[:watch] preview_mode = options[:preview] client = Agave::Site::Client.new( extra_headers: { 'X-Reason' => 'dump', 'X-SSG' => Dump::SsgDetector.new(Dir.pwd).detect } ) if watch_mode site_id = client.request(:get, '/api/site')['data']['id'] semaphore = Mutex.new thread_safe_dump(semaphore, config_file, client, preview_mode) Agave::Watch::SiteChangeWatcher.new(site_id).connect do thread_safe_dump(semaphore, config_file, client, preview_mode) end watch_config_file(config_file) do thread_safe_dump(semaphore, config_file, client, preview_mode) end sleep else Dump::Runner.new(config_file, client, preview_mode).run end end
thread_safe_dump(semaphore, config_file, client, preview_mode)
click to toggle source
# File lib/agave/cli.rb, line 86 def thread_safe_dump(semaphore, config_file, client, preview_mode) semaphore.synchronize do Dump::Runner.new(config_file, client, preview_mode).run end end
watch_config_file(config_file, &block)
click to toggle source
# File lib/agave/cli.rb, line 78 def watch_config_file(config_file, &block) Listen.to( File.dirname(config_file), only: /#{Regexp.quote(File.basename(config_file))}/, &block ).start end