#!/usr/bin/env ruby require File.expand_path(File.dirname(__FILE__)+ '/../lib/s3_website') class Cfg < Thor desc 'create', 'Create a config file with placeholder values' def create config_file_src = File.dirname(__FILE__) + '/../resources/configuration_file_template.yml' config_file = Dir.pwd + '/s3_website.yml' unless File.exists? config_file require 'fileutils' FileUtils.cp config_file_src, config_file puts "Created the config file s3_website.yml. Go fill it with your settings." end rescue Exception => error puts "#{error.message} (#{error.class})" exit 1 end desc 'apply', 'Apply the configuration on the AWS services' long_desc <<-LONGDESC `s3_website cfg apply` will apply the configuration the S3 bucket. In addition, if you CloudFront related settings, this command will apply them on the CloudFront distribution. If the S3 bucket does not exist, this command will create it and configure it to function as a website. LONGDESC def apply puts 'Applying the configurations in s3_website.yml on the AWS services ...' require 'configure-s3-website' config_source = ConfigureS3Website::FileConfigSource.new 's3_website.yml' ConfigureS3Website::Runner.run({ :config_source => config_source }) rescue Exception => error puts "#{error.message} (#{error.class})" exit 1 end end class Cli < Thor option( :site, :type => :string, :default => 'infer automatically', :desc => "The directory where your website files are. When not defined, s3_website will look for the site in #{S3Website::Paths.site_paths.join(' or ')}." ) option( :config_dir, :type => :string, :default => Dir.pwd, :desc => "The directory where your config file is. When not defined, s3_website will look in the current working directory." ) desc 'push', 'Push local files with the S3 website' long_desc <<-LONGDESC `s3_website push` will upload new and changes files to S3. It will also delete from S3 the files that you no longer have locally. LONGDESC def push call_dir = Dir.pwd Dir.chdir(File.dirname(__FILE__)+ '/..') { # Compile Scala if needed jar_file = File.dirname(__FILE__) + '/../target/scala-2.11/s3_website.jar' unless File.exists? jar_file puts "Compiling the s3_website.jar. This happens only once. Please wait up to a few minutes..." assembly_succeeded = system "./sbt assembly" unless assembly_succeeded puts "Failed to create the s3_website.jar. Please file a bug report." exit 1 end end # Then run it site_path = File.expand_path(S3Website::Paths.infer_site_path options[:site], call_dir) config_dir = File.expand_path options[:config_dir] args = "--site=#{site_path} --config-dir=#{config_dir}" exit system("java -cp #{jar_file} s3.website.Push #{args}") } end desc 'cfg SUBCOMMAND ...ARGS', 'Operate on the config file' subcommand 'cfg', Cfg end Cli.start(ARGV)