Making rake package zip on Windows by jgn on Monday, October 1, 2007 in Uncategorized

If you want to do rake package on Windows and specify need_zip = true, it's a bit of a problem because Windows doesn't come with a command-line zip program. To be sure, one could always install Cygwin.

I've seen blogs talking about hacking rake, but that seems really gross.

Another option is to clone as much of zip as rake needs (not much!) with the rubyzip gem. After doing gem install rubyzip, the following seems to be acceptable for rake (haven't tested this a lot; feel free to fix my code :-)). This little bit of code -- simulating what command-line zip does -- seems to be a sort of missing link in the documentation and tests for rubyzip. It's easy, but not super-obvious from the docs.

> require 'zip/zip'
> recursive = false
> if ARGV[0] == '-r'
> recursive = true
> ARGV.shift
> end
> archive = ARGV.shift
> ARGV.each do |arg|
> files = recursive ? Dir[arg + '/**/*.*'] : [arg]
> files.each do |f|
>, Zip::ZipFile::CREATE) do |z|
> z.add( f, f)
> puts " adding #{f}"
> end
> end
> end
> ```
 And then in your Rakefile.rb, something like:

> desc "Zip up project"
>"#{PROJECT}-#{USER}", "1.0.0") do |p|
> p.need_zip = true
> p.zip_command = 'ruby ../myzip.rb'
> p.package_files.include("./**/*")
> p.package_files.exclude("./**/*.svn")
> p.package_files.exclude("./doc")
> p.package_files.exclude("./pkg")
> end
> ```
comments powered by Disqus