-
Notifications
You must be signed in to change notification settings - Fork 217
/
capifony
executable file
·132 lines (106 loc) · 3.91 KB
/
capifony
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env ruby
require 'optparse'
require 'fileutils'
symfony_version = nil
symfony_app_path = 'app'
capifony_version = '2.2.7'
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 # 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('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 # 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_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!"