weewar.com corner

Sake Task for Creating Rails Project + SVN Support

Posted by railsbros_dirk
on Wednesday, February 06

I put together a Sake task which allows you to create a Rails project and put directly into subversion. And the clue with this is, it asks you interactivly where your SVN repository lives and which name your project should have. Knowing this the tasks creates a directory in your Subversion repository named after your project, sets up directories for trunk, branches and tags. After that checking the trunk out as your project name, creates the Rails stubs in it, add everything but the stuff you usually don't want to see under version control (log files, temporary directory and the database.yml). In the end everything is where it belongs and you can start coding.

Hope you enjoy this little task.

  
namespace :rails do
  desc "Sake Tasks for setting up a new Rails project and put into SVN"
  task :setup_with_svn do
    puts "-----------------------------------------------"
    puts "| Setting up a Rails Project with SVN Support |"
    puts "-----------------------------------------------"
    puts
    puts "Enter your SVN URL where the Rails projects will live ..."
    print "> "
    svn_url = STDIN.gets.strip!
    puts "Enter the name of the Rails project ..."
    print "> "
    project_name = STDIN.gets.strip!
    system("svn mkdir #{svn_url}/#{project_name} -m 'ADDED - project to dir'")
    system("svn mkdir #{svn_url}/#{project_name}/trunk -m 'ADDED - initial trunk directory for the project'")
    system("svn mkdir #{svn_url}/#{project_name}/branches -m 'ADDED - initial branches directory for the project'")
    system("svn mkdir #{svn_url}/#{project_name}/tags -m 'ADDED - initial tags directory for the project'")
    system("svn checkout #{svn_url}/#{project_name}/trunk #{project_name}")
    system("cd #{project_name}; rails .")
    system("mv #{project_name}/config/database.{yml,yml.sample}")
    system("rm -rf #{project_name}/log/*")
    system("rm -rf #{project_name}/tmp/*")
    system("cd #{project_name}; svn status | grep '^? \+\(log\|tmp\)' -v | sed -e 's/? *//' | sed -e 's/ / /g' | xargs svn add")
    system("svn propset svn:ignore '*' #{project_name}/log/")
    system("svn propset svn:ignore '*' #{project_name}/tmp/")
    system("svn propset svn:ignore 'database.yml' #{project_name}/config/")
    system("cd #{project_name}; svn commit -m 'ADDED - the Rails Project has been added and all files that are not needed in the repo have been ignored.'")
    system("cp #{project_name}/config/database.{yml.sample,yml}")
    system("cd #{project_name}; rake tmp:create")
    system("touch #{project_name}/log/{development,test,server,production}.log")
  end
end
  

You can grep the tasks via pastie or via our SVN with the sake -i <URL> command.