Skip to content

Instantly share code, notes, and snippets.

@samuelkadolph
Last active December 20, 2015 17:49
Show Gist options
  • Save samuelkadolph/6171589 to your computer and use it in GitHub Desktop.
Save samuelkadolph/6171589 to your computer and use it in GitHub Desktop.
def replace(path, pattern, replacement)
File.open(path, "r+") do |file|
contents = file.read
file.truncate(0)
file.pos = 0
file << contents.gsub(pattern, replacement)
end
end
run "git init"
run "git add --all"
run "git commit --message 'Initial rails application'"
log :lean, "making the app lean"
log :clean, "making the app clean"
Dir["{app,config,test}/**/*.rb", "bin/*", "Gemfile", "Rakefile"].each do |path|
replace(path, /(?<!\w)'|'(?!\w)/, '"')
replace(path, /require (?:::)?File\.expand_path\("..\/([^"]+)",\s*__FILE__\)/, "require_relative \"\\1\"")
replace(path, /^\s*#(?!!).*\n/, "")
replace(path, /\A\n+/, "")
end
replace("config.ru", /(?<!\w)'|'(?!\w)/, '"')
replace("config.ru", /require (?:::)?File\.expand_path\("..\/([^"]+)",\s*__FILE__\)/, "require File.expand_path(\"../\\1\", __FILE__)")
replace("config.ru", /^\s*#(?!!).*\n/, "")
replace("config.ru", /\A\n+/, "")
FileUtils.rm_rf("lib/assets")
File.truncate("db/seeds.rb", 0)
File.truncate("public/robots.txt", 0)
FileUtils.rm_rf("vendor")
FileUtils.mv("README.rdoc", "README.md")
File.truncate("README.md", 0)
run "git add --all"
run "git commit --message 'Lean and clean'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment