Sha256: da96f60908ed275ddd9d875f2aa31ee5792f55a5eaf831aefa2f1410d76f4f1a

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

#!/usr/bin/env ruby

require File.dirname(__FILE__) + "/../vendor/trollop"

opts = Trollop::options do
  banner "Usage: #{$0} [options] PROJECT_NAME"
  
  opt :public, "Use the public twitter maven repo"  
  opt :namespace, "Use something besides com.twitter", :type => :string
end


if ARGV.length < 1 
  Trollop::die "PROJECT_NAME is required"
  exit 1
end

class String
  def camelize(first_letter_in_uppercase = false)
    if first_letter_in_uppercase
      gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
    else
      self[0].chr.downcase + camelize(self)[1..-1]
    end
  end    
end

def gsub_birds(haystack, name, namespace)
  haystack.
    gsub("BirdName", name).
    gsub("birdname", name.downcase).
    gsub("birdName", name.camelize).
    gsub("com.twitter", namespace).
    gsub("com/twitter", namespace.gsub(".", "/"))
end

require "erb"
require "fileutils"
include FileUtils

project_name = ARGV.pop.camelize(true)
is_public = opts[:public]
namespace = opts[:namespace] || "com.twitter"

root = File.expand_path(File.dirname(__FILE__) + "/../lib/template")

Dir["#{root}/**/*"].select{|path| File.file?(path)}.each do |path|
  relative = path.sub("#{root}/", "")
  content = File.read(path)
  template = ERB.new(content, nil, nil, "@output")
  target_path = gsub_birds(relative, project_name, namespace).sub(/\.erb$/, '')
  if File.exists?(target_path) && !$overwrite_all
    print "File exists `#{relative}`, replace? ([Y]es, [N]o, [A]ll, [Q]uit)"
    $stdout.flush
    case STDIN.gets
    when /^y/i: # continue
    when /^n/i: next
    when /^a/i: $overwrite_all = true
    when /^q/i: exit(2)
    else
      retry
    end
  end
  puts "writing #{target_path}"
  mkdir_p(File.dirname(target_path))
  File.open(target_path, "w") {|f| f.print(gsub_birds(template.result(binding), project_name, namespace)) }
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scala-bootstrapper-0.3.0 bin/scala-bootstrapper