Class: Snapshot::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/snapshot/builder.rb

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



4
5
6
# File 'lib/snapshot/builder.rb', line 4

def initialize
  @build_dir = SnapshotConfig.shared_instance.build_dir || '/tmp/snapshot'
end

Instance Method Details

#build_app(clean: true) ⇒ Object



8
9
10
11
12
13
14
15
16
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
# File 'lib/snapshot/builder.rb', line 8

def build_app(clean: true)
  FileUtils.rm_rf(@build_dir) if clean

  command = SnapshotConfig.shared_instance.build_command

  if not command
    # That's the default case, user did not provide a custom build_command
    raise "Could not find project. Please pass the path to your project using 'project_path'.".red unless SnapshotConfig.shared_instance.project_path
    command = generate_build_command(clean: clean)
  end

  Helper.log.info "Building project '#{SnapshotConfig.shared_instance.project_name}' - this might take some time...".green
  Helper.log.debug command.yellow

  all_lines = []

  PTY.spawn(command) do |stdin, stdout, pid|
    stdin.each do |line|
      all_lines << line
      begin
        parse_build_line(line) if line.length > 2
      rescue => ex
        Helper.log.fatal all_lines.join("\n")
        raise ex
      end
    end
    Process.wait(pid)
  end
  # Exit status for build command, should be 0 if build succeeded
  cmdstatus = $?.exitstatus

  if cmdstatus == 0 || all_lines.join('\n').include?('** BUILD SUCCEEDED **')
    Helper.log.info "BUILD SUCCEEDED".green
    return true
  else
    Helper.log.info(all_lines.join(' '))
    raise "Looks like the build was not successful."
  end
end