require 'reap/manager/gem' module Reap class Manager # Remove packages. def clobber_packages(options=nil) options = configure_options(options, 'package') store = 'pkg' packages = glob(File.join(store, '*')) packages.each do |path| rm_r(path) puts "Removed #{path}" unless dryrun? end end # General pack command. def package(options=nil) packopts = configure_options(options, 'package') formats = packopts['formats'] || ['zip'] formats = [formats].flatten puts formats.each do |format| send("package_#{format}", options) puts end end # Routes to $gem_package. def package_gem(options=nil) gem_package(options) end # Create a Tar'd Gzip package. def package_tgz(options=nil) status "Creating .tgz package" options = configure_options(options, 'package-tgz', 'package') package = metadata.clone package.update(options) abort "No name" unless package.name abort "No version" unless package.version store = 'pkg' #package.package_directory fname = package.stage_name files = package.filelist stage = File.join(store, fname) pfile = stage + ".tgz" unless out_of_date?(pfile, *files) or force? report_package_already_built(pfile) return end rm_r(stage) if File.exist?(stage) # remove old stage stage(stage, files) # make new stage package_manifest(stage) # generate stage manifest if dryrun? status "tar -cxf #{fname}.tgz" else file = nil cd(store) do file = tgz(fname) # FIXME: Prefer .tgz as extensions. end transfer(file, store) report_package_built(file) end end # Create Zip package. def package_zip(options=nil) status "Creating .zip package" options = configure_options(options, 'package-zip', 'package') package = metadata.clone package.update(options) abort "No name" unless package.name abort "No version" unless package.version store = 'pkg' #package.package_directory fname = package.stage_name files = package.filelist stage = File.join(store, fname) pfile = stage + ".zip" unless out_of_date?(pfile, *files) or force? report_package_already_built(pfile) return end rm_r(stage) if File.exist?(stage) # remove old stage stage(stage, files) # make new stage package_manifest(stage) # generate manifest if dryrun? status "zip -r #{fname}.zip ." else file = nil cd(store) do file = zip(fname) end transfer(file, store) report_package_built(file) end end # Create off-line documentation package. # # FIXME: package_docs is not yet ready for use. def package_docs(options=nil) options = configure_options(options, 'package-doc') dir = options['dir'] || 'doc' name = options['name'] || metadata.name ver = options['version'] || metadata.version cd(dir) do zip "-czhvf #{name}-docs-#{ver}.zip *" end end private # Transfer package file to storage location. def transfer(file, store) # move to store, unless already there dest = File.join(store, File.basename(file)) dest = File.expand_path(dest) mv(file, store) unless file == dest end # Generate manifest. def package_manifest(dir) return if dryrun? Dir.chdir(dir) do files = Dir['**/*'] rm('MANIFEST') if File.exist?('MANIFEST') File.open('MANIFEST', 'w') do |f| f << files.join("\n") end end end # Report that a package has been built. # FIXME: will type, name and version always be right? def report_package_built(file) file = File.basename(file) type = File.extname(file) name = file[0...file.rindex('-')] vers = file[file.rindex('-')+1..-1].chomp(type) puts " Successfully built #{type}" puts " Name: #{name}" puts " Version: #{vers}" puts " File: #{file}" end # Report that a package has been built. # FIXME: will type, name and version always be right? def report_package_already_built(file) file = File.basename(file) type = File.extname(file) name = file[0...file.rindex('-')] vers = file[file.rindex('-')+1..-1].chomp(type) puts " Package #{file} is already current." #puts " Name: #{name}" #puts " Version: #{vers}" #puts " File: #{file}" end end end # # Build packages. # # TODO Move this to Manager ? # # def generate_packages # package_files = formats.collect do |format| # #format = clean_type(format) # say '' if format == 'gem' # FIXME This is here b/c Gems outputs on it's own. # file = create_package(format) # unless dryrun? or (format == 'gem') # report_package_built(format, file) if file # end # file # end # report_packaging_complete(package_files.size) # end # # # Create package. # # def create_package(type) # package.format = type # # builder_class = FormatBuilder.registry[type] # builder = builder_class.new(package, stage_directory, options) # file = builder.build # # transfer(file) unless dryrun? # # return file # end # # # Report that packaging is complete. # # def report_packaging_complete(size) # say "\nSuccessfully built #{size} packages at #{store}/." # end