Class: StaticExe

Inherits:
Thor
  • Object
show all
Defined in:
lib/staticmatic/deployers/aws-s3.rb

Instance Method Summary collapse

Instance Method Details

#s3_deploy(directory = '.') ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/staticmatic/deployers/aws-s3.rb', line 9

def s3_deploy(directory = '.')
  return if needs_setup? directory
  
  invoke :build, directory unless options[:skip_build]
  
  if build_files(directory).empty?
    say 'Your build/ folder is empty', :red
    say 'Nothing to do.'
    return
  end
  
  amazon_config = YAML::load File.read(amazon_config_path directory)
  env = options[:env] || 'development'
  bucket_name = amazon_config['Buckets'][env]
  
  connect_to_amazon_s3(amazon_config,env,bucket_name)

  build_files(directory).each do |file|
    contents = File.read file
    s3path = file.sub(%r{^\./build/},'')
    
    say "      upload ", :cyan; say s3path
    AWS::S3::S3Object.store(s3path, contents, bucket_name, :access => :public_read)
  end
  say 'Done.'
end

#s3_upload(*files) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/staticmatic/deployers/aws-s3.rb', line 40

def s3_upload(*files)
  return if needs_setup? options[:directory]
  
  if files.length == 0
    say 'No files selected.', :red
    say 'Nothing to do.'
    return
  end
  
  amazon_config = YAML::load File.read(amazon_config_path '.')
  env = options[:env] || 'development'
  bucket_name = amazon_config['Buckets'][env]
  
  connect_to_amazon_s3(amazon_config,env,bucket_name)
  
  files.each do |file|
    
    unless File.exists? file
      say "      Does not exist ", :red; say file; next
    end
    
    contents = File.read file
    s3path = file.sub(%r{^(\./)?build/},'')
  
    say "      upload ", :cyan; say s3path
    AWS::S3::S3Object.store(s3path, contents, bucket_name, :access => :public_read)
  end
end