Way back in the day, source control was so clunky and frustrating (or non-existent), that sometimes the easiest way to share code was to zip it up and send it over email to your fellow developer. There are tons of source control options now, all quite mature and most very easy to use.
However (heh), every now and again you need to package up your files in a “zip” or some other archive form for including in a set of final deliverables, or to transfer them to someone who doesn’t use (or even understand) source control. In those cases, I’ve often gone through and manually ensured that I don’t include items that I don’t want to (local db configs, for example) in the final archive. Then I was working on a ruby gem and realized that the package task is absolutely perfect for this (and makes “zipping stuff up” a breeze).
I prefer git, and will generally create a local repo even if I’m not pushing to centralized server or sharing code with anyone. So this little snippet is a bit git-specific, but it should be easy to convert for other scm’s. Anyways, if what you want in your archive is what you store in git (which is likely how you have things set up already), then just do this:
1 2 3 4 5 6 | require 'rake/packagetask' Rake::PackageTask.new("myfile", "0.1.0") do |p| p.need_zip = true p.package_files = `git ls-files`.split(/\n/) end |
You can see at line three I pretty much use an arbitrary version number, since it’s rake you could extract a revision or another identifier if need be. Then you can zip ‘er all up with “rake package” or “rake repackage” — and bring back some of that old-school “no-scm” vibe…
cheers
{ 0 comments }