Over a million developers have joined DZone.

Init Rails Project Script

·
From http://vinsol.com/2007/02/08/ruby-script-for-creating-new-rails-project-and-initial-svn-import-with-ignoringremoving-logother-files


require 'fileutils'

puts  "########################################"
puts  "This script creates a new rails project and do the initial svn import with ignoring/deleting files from subversion"
puts  "Please send your feedback to Akhil Bansal"
puts  "I have tested this script and it works great on my system."
puts  ""
puts  ""
puts  "                    ###### ATTENTION #######"
puts  ""
puts  ""
puts  "Use this script at your own risk, if your computer explodes its not my fault :-) "
puts  "#######################################"

puts  "Enter svn username: "
username = gets.strip
puts  "Enter the svn url: "
svn_url =gets.strip

puts  "Enter Rails Application Path:(eg: /home/akhil/ror): "
app_path = gets.strip
puts  "Enter Application Name: "
app_name = gets.strip

puts  "######################################"


puts  "Please verify the following variables: "
puts  "Svn Username: #{username}"
puts  "Svn URL: #{svn_url}"
puts  "Application Path: #{app_path}"
puts  "Application name: #{app_name}"

puts  "Proceed (y/n)"
proceed = gets
proceed = proceed.strip.upcase
if proceed == 'N' 
    puts  "Terminating..."
    exit 0
elsif proceed == 'Y' 
    if system("rails -v")
      s="/"
    elsif   system("rails.cmd -v")
      s="\\"
    else
        puts "Cannot find rails. Terminating..."
        exit 0
    end    
    app_root=app_path+s+ app_name
    
    puts  "Generating rails project: (#{app_root})"
    if system("rails #{app_root}")
      s="/"
    elsif   system("rails.cmd #{app_root}")
      s="\\"
    else
        puts "Cannot create rails project. Terminating..."
        exit 0
    end    
    
    puts  "SVNinitial import: "
    system("svn import #{app_root} #{svn_url} -m \"Initial Import\" --username #{username}")
   
    FileUtils.remove_dir(app_root, true)
   
    puts  "Checking out from svn: "

    system("svn checkout #{svn_url} #{app_root}")
    FileUtils.cd(app_root, :verbose => true)
    
    puts  "Removing all log files from SVN"
    system("svn remove log"+s+"*")
    puts  "commiting..."
    system("svn commit -m \"removing all log files from subversion \" ")
    puts  "Ignoring all log files under log dir"
    system("svn propset svn:ignore \"*.log\" log"+s)
    puts  "Updating and commiting..."
    system("svn update log"+s)
    system("svn commit -m \"Ignoring all files in "+s+"log"+s+" ending in .log \" ")
    puts  "Removing tmp directory from SVN"
    system("svn remove tmp"+s)
    puts  "commiting..."
    system("svn commit -m \"removing the temp directory from subversion \" ")
    puts  "Ignoring tmp dir"
    system("svn propset svn:ignore \"*\" tmp"+s)
    puts  "Updating and commiting again...."

    system("svn update tmp"+s)
    system("svn commit -m \"Ignore the whole tmp"+s+" directory, might not work on subdirectories? \" ")
    puts  "Moving database.yml to database.example"
    system("svn move config"+s+"database.yml config"+s+"database.example")
    puts  "commiting..."
    system("svn commit -m \"Moving database.yml to database.example to provide a template for anyone who checks out the code \" ")
    puts  "Ignoring database.yml , updating and commiting..."
    system("svn propset svn:ignore 'database.yml' config"+s)
    system("svn update config"+s)
    system("svn commit -m \"Ignoring database.yml\" ")
    puts  "Finished."

else
    puts  "Unknown Input. Terminating..."
	exit 0
end
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}