forked from bborn/communityengine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
community_engine_setup_template.rb
executable file
·111 lines (88 loc) · 2.97 KB
/
community_engine_setup_template.rb
1
2
3
4
5
6
7
8
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
35
36
37
38
39
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Utility methods
def say(message)
puts " [CE SETUP] #{message} \n "
end
def checkout_ce_branch(branch)
inside 'vendor/plugins/community_engine' do
say "Checking out the #{branch} branch"
run "git checkout --track -b #{branch} origin/#{branch}"
end
end
def modify_environment_files
in_root do
say "Modifying your environment.rb and environments files to work with CE"
sentinel = "require File.join(File.dirname(__FILE__), 'boot')"
desert_require = "require 'desert'"
gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
"#{match}\n #{desert_require}\n"
end
ce_plugins_config = <<EOF
config.plugins = [:community_engine, :white_list, :all]
config.plugin_paths += ["\#{RAILS_ROOT}/vendor/plugins/community_engine/plugins"]
EOF
environment ce_plugins_config
ce_boot_line = "\n require \"\#{RAILS_ROOT}/vendor/plugins/community_engine/config/boot.rb\""
append_file 'config/environment.rb', ce_boot_line
say "Modifying environment files ..."
['development', 'test'].each do |env|
environment "\nAPP_URL = \"http://localhost:3000\"", :env => env
end
app_url = ask("Please enter the url where you plan to deploy this app (use 'example.com' for now if you don't know yet):")
environment "\nAPP_URL = \"http://#{app_url}\"", :env => 'production'
end
end
def add_application_yml(name)
file("config/application.yml") do
"community_name: #{name}"
end
end
# CommunityEngine Setup
ce_git_repo = "git://github.com/bborn/communityengine.git"
app_name = ask("Please enter the application's name: ")
# Delete unnecessary files
run "rm public/index.html"
# Set up git repository
git :init
git :add => '.'
# Set up .gitignore files
run "touch tmp/.gitignore log/.gitignore vendor/.gitignore"
run %{find . -type d -empty | grep -v "vendor" | grep -v ".git" | grep -v "tmp" | xargs -I xxx touch xxx/.gitignore}
file '.gitignore', <<-END
.DS_Store
log/*.log
tmp/**/*
config/database.yml
db/*.sqlite3
END
# Install all gems
gem 'desert', :lib => 'desert'
gem 'rmagick', :lib => 'RMagick'
gem 'hpricot', :lib => 'hpricot'
gem 'htmlentities', :lib => 'htmlentities'
gem 'haml', :lib => 'haml'
gem "aws-s3", :lib => "aws/s3"
gem 'calendar_date_select'
gem 'ri_cal'
gem 'authlogic'
gem 'searchlogic'
gem 'rakismet'
rake('gems:install', :sudo => true)
plugin 'community_engine', :git => ce_git_repo, :submodule => true
# Initialize submodules
git :submodule => "init"
git :submodule => "update"
checkout_ce_branch('edge')
# Add CE routes
route "map.routes_from_plugin :community_engine"
modify_environment_files
add_application_yml(app_name)
generate :plugin_migration
rake('db:create:all')
rake('db:migrate')
capify!
# Commit all work so far to the repository
git :add => '.'
git :commit => "-a -m 'Initial commit'"
# Success!
puts "SUCCESS!"
puts "Next, you should probably run `rake test` and `rake community_engine:test` and make sure all tests pass. "