Permalink
Browse files

Very close to fully functional now, just need to resolve problems wit…

…h sorting and requires.
  • Loading branch information...
1 parent 8c37c87 commit 1c657fe6d993ed8cf11e54684f5e3da38a2fe457 Michael Bleigh committed Mar 15, 2011
Showing with 83 additions and 32 deletions.
  1. +3 −2 lib/rails_wizard/recipe.rb
  2. +8 −3 lib/rails_wizard/template.rb
  3. +15 −0 recipes/git.rb
  4. +41 −9 recipes/heroku.rb
  5. +5 −10 recipes/mongohq.rb
  6. +5 −4 templates/helpers.erb
  7. +6 −4 templates/layout.erb
@@ -14,13 +14,14 @@ def self.<=>(another)
0
end
- ATTRIBUTES = %w(key args category name description template config exclusive tags run_before run_after)
+ ATTRIBUTES = %w(key args category name description template config exclusive tags run_before run_after requires)
DEFAULT_ATTRIBUTES = {
:category => 'other',
:args => [],
:tags => [],
:run_after => [],
- :run_before => []
+ :run_before => [],
+ :requires => []
}
def self.generate(key, template_or_file, attributes = {})
@@ -18,15 +18,20 @@ def render(template_name, binding = nil); self.class.render(template_name, bindi
def resolve_recipes
- recipes_with_dependencies.sort
+ @resolve_recipes ||= recipes_with_dependencies.sort
+ end
+
+ def recipe_classes
+ @recipe_classes ||= recipes.map{|r| RailsWizard::Recipe.from_mongo(r)}
end
def recipes_with_dependencies
- @recipes_with_dependencies ||= recipes
+ @recipes_with_dependencies ||= recipe_classes
added_more = false
- for recipe in recipes
+ for recipe in recipe_classes
recipe.requires.each do |requirement|
+ requirement = RailsWizard::Recipe.from_mongo(requirement)
unless @recipes_with_dependencies.include?(requirement)
@recipes_with_dependencies << requirement
added_more = true
View
@@ -0,0 +1,15 @@
+after_everything do
+ git :init
+ git :add => '.'
+ git :commit => '-m "Initial import."'
+end
+
+__END__
+
+name: Git
+description: "Provides basic Git setup for the Rails app and commits the initial repository."
+author: mbleigh
+
+exclusive: scm
+category: other
+tags: [scm]
View
@@ -1,26 +1,58 @@
-after_bundler do
- heroku_name = nil
- while heroku_name.blank? || !system("heroku create #{heroku_name}")
- heroku_name = wizard_ask("What do you want to call your app? ")
+heroku_name = app_name.gsub('_','')
+
+after_everything do
+ if config['create']
+ say_wizard "Creating Heroku app '#{heroku_name}.heroku.com'"
+ while !system("heroku create #{heroku_name}")
+ heroku_name = ask_wizard("What do you want to call your app? ")
+ end
+ end
+
+ if config['staging']
+ staging_name = "#{heroku_name}-staging"
+ say_wizard "Creating staging Heroku app '#{staging_name}.heroku.com'"
+ while !system("heroku create #{staging_name}")
+ staging_name = ask_wizard("What do you want to call your staging app?")
+ end
+ git :remote => "rm heroku"
+ git :remote => "add production git@heroku.com:#{heroku_name}.git"
+ git :remote => "add staging git@heroku.com:#{staging_name}.git"
+ say_wizard "Created branches 'production' and 'staging' for Heroku deploy."
+ end
+
+ unless config['domain'].blank?
+ run "heroku addons:add custom_domains"
+ run "heroku domains:add #{config['domain']}"
end
- git :push => "heroku master"
+ git :push => "#{config['staging'] ? 'staging' : 'heroku'} master" if config['deploy']
end
__END__
name: Heroku
-description: Create a Heroku application and instantly deploy.
+description: Create'] Heroku application and instantly deploy.
author: mbleigh
+requires: [git]
+run_after: [git]
exclusive: deployment
category: deployment
tags: [provider]
config:
- - app_name:
- prompt: "Application Name:"
- type: string
+ - create:
+ prompt: "Automatically create appname.heroku.com?"
+ type: boolean
- staging:
prompt: "Create staging app? (appname-staging.heroku.com)"
type: boolean
+ if: create
+ - domain:
+ prompt: "Specify custom domain (or leave blank):"
+ type: string
+ if: create
+ - deploy:
+ prompt: "Deploy immediately?"
+ type: boolean
+ if_recipe: git
View
@@ -1,5 +1,4 @@
if config['use_heroku']
- say_wizard 'Adding mongohq:free addon (you can always upgrade later)'
header = <<-YAML
<% if ENV['MONGOHQ_URL'] %>
@@ -14,6 +13,7 @@
YAML
after_bundler do
+ say_wizard 'Adding mongohq:free addon (you can always upgrade later)'
system 'heroku addons:add mongohq:free'
end
else
@@ -29,16 +29,11 @@
YAML
end
-if recipe? 'mongo_mapper'
- gsub_file "config/mongo.yml", /defaults:/, <<-YAML
-#{header}
-
-defaults:
-YAML
-
-
-elsif recipe? 'mongoid'
+after_bundler do
+ mongo_yml = "config/mongo#{'id' if recipe?('mongoid')}.yml"
+ prepend_file mongo_yml, header
+ inject_into_file mongo_yml, " <<: *mongohq\n", :after => "production:\n <<: *defaults\n"
end
__END__
@@ -3,10 +3,10 @@ def recipe?(name); @recipes.include?(name) end
def say_custom(tag, text); say "\033[1m\033[36m" + tag.to_s.rjust(10) + "\033[0m" + " #{text}" end
def say_recipe(name); say "\033[1m\033[36m" + "recipe".rjust(10) + "\033[0m" + " Running #{name} recipe..." end
-def say_wizard(text); say_custom('wizard', text) end
+def say_wizard(text); say_custom(@current_recipe || 'wizard', text) end
def ask_wizard(question)
- ask "\033[1m\033[30m\033[46m" + "prompt".rjust(10) + "\033[0m\033[36m" + " #{question}\033[0m"
+ ask "\033[1m\033[30m\033[46m" + (@current_recipe || "prompt").rjust(10) + "\033[0m\033[36m" + " #{question}\033[0m"
end
def yes_wizard?(question)
@@ -37,7 +37,8 @@ end
@current_recipe = nil
@after_blocks = []
-def after_bundler(&block); @after_blocks << block; end
-
+def after_bundler(&block); @after_blocks << [@current_recipe, block]; end
+@after_everything_blocks = []
+def after_everything(&block); @after_everything_blocks << [@current_recipe, block]; end
@before_configs = {}
def before_config(&block); @before_configs[@current_recipe] = block; end
View
@@ -19,22 +19,24 @@ Rails.application.config.generators do |g|
end
RUBY
-@recipes = <%= recipes.map(&:key).inspect %>
+@recipes = <%= resolve_recipes.map(&:key).inspect %>
<%= render "helpers" %>
-<% recipes.each do |recipe| %>
+<% resolve_recipes.each do |recipe| %>
<%= render 'recipe', recipe.get_binding %>
<% end %>
<% if custom_code? %># >-----------------------------[ Custom Code ]-------------------------------<
<%= custom_code %><% end %>
+@current_recipe = nil
+
# >-----------------------------[ Run Bundler ]-------------------------------<
say_wizard "Running Bundler install. This will take a while."
run 'bundle install'
say_wizard "Running after Bundler callbacks."
-@after_blocks.each{|b| b.call}
-
+@after_blocks.each{|b| @current_recipe = b[0]; b[1].call}
+@after_everything_blocks.each{|b| @current_recipe = b[0]; b[1].call}

0 comments on commit 1c657fe

Please sign in to comment.