Permalink
faa5bef Apr 29, 2015
@willdurand @everzet @smoove @pylebecq @mtrias @matteosister
executable file 131 lines (104 sloc) 3.73 KB
#!/usr/bin/env ruby
require 'optparse'
require 'fileutils'
symfony_version = nil
symfony_app_path = 'app'
capifony_version = '2.8.7.dev'
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("-v", "--version", "") do
puts "capifony v#{capifony_version}"
exit 0
end
opts.on("-s", "--symfony VERSION", "Capify specific symfony version (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 capifony."
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
require 'capifony_symfony2'
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, :primary => true # This may be the same as your `Web` server
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('capifony_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, :primary => true # This may be the same as your `Web` server
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_p(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!"