require "smooster" require "colorize" require "thor" module Smooster module Cli class Executable < Thor desc "test", "Returns test data" def test puts Smooster::Application.instance.api_key() puts Dir.pwd end desc "setup API_KEY", "Setup your smooster gem. Add your API_KEY" def setup(api_key) Smooster::Application.instance.update_api_key(api_key) puts Smooster::Application.instance.api_key() puts "done!" end desc "site SITE_ID [API_URL, HTML_FOLDER]", "Setup a new site / project. SITE_ID is the smooster site_id given, when you create a new site in smooster." #method_options :force => :boolean, :alias => :string def site(site_id, api_url="http://cms.smooster.com/api", html_folder="html") unless File.directory?("#{Smooster::Application.instance.base_dir}/.smo") FileUtils.mkdir_p("#{Smooster::Application.instance.base_dir}/.smo") end config_store = Smooster::Application.instance.config config_store.transaction do config_store[:api_url] = api_url config_store[:html_folder] = html_folder config_store[:site_id] = site_id end end desc "deploy [TYPE]", "deploy your project to the smooster cloud DEFAULT=assets [assets,templates,all]" def deploy(type="assets") puts "Starting push to smooster..." if type == "assets" || type == "all" Smooster::Deploy::MediaAsset.all.each do |ma| status = "[deployed]".colorize(:blue) status = "[unchanged]".colorize(:green) if ma.checksum.to_s == ma.load_checksum.to_s puts "#{ma.file_path} #{status}" ma.upload end end if type == "templates" || type == "all" Smooster::Deploy::SiteTemplate.all.each do |st| status = "[deployed]".colorize(:blue) status = "[unchanged]".colorize(:green) if st.checksum.to_s == st.load_checksum.to_s st.upload puts "#{st.path} #{status}" end end puts "#{type} done!" end desc "load [TYPE]", "load your project from the smooster cloud DEFAULT=assets [assets,templates,all]" def load(type="assets") puts "Starting loading from smooster..." if type == "assets" || type == "all" Smooster::Deploy::MediaAsset.all.each do |ma| status = "[loading]".colorize(:blue) status = "[unchanged]".colorize(:green) if ma.checksum.to_s == ma.load_checksum.to_s puts "#{ma.file_path} #{status}" ma.download end end puts "#{type} done!" end end end end