Class: Wooget::Paket

Inherits:
Object
  • Object
show all
Defined in:
lib/wooget/paket.rb

Constant Summary collapse

@@paket_path =
File.expand_path(File.join(__FILE__, "..", "third_party", "paket.exe"))
@@unity3d_path =
File.expand_path(File.join(__FILE__, "..", "third_party", "paket.unity3d.exe"))

Class Method Summary collapse

Class Method Details

.env_varsObject



50
51
52
# File 'lib/wooget/paket.rb', line 50

def self.env_vars
  "USERNAME=#{Wooget.credentials[:username]} PASSWORD=#{Wooget.credentials[:password]}"
end

.execute(args) ⇒ Object



6
7
8
9
10
11
# File 'lib/wooget/paket.rb', line 6

def self.execute args
  cmd = "mono #{ @@paket_path} #{args}"
  Wooget.log.debug "Running #{cmd}"

  exec cmd
end

.install(options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/wooget/paket.rb', line 20

def self.install options={}
  options[:path] ||= Dir.pwd

  commands = ["#{env_vars} mono #{@@paket_path} install #{"--force" if options[:force]}"]
  commands << "#{env_vars} mono #{@@unity3d_path} install" if Util.is_a_unity_project_dir(options[:path])

  commands.each do |cmd|
    reason, exitstatus = Util.run_cmd(cmd, options[:path]) { |log| Wooget.no_status_log log }
    unless exitstatus == 0
      Wooget.log.error "Install failed:\n #{reason}"
      break
    end
  end
end

.installed?(project_path, package) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
# File 'lib/wooget/paket.rb', line 54

def self.installed? project_path, package
  abort "Not a valid paket dir - #{project_path}" unless Util.is_a_unity_project_dir(project_path) or Util.is_a_wooget_package_dir(project_path)

  lock_file = File.join(project_path, "paket.lock")
  return false unless File.exists? lock_file

  File.open(lock_file).read.lines.any? { |l| l =~ /\s*#{package}\s+/ }
end

.pack(options) ⇒ Object



70
71
72
73
# File 'lib/wooget/paket.rb', line 70

def self.pack options
  pack_cmd = "#{env_vars} mono #{@@paket_path} pack output #{options[:output]} version #{options[:version]} releaseNotes \"#{options[:release_notes]}\""
  Util.run_cmd(pack_cmd, options[:path] || Dir.pwd) { |log| Wooget.no_status_log log }
end

.push(auth, url, package) ⇒ Object



75
76
77
78
# File 'lib/wooget/paket.rb', line 75

def self.push auth, url, package
  push_cmd = "#{env_vars} nugetkey=#{auth} mono #{@@paket_path} push url #{url} file #{package}"
  Util.run_cmd(push_cmd) { |log| Wooget.no_status_log log }
end

.should_generate_unity3d_references?(path = Dir.pwd) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
# File 'lib/wooget/paket.rb', line 63

def self.should_generate_unity3d_references? path=Dir.pwd
  #if the references file doesnt exist, or it does exist and
  # it contains the automanage tag then we can rewrite it
  auto_manage_tag = "[!automanage!]"
  !File.exists?(File.join(path, "paket.unity3d.references")) or (Util.file_contains? File.join(path, "paket.dependencies"), auto_manage_tag)
end

.unity3d_execute(args) ⇒ Object



13
14
15
16
17
18
# File 'lib/wooget/paket.rb', line 13

def self.unity3d_execute args
  cmd = "mono #{@@unity3d_path} #{args}"
  Wooget.log.debug "Running #{cmd}"

  exec cmd
end

.update(package = nil, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/wooget/paket.rb', line 35

def self.update package=nil, options={}
  options[:path] ||= Dir.pwd

  commands = ["#{env_vars} mono #{@@paket_path} update #{"nuget #{package}" if package} #{"--force" if options[:force]}"]
  commands << "#{env_vars} mono #{@@unity3d_path} install" if Util.is_a_unity_project_dir(options[:path])

  commands.each do |cmd|
    reason, exitstatus = Util.run_cmd(cmd, options[:path]) { |log| Wooget.no_status_log log }
    unless exitstatus == 0
      Wooget.log.error "Update failed:\n #{reason}"
      break
    end
  end
end