Module: Packmule

Defined in:
lib/packmule/version.rb,
lib/packmule.rb,
lib/packmule/cli.rb,
lib/packmule/archiver.rb

Overview

PackMule Copyright © 2012 Nirix All Rights Reserved

PackMule is released under the GNU GPL v3 only license.

Defined Under Namespace

Modules: Archiver, CLI

Constant Summary collapse

VERSION =
"0.4.0"

Class Method Summary collapse

Class Method Details

.pack(options) ⇒ Object

The center of Packmule, takes the Packfile and packs the directory according to the options.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/packmule.rb', line 17

def self.pack(options)
  require 'yaml'
  require 'fileutils'
  require 'tmpdir'

  tempdir = Dir.mktmpdir

  # Read the Packfile and exit if it doesn't exist
  puts "Reading the Packfile..."
  begin
    config = YAML::load_file('./Packfile')
  rescue
    puts "No Packfile found, stopping"
    exit;
  end

  # Options
  opt = {
    :filename => config['package-as'] + (options[:version] != '' ? '-' + options[:version] : ''),
    :formats  => config['formats'],
    :version  => options[:version],
    :ignore   => config['ignore'],
    :commands => config['commands']
  }

  # Any commands?
  if opt[:commands]
    opt[:commands].each do |c|
      # Change to tempdir and run
      `cd #{tempdir}; #{c}`
    end
  end

  # Clone directory
  ::FileUtils.cp_r './', tempdir

  # Remove ignored files and directories
  opt[:ignore].each do |badness|
    ::FileUtils.rm_rf Dir["#{tempdir}/#{badness}"], :secure => true
  end

  # Archive the directory
  Packmule::Archiver.create({
    :filename => opt[:filename],
    :formats  => opt[:formats],
    :ignore   => opt[:ignore],
    :dir      => tempdir
  })

  # Cleanup
  FileUtils.remove_entry_secure tempdir

  puts "Packaging complete"
  exit
end