Last active
August 29, 2015 14:01
-
-
Save danielpclark/8dfcdd7ac63149323bbc to your computer and use it in GitHub Desktop.
Rename Rails Project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Rename Rails Project (File: rename_rails) | |
# Copyright 6ft Dan(TM) / MIT License | |
# Check the config/application.rb for capital usage in project name by model OldProjectName | |
# Usage: rename_rails OldProjectName NewAwesomeName | |
require 'fileutils' | |
# Replace string instances of project name | |
`grep -lR #{ARGV[0]} | xargs sed -i 's/#{ARGV[0]}/#{ARGV[1]}/g'` | |
`grep -lR #{ARGV[0].downcase} | xargs sed -i 's/#{ARGV[0].downcase}/#{ARGV[1].downcase}/g'` | |
# Rename Rails directory if it exists | |
if File.directory?(ARGV[0]) | |
`mv #{ARGV[0]} #{ARGV[1]}` | |
drc = ARGV[1] | |
elsif File.directory?(ARGV[0].downcase) | |
`mv #{ARGV[0].downcase} #{ARGV[1]}` | |
drc = ARGV[1] | |
end | |
# Delete temporary files (helps prevent errors) | |
drc ||= '' | |
if ['cache','pids','sessions','sockets'].all? { | |
|direc| File.directory?(File.join(drc,'tmp', direc)) } | |
FileUtils.rm_rf(File.join(drc,'tmp')) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment