create_project
1.97 KB
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
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'rubygems'
require 'activesupport'
require 'pathname'
require 'digest/md5'
project_name = ARGV[0]
fail("Usage: #{File.basename(__FILE__)} new_project_name") unless project_name
fail("Project name must only contain [a-z0-9_]") unless project_name =~ /^[a-z0-9_]+$/
base_directory = Pathname.new(File.join(File.dirname(__FILE__), '..', '..')).realpath
project_directory = base_directory + project_name
fail("Project directory (#{project_directory}) already exists") if project_directory.exist?
template_url = "git://github.com/dancroak/heroku_suspenders.git"
changeme = "CHANGEME"
changesession = "CHANGESESSION"
def run(cmd)
puts "Running '#{cmd}'"
out = `#{cmd}`
if $? != 0
fail "Command #{cmd} failed: #$?\n#{out}"
end
out
end
def search_and_replace(file, search, replace)
if File.file?(file)
contents = File.read(file)
if contents[search]
puts "Replacing #{search} with #{replace} in #{file}"
contents.gsub!(search, replace)
File.open(file, "w") { |f| f << contents }
end
end
end
run("mkdir #{project_directory}")
Dir.chdir(project_directory) or fail("Couldn't change to #{project_directory}")
run("git init")
run("git remote add heroku_suspenders #{template_url}")
run("git pull heroku_suspenders master")
Dir.glob("#{project_directory}/**/*").each do |file|
search_and_replace(file, changeme, project_name)
end
Dir.glob("#{project_directory}/**/session_store.rb").each do |file|
datestring = Time.now.strftime("%j %U %w %A %B %d %Y %I %M %S %p %Z")
search_and_replace(file, changesession, Digest::MD5.hexdigest("#{project_name} #{datestring}"))
end
run("git commit -a -m 'New Heroku Suspenders app'")
run("rake db:migrate RAILS_ENV=development")
run("rake db:migrate RAILS_ENV=test")
run("rake db:migrate RAILS_ENV=cucumber")
puts
puts "Next: run the tests, configure Heroku, deploy!"
puts
puts "cd ../#{project_name} && rake && rake heroku:setup"