Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

126 lines (102 sloc) 3.964 kb
#!/usr/bin/env ruby
require 'optparse'
require 'fileutils'
symfony_version = nil
symfony_app_path = 'app'
OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename($0)} [path]"
opts.on("-h", "--help", "Displays this help info") do
puts opts
exit 0
end
opts.on("-s", "--symfony VERSION", "Capify specific symfony verion (1|2)") do |version|
symfony_version = version.to_i
end
opts.on("-p", "--app NAME", "Specify app name (folder) to capify") do |path|
symfony_app_path = path
end
begin
opts.parse!(ARGV)
rescue OptionParser::ParseError => e
warn e.message
puts opts
exit 1
end
end
if ARGV.empty?
abort "Please specify the directory to capifony, e.g. `#{File.basename($0)} .'"
elsif !File.exists?(ARGV.first)
abort "`#{ARGV.first}' does not exist."
elsif !File.directory?(ARGV.first)
abort "`#{ARGV.first}' is not a directory."
elsif ARGV.length > 1
abort "Too many arguments; please specify only the directory to capify."
end
def unindent(string)
indentation = string[/\A\s*/]
string.strip.gsub(/^#{indentation}/, "")
end
base = ARGV.shift
symfony_version = symfony_version || ((File.directory? File.join(base, 'config')) ? 1 : 2)
if symfony_version == 2
files = {
"Capfile" => unindent(<<-FILE),
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['vendor/**/Resources/recipes/*.rb'].each { |bundle| load(bundle) }
load Gem.find_files('symfony2.rb').first.to_s
load '#{symfony_app_path}/config/deploy'
FILE
"#{symfony_app_path}/config/deploy.rb" => unindent(<<-FILE)
set :application, "set your application name here"
set :domain, "\#{application}.com"
set :deploy_to, "/var/www/\#{domain}"
set :app_path, "#{symfony_app_path}"
set :repository, "\#{domain}:/var/repos/\#{application}.git"
set :scm, :git
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `subversion`, `mercurial`, `perforce`, or `none`
set :model_manager, "doctrine"
# Or: `propel`
role :web, domain # Your HTTP server, Apache/etc
role :app, domain # This may be the same as your `Web` server
role :db, domain, :primary => true # This is where Symfony2 migrations will run
set :keep_releases, 3
# Be more verbose by uncommenting the following line
# logger.level = Logger::MAX_LEVEL
FILE
}
else
files = {
"Capfile" => unindent(<<-FILE),
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['plugins/*/lib/recipes/*.rb'].each { |plugin| load(plugin) }
load Gem.find_files('symfony1.rb').first.to_s
load 'config/deploy'
FILE
"config/deploy.rb" => 'set :application, "set your application name here"
set :domain, "#{application}.com"
set :deploy_to, "/var/www/#{domain}"
set :repository, "#{domain}:/var/repos/#{application}.git"
set :scm, :git
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `subversion`, `mercurial`, `perforce`, or `none`
role :web, domain # Your HTTP server, Apache/etc
role :app, domain # This may be the same as your `Web` server
role :db, domain, :primary => true # This is where symfony migrations will run
set :keep_releases, 3'
}
end
files.each do |file, content|
file = File.join(base, file)
if File.exists?(file)
warn "[skip] '#{file}' already exists"
elsif File.exists?(file.downcase)
warn "[skip] '#{file.downcase}' exists, which could conflict with `#{file}'"
else
unless File.exists?(File.dirname(file))
puts "[add] making directory '#{File.dirname(file)}'"
FileUtils.mkdir(File.dirname(file))
end
puts "[add] writing '#{file}'"
File.open(file, "w") { |f| f.write(content) }
end
end
puts "[done] symfony #{symfony_version.to_s} project capifonied!"
Jump to Line
Something went wrong with that request. Please try again.