Class: AwsSamYarnBuilder::Package
- Inherits:
-
Object
- Object
- AwsSamYarnBuilder::Package
- Defined in:
- lib/aws_sam_yarn_builder/package.rb
Defined Under Namespace
Classes: Dependency
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #build(output_name, output, tmp_directory) ⇒ Object
- #dependencies ⇒ Object
- #has_sam_prebuild_script? ⇒ Boolean
-
#initialize(path, contents) ⇒ Package
constructor
A new instance of Package.
- #name ⇒ Object
- #org? ⇒ Boolean
- #pack(output) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(path, contents) ⇒ Package
44 45 46 47 |
# File 'lib/aws_sam_yarn_builder/package.rb', line 44 def initialize(path, contents) self.path = path self.contents = contents.with_indifferent_access end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
119 120 121 |
# File 'lib/aws_sam_yarn_builder/package.rb', line 119 def path @path end |
Class Method Details
.extract_from_file!(file_path) ⇒ Object
40 41 42 |
# File 'lib/aws_sam_yarn_builder/package.rb', line 40 def self.extract_from_file!(file_path) new file_path, JSON.parse(File.read(file_path)) end |
Instance Method Details
#build(output_name, output, tmp_directory) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/aws_sam_yarn_builder/package.rb', line 93 def build(output_name, output, tmp_directory) tmp_package_path = File.join(tmp_directory, name) yarn_lock_path = File.join(base_path, "yarn.lock") FileUtils.cp yarn_lock_path, tmp_package_path Dir.chdir tmp_package_path do puts "Yarn Installing for #{name}" execute_command("yarn install --ignore-scripts --production --pure-lockfile") end deploy_package_path = File.join(output, output_name) FileUtils.rm_rf deploy_package_path FileUtils.mv tmp_package_path, deploy_package_path FileUtils.rm_rf File.join(deploy_package_path, "node_modules", "@types") package_json_path = File.join(deploy_package_path, "package.json") File.open(package_json_path, "w+") do |file| file << JSON.pretty_generate(contents) end end |
#dependencies ⇒ Object
61 62 63 |
# File 'lib/aws_sam_yarn_builder/package.rb', line 61 def dependencies @dependencies ||= contents[:dependencies].map { |name, version| Dependency.new(self, name, version) } end |
#has_sam_prebuild_script? ⇒ Boolean
65 66 67 |
# File 'lib/aws_sam_yarn_builder/package.rb', line 65 def has_sam_prebuild_script? contents[:scripts].present? && contents[:scripts]["sam:prebuild"].present? end |
#name ⇒ Object
49 50 51 |
# File 'lib/aws_sam_yarn_builder/package.rb', line 49 def name contents[:name] end |
#org? ⇒ Boolean
57 58 59 |
# File 'lib/aws_sam_yarn_builder/package.rb', line 57 def org? name.include?("/") end |
#pack(output) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/aws_sam_yarn_builder/package.rb', line 69 def pack(output) change_to_directory do execute_command("yarn run sam:prebuild") if has_sam_prebuild_script? execute_command("yarn pack") end FileUtils.mv packaged_tarball_path, output Dir.chdir output do execute_command("tar zxvf #{packed_tarball_name}") FileUtils.mkdir_p name File.rename "package", name FileUtils.rm packed_tarball_name end package_json_path = File.join(output, name, "package.json") File.open(package_json_path, "w+") do |file| file << JSON.pretty_generate(overrite_local_dependencies) end end |
#version ⇒ Object
53 54 55 |
# File 'lib/aws_sam_yarn_builder/package.rb', line 53 def version contents[:version] end |