microstatic 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,4 +7,5 @@ The microstatic gem turns generating your static site and deploying it to S3 int
7
7
  The s3 deployment code was originally written by [Giles Alexander](http://twitter.com/gga)
8
8
 
9
9
  ## TODO
10
- - DONE! create Route 53 subdomain on demand
10
+ - specify MICROSTATIC_SITE_NAME and cloud creds using dot file
11
+ -
@@ -3,6 +3,10 @@ require 'rainbow'
3
3
 
4
4
  module Microstatic
5
5
  class CLI < Thor
6
+ include Thor::Actions
7
+
8
+ source_root( File.expand_path( "../../../templates", __FILE__ ) )
9
+
6
10
  desc "setup <APP_NAME>", "do the needful to get started hosting your static site. S3, Route 53, whatever it takes."
7
11
  def setup( app_name = false )
8
12
  app_name ||= inferred_app_name
@@ -11,8 +15,7 @@ module Microstatic
11
15
  bucket = bucket( bucket_name )
12
16
  # TODO: pass bucket through to dns setup so we don't have to look it up again
13
17
  dns( app_name )
14
-
15
- # TODO: add Rakefile, Gemfile, etc for doing a rake deploy using this gem
18
+ rakefile( bucket_name )
16
19
  end
17
20
 
18
21
  desc "bucket <BUCKET_NAME>", "create an S3 bucket which can host your static site"
@@ -26,18 +29,33 @@ module Microstatic
26
29
  describe_operation( "create S3 bucket '#{bucket_name}'" ) do
27
30
  S3BucketCreator.new( config.aws_creds ).create( bucket_name )
28
31
  end
32
+ rescue Microstatic::Config::MissingEnvVar
33
+ raise Thor::Error.new($!)
29
34
  end
30
35
 
31
36
  desc "dns <APP_NAME>", "create a Route 53 entry pointing to the S3 bucket containing your static site"
32
37
  def dns( app_name = false )
33
38
  app_name ||= inferred_app_name
34
39
  bucket_name = subdomain_for(app_name)
40
+ #
41
+ # TODO: handle the subdomain DNS record already existing
35
42
 
36
43
  describe_operation( "create Route 53 entry '#{bucket_name}'" ) do
37
44
  Route53Dns.new( config.aws_creds ).add_s3_record_for_bucket( bucket_name )
38
45
  end
46
+
47
+ rescue Microstatic::Config::MissingEnvVar
48
+ raise Thor::Error.new($!)
39
49
  end
40
50
 
51
+ desc "rakefile <BUCKET_NAME>", "create a simple Rakefile that will deploy to the specified bucket"
52
+ def rakefile( bucket_name = false )
53
+ bucket_name ||= guess_bucket_name
54
+ # TODO: check if Rakefile already exists
55
+ template( "Rakefile.erb", "Rakefile", :bucket_name => bucket_name )
56
+ end
57
+
58
+
41
59
  private
42
60
 
43
61
  def guess_bucket_name
@@ -46,6 +64,8 @@ module Microstatic
46
64
 
47
65
  def subdomain_for( app_name )
48
66
  "#{app_name}.#{config.site_name}"
67
+ rescue Microstatic::Config::MissingEnvVar
68
+ raise Thor::Error.new($!)
49
69
  end
50
70
 
51
71
  def inferred_app_name
@@ -1,5 +1,8 @@
1
1
  module Microstatic
2
2
  class Config
3
+ class MissingEnvVar < RuntimeError
4
+ end
5
+
3
6
  def self.automagic
4
7
  #in the future this'll try to create a config based on
5
8
  #various diff. files, in priority order?
@@ -7,7 +10,7 @@ module Microstatic
7
10
  end
8
11
 
9
12
  def site_name
10
- ENV.fetch('MICROSTATIC_SITE_NAME')
13
+ env_var('MICROSTATIC_SITE_NAME')
11
14
  end
12
15
 
13
16
  def aws_creds
@@ -18,11 +21,17 @@ module Microstatic
18
21
  end
19
22
 
20
23
  def aws_access_key_id
21
- ENV.fetch('AWS_ACCESS_KEY_ID')
24
+ env_var('AWS_ACCESS_KEY_ID')
22
25
  end
23
26
 
24
27
  def aws_secret_access_key
25
- ENV.fetch('AWS_SECRET_ACCESS_KEY')
28
+ env_var('AWS_SECRET_ACCESS_KEY')
29
+ end
30
+
31
+ private
32
+
33
+ def env_var(key)
34
+ ENV.fetch(key) { raise MissingEnvVar.new("you must set the #{key} environment variable") }
26
35
  end
27
36
  end
28
37
  end
@@ -1,3 +1,3 @@
1
1
  module Microstatic
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -0,0 +1,7 @@
1
+ require 'microstatic/rake'
2
+
3
+ desc "deploy to <%=config[:bucket_name]%>"
4
+ Microstatic::Rake.s3_deploy_task(:deploy) do |task|
5
+ task.source_dir = File.expand_path("../public",__FILE__)
6
+ task.bucket_name = "<%=config[:bucket_name]%>"
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: microstatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-22 00:00:00.000000000 Z
12
+ date: 2014-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
@@ -156,6 +156,7 @@ files:
156
156
  - spec/integration/fixtures/subdir/subsubdir/deep.txt
157
157
  - spec/integration/spec_helper.rb
158
158
  - spec/integration/upload_to_test_bucket_spec.rb
159
+ - templates/Rakefile.erb
159
160
  homepage: https://github.com/moredip/microstatic
160
161
  licenses: []
161
162
  post_install_message:
@@ -170,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
171
  version: '0'
171
172
  segments:
172
173
  - 0
173
- hash: 3071074031925254256
174
+ hash: 4513272615813989365
174
175
  required_rubygems_version: !ruby/object:Gem::Requirement
175
176
  none: false
176
177
  requirements:
@@ -179,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
180
  version: '0'
180
181
  segments:
181
182
  - 0
182
- hash: 3071074031925254256
183
+ hash: 4513272615813989365
183
184
  requirements: []
184
185
  rubyforge_project:
185
186
  rubygems_version: 1.8.25