#!/usr/bin/env ruby require 'siteleaf' def help 'See https://github.com/siteleaf/siteleaf-gem for documentation.' end def auth(re_auth = false) Siteleaf.load_settings if !re_auth if re_auth or !Siteleaf.api_key print 'Enter your Siteleaf e-mail: ' email = $stdin.gets.chomp print 'Enter your Siteleaf password: ' system 'stty -echo' password = $stdin.gets.chomp system 'stty echo' puts "Authorizing..." if auth = Siteleaf::Client.auth(email, password) and auth.is_a?(Hash) and auth.has_key?('api_key') File.open(Siteleaf.settings_file,'w') do|file| Marshal.dump({:api_key => auth['api_key'], :api_secret => auth['api_secret']}, file) end puts "=> Gem authorized." if re_auth else puts "Could not authorize, check your e-mail or password." end end end def config(site) File.open('config.ru', 'w') { |file| file.write "# Intended for development purposes only, do not upload or use in production. # See https://github.com/siteleaf/siteleaf-gem for documentation. require 'siteleaf' run Siteleaf::Server.new(:site_id => '#{site.id}')" } pow_path = "#{Etc.getpwuid.dir}/.pow" if File.directory?(pow_path) site_no_tld = site.domain.gsub(/\.[a-z]{0,4}$/i,'') site_symlink = "#{pow_path}/#{site_no_tld}" FileUtils.rm(site_symlink) if File.symlink?(site_symlink) FileUtils.symlink(File.dirname(__FILE__), site_symlink) puts "=> Site configured with Pow, open `http://#{site_no_tld}.dev` to test site locally.\n" else puts "=> Site configured, run `siteleaf server` to test site locally.\n" end end case ARGV[0] when '-v', '--version' puts Siteleaf::VERSION when '-h', '--help' puts help when 's', 'server' if File.exist?('config.ru') `rackup config.ru` else puts "No config found, run `siteleaf config yoursite.com`.\n" end when 'auth' auth true when 'c', 'config', 'setup' auth if site = Siteleaf::Site.find_by_domain(ARGV[1]) config site else puts "No site found for `#{ARGV[1]}`, run `siteleaf new #{ARGV[1]}` to create it.\n" end when 'n', 'new' auth if site = Siteleaf::Site.create(:title => ARGV[1], :domain => ARGV[1]) dir = ARGV.size >= 3 ? ARGV[2] : ARGV[1] Dir.mkdir(dir) unless File.directory?(dir) Dir.chdir(dir) config site else puts "Could not create site `#{ARGV[1]}`.\n" end else puts "`#{ARGV[0]}` command not found.\n" puts help end