#!/usr/bin/env ruby require 'optparse' require 'fileutils' CONFIG_DIR = 'application/configs' stages = [] OptionParser.new do |opts| opts.banner = "Usage: #{File.basename($0)} [path]" opts.on("-m [stage1,stage2]", "--multistage [stage1,stage2]", Array, "Uses multistage configuration") do |stges| stages = stges end opts.on("-h", "--help", "Displays this help info") do puts opts exit 0 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 capify, 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 files = { "Capfile" => unindent(<<-FILE), require 'rubygems' require 'zend-framework-deploy' load '#{CONFIG_DIR}/deploy' FILE "#{CONFIG_DIR}/deploy.rb" => 'set :application, "set your application name here" set :repository, "set your repository location here" set :deploy_to, "set path where to deploy application" set :zf_path, "set Zend Framework (remote) installation path here" set :scm, :subversion # Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none` role :web, "your web-server goes here" # Your HTTP server, Apache/etc '} # multistage patch unless stages.empty? files["#{CONFIG_DIR}/deploy.rb"] << <<-MULTI # multistage setup, see https://boxpanel.bluebox.net/public/the_vault/index.php/Capistrano_Multi_Stage_Instructions set :default_stage, "#{stages.first}" set :stages, %w(#{stages.join(' ')}) require 'capistrano/ext/multistage' MULTI files.merge!( stages.inject({}) do |hash, file| hash["#{CONFIG_DIR}/deploy/" + file + '.rb'] = "# #{file} stage configuration goes here\n" hash end ) puts "Multistage configuration selected, remember to install capistrano-ext gem with '[sudo] gem install capistrano-ext'" end # hints to use other gems to improve capistrano experience files["#{CONFIG_DIR}/deploy.rb"] << <<-HINTS # gem install capistrano-tags to enable tag and branches deploying # require 'capistrano-tags' # gem install capistrano_colors to colorize capistano output # require 'capistrano_colors' HINTS base = ARGV.shift 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] zf-capified!"