Class: AwsSamYarnBuilder::Build

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_sam_yarn_builder/build.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Build

Returns a new instance of Build.



3
4
5
# File 'lib/aws_sam_yarn_builder/build.rb', line 3

def initialize(options = {})
  self.options = options
end

Instance Method Details

#build!Object



7
8
9
10
11
12
13
14
15
# File 'lib/aws_sam_yarn_builder/build.rb', line 7

def build!
  if options[:function]
    build_single_function!
  elsif options[:unified_package]
    build_unified_template!
  else
    build_full_template!
  end
end

#build_full_template!Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/aws_sam_yarn_builder/build.rb', line 37

def build_full_template!
  reset_build_dir!
  reset_staging_dir!

  local_dependencies = template.function_resources.map do |function|
    get_local_file_dependencies(function)
  end.flatten.uniq.compact

  local_dependencies.each do |d|
    d.pack destination_staging_dir
  end

  template.function_resources.each do |function|
    package = package_from_function(function)

    package.pack destination_staging_dir
    package.build function.name, destination_dir, destination_staging_dir
  end

  template.write_to_output(destination_dir, template_base_dir)

  FileUtils.rm_rf(destination_staging_dir)
end

#build_single_function!Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/aws_sam_yarn_builder/build.rb', line 61

def build_single_function!
  reset_build_dir!
  reset_staging_dir!

  function_resource = template.function_resource_by_logical_id(options[:function])

  if function_resource
    local_dependencies = get_local_file_dependencies(function_resource).flatten.uniq.compact

    local_dependencies.each do |d|
      d.pack destination_staging_dir
    end

    package = package_from_function(function_resource)

    package.pack destination_staging_dir
    package.build function_resource.name, destination_dir, destination_staging_dir

    FileUtils.rm_rf(destination_staging_dir)
  end
end

#build_unified_template!Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/aws_sam_yarn_builder/build.rb', line 17

def build_unified_template!
  reset_build_dir!
  reset_staging_dir!

  package = package_from_global_path(template.function_globals.path)

  local_dependencies = package.dependencies.select(&:local?).flatten.uniq.compact

  local_dependencies.each do |d|
    d.pack destination_staging_dir
  end

  package.pack destination_staging_dir
  package.build "UnifiedPackage", destination_dir, destination_staging_dir

  template.write_to_output(destination_dir, template_base_dir, true)

  FileUtils.rm_rf(destination_staging_dir)
end