Sha256: 7ede5f3d0f67d1caaa35f23abf94c3f6e68f0ccfd0a5c7a9b47585b47dc855ee

Contents?: true

Size: 2 KB

Versions: 5

Compression:

Stored size: 2 KB

Contents

#!/usr/bin/env ruby

require 'optparse'
require 'fileutils'

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

  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 derpify, 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 didify."
end

def unindent(string)
  indentation = string[/\A\s*/]
  string.strip.gsub(/^#{indentation}/, "")
end

dirname = File.basename(File.expand_path(ARGV[0]))
source = File.expand_path(File.dirname(__FILE__)) + "/../templates/"

files = {
  "Capfile" => unindent(<<-FILE),
    require 'rubygems'
    require 'derpy'
    load 'config/deploy'
  FILE

  "config/deploy.rb" => File.read(source + "deploy.rb").gsub('[sitename]',dirname),
  "config/deploy/staging.rb" => File.read(source + "staging.rb").gsub('[sitename]',dirname),
  "config/deploy/production.rb" => File.read(source + "production.rb").gsub('[sitename]',dirname)
}

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_p(File.dirname(file))
    end
    puts "[add] writing '#{file}'"
    File.open(file, "w") { |f| f.write(content) }
  end
end

puts "[done] derpified!"

puts ""
puts 'After editing your config files just run: "derpy deploy:cold" to setup from scratch.'
puts 'After that you can do incremental updates with: "derpy deploy".'

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
derpy-2.0.5 bin/derpify
derpy-2.0.4 bin/derpify
derpy-2.0.3 bin/derpify
derpy-2.0.1 bin/derpify
derpy-2.0.0 bin/derpify