aws_sam_yarn_builder 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +41 -0
- data/README.md +81 -0
- data/Rakefile +12 -0
- data/aws_sam_yarn_builder.gemspec +27 -0
- data/bin/sam-build-yarn +9 -0
- data/lib/aws_sam_yarn_builder.rb +14 -0
- data/lib/aws_sam_yarn_builder/build.rb +71 -0
- data/lib/aws_sam_yarn_builder/option_parser.rb +17 -0
- data/lib/aws_sam_yarn_builder/package.rb +179 -0
- data/lib/aws_sam_yarn_builder/template.rb +72 -0
- data/lib/aws_sam_yarn_builder/version.rb +3 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 84a6ff9a256e1732ea9e35fbe0797cb6acc7182513adf75398170d2ac35958b3
|
4
|
+
data.tar.gz: 5d60e78270fd623c4c5d7bff2d972a1e3a5457634e651c5a60cceb65c2ed8110
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 04b422bbcc7c58b4020bb0a1d4698c7811c78ac1b71086702f874865e2e920ba3e496ee41b1a65f89b79865fecc128c55521069cd02f54daf1780242e0f905c5
|
7
|
+
data.tar.gz: e5f56b438c8a09b61330368a87c43a8d5604adf9c3cdbb3da67bcc0f4a8b1c704afccf0804f9656bae6460405807b3d1ccb067e166f9563dd17ffe8b7293d6c9
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at eallam@icloud.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
aws_sam_yarn_builder (0.1.1)
|
5
|
+
activesupport (~> 5.2.2)
|
6
|
+
slop (~> 4.6.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (5.2.2)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
coderay (1.1.2)
|
17
|
+
concurrent-ruby (1.1.4)
|
18
|
+
i18n (1.4.0)
|
19
|
+
concurrent-ruby (~> 1.0)
|
20
|
+
method_source (0.9.2)
|
21
|
+
minitest (5.11.3)
|
22
|
+
pry (0.12.2)
|
23
|
+
coderay (~> 1.1.0)
|
24
|
+
method_source (~> 0.9.0)
|
25
|
+
rake (10.5.0)
|
26
|
+
slop (4.6.2)
|
27
|
+
thread_safe (0.3.6)
|
28
|
+
tzinfo (1.2.5)
|
29
|
+
thread_safe (~> 0.1)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
ruby
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
aws_sam_yarn_builder!
|
36
|
+
bundler (~> 1.16)
|
37
|
+
pry
|
38
|
+
rake (~> 10.0)
|
39
|
+
|
40
|
+
BUNDLED WITH
|
41
|
+
1.16.1
|
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# sam-build-yarn
|
2
|
+
|
3
|
+
Command to build AWS SAM apps that use nodejs with `yarn`.
|
4
|
+
|
5
|
+
Supports local file dependencies, and matches the `sam build` command output so you can use the `sam-build-yarn` command as a replacement for `sam build`.
|
6
|
+
|
7
|
+
**NOTE:** Currently _does not_ support building using a container e.g. `sam build --container`
|
8
|
+
|
9
|
+
## New Features:
|
10
|
+
|
11
|
+
- Specify commands to run before building in a function by including a `sam:prebuild` script in the `package.json`.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
AWS SAM Yarn Builder is a ruby gem, so you can install it using this command:
|
16
|
+
|
17
|
+
$ gem install aws-sam-yarn-builder
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Execute:
|
22
|
+
|
23
|
+
$ sam-build-yarn
|
24
|
+
|
25
|
+
Assumes the template is located at the root of the project and named `template.yml`. You can specify a different template file like so:
|
26
|
+
|
27
|
+
$ sam-build-yarn --template-file ./samapp.yaml
|
28
|
+
|
29
|
+
### Example App
|
30
|
+
|
31
|
+
For an example of how this builder can work, here is the layout of an example SAM app with a single function (under `src`) with a local nodejs dependency (under `lib`):
|
32
|
+
|
33
|
+
```
|
34
|
+
sam-app/
|
35
|
+
├── lib/
|
36
|
+
│ └── local-dependency/
|
37
|
+
│ ├── index.js
|
38
|
+
│ └── package.json
|
39
|
+
└── src/
|
40
|
+
└── hello-world/
|
41
|
+
├── app.js
|
42
|
+
└── package.json
|
43
|
+
```
|
44
|
+
|
45
|
+
The `hello-world/package.json` contents look like this:
|
46
|
+
|
47
|
+
```json
|
48
|
+
{
|
49
|
+
"name": "hello_world",
|
50
|
+
"version": "1.0.0",
|
51
|
+
"dependencies": {
|
52
|
+
"local-file-dependency": "file:../../lib/local-file-dependency"
|
53
|
+
}
|
54
|
+
}
|
55
|
+
```
|
56
|
+
|
57
|
+
With this layout and setup, you would not be able to build with `sam build` because it doesn't support dependencies that point to a file on the local filesystem.
|
58
|
+
|
59
|
+
`sam-build-yarn` will inspect all function package.json files for local file dependencies and "stage" them into the build before building each function, overriding the dependencies path in the package.json to point to the staged one.
|
60
|
+
|
61
|
+
The result of the build after running `sam-build-yarn` matches that of `sam build`:
|
62
|
+
|
63
|
+
```
|
64
|
+
sam-app/
|
65
|
+
├── .aws-sam/
|
66
|
+
│ └── build/
|
67
|
+
│ ├── HelloWorldFunction/
|
68
|
+
│ │ ├── node_modules/
|
69
|
+
│ │ ├── app.js
|
70
|
+
│ │ ├── package.json
|
71
|
+
│ │ └── yarn.lock
|
72
|
+
│ └── template.yaml
|
73
|
+
├── lib/
|
74
|
+
│ └── local-dependency/
|
75
|
+
│ ├── index.js
|
76
|
+
│ └── package.json
|
77
|
+
└── src/
|
78
|
+
└── hello-world/
|
79
|
+
├── app.js
|
80
|
+
└── package.json
|
81
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "aws_sam_yarn_builder/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "aws_sam_yarn_builder"
|
7
|
+
spec.version = AwsSamYarnBuilder::VERSION
|
8
|
+
spec.authors = ["Eric Allam"]
|
9
|
+
spec.email = ["eallam@icloud.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{A command line program to produce builds for aws-sam-cli for nodejs/yarn projects}
|
12
|
+
spec.description = %q{A command line program to produce builds for aws-sam-cli for nodejs/yarn projects}
|
13
|
+
spec.homepage = "https://github.com/ericallam/aws-sam-yarn-builder"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
|
19
|
+
spec.bindir = "bin"
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
|
22
|
+
spec.add_dependency "slop", "~> 4.6.0"
|
23
|
+
spec.add_dependency "activesupport", "~> 5.2.2"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
end
|
data/bin/sam-build-yarn
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
require "active_support/dependencies/autoload"
|
3
|
+
require "active_support/core_ext/hash"
|
4
|
+
require "fileutils"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module AwsSamYarnBuilder
|
8
|
+
extend ActiveSupport::Autoload
|
9
|
+
|
10
|
+
autoload :Package
|
11
|
+
autoload :Build
|
12
|
+
autoload :Template
|
13
|
+
autoload :OptionParser
|
14
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module AwsSamYarnBuilder
|
2
|
+
class Build
|
3
|
+
def initialize(options = {})
|
4
|
+
self.options = options
|
5
|
+
end
|
6
|
+
|
7
|
+
def build!
|
8
|
+
reset_build_dir!
|
9
|
+
reset_staging_dir!
|
10
|
+
|
11
|
+
local_dependencies = template.function_resources.map do |function|
|
12
|
+
get_local_file_dependencies(function)
|
13
|
+
end.flatten.uniq.compact
|
14
|
+
|
15
|
+
local_dependencies.each do |d|
|
16
|
+
d.pack destination_staging_dir
|
17
|
+
end
|
18
|
+
|
19
|
+
template.function_resources.each do |function|
|
20
|
+
package = package_from_function(function)
|
21
|
+
|
22
|
+
package.pack destination_staging_dir
|
23
|
+
package.build function.name, destination_dir, destination_staging_dir
|
24
|
+
end
|
25
|
+
|
26
|
+
template.write_to_output(destination_dir)
|
27
|
+
|
28
|
+
FileUtils.rm_rf(destination_staging_dir)
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
attr_accessor :options
|
34
|
+
|
35
|
+
def get_local_file_dependencies(function)
|
36
|
+
package = package_from_function(function)
|
37
|
+
|
38
|
+
package.dependencies.select(&:local?)
|
39
|
+
end
|
40
|
+
|
41
|
+
def package_from_function(function)
|
42
|
+
Package.extract_from_file! File.join(File.expand_path(File.join(template_base_dir, function.path)), "package.json")
|
43
|
+
end
|
44
|
+
|
45
|
+
def reset_staging_dir!
|
46
|
+
FileUtils.rm_rf(destination_staging_dir)
|
47
|
+
FileUtils.mkdir_p(destination_staging_dir)
|
48
|
+
end
|
49
|
+
|
50
|
+
def reset_build_dir!
|
51
|
+
FileUtils.rm_rf(destination_dir)
|
52
|
+
FileUtils.mkdir_p(destination_dir)
|
53
|
+
end
|
54
|
+
|
55
|
+
def destination_dir
|
56
|
+
@destination_dir ||= File.join(File.expand_path(options[:destination]), "build")
|
57
|
+
end
|
58
|
+
|
59
|
+
def destination_staging_dir
|
60
|
+
@destination_staging_dir ||= File.join(File.expand_path(options[:destination]), "tmp")
|
61
|
+
end
|
62
|
+
|
63
|
+
def template
|
64
|
+
@template ||= Template.extract_from_file!(File.expand_path(options[:template_file]))
|
65
|
+
end
|
66
|
+
|
67
|
+
def template_base_dir
|
68
|
+
File.dirname(File.expand_path(options[:template_file]))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "slop"
|
2
|
+
|
3
|
+
module AwsSamYarnBuilder
|
4
|
+
module OptionParser
|
5
|
+
def self.parse!
|
6
|
+
Slop.parse do |o|
|
7
|
+
o.string "-d", "--destination", "path to use for the output of the build process", default: "./.aws-sam"
|
8
|
+
o.string "-t", "--template-file", "path to the SAM template file", default: "./template.yml"
|
9
|
+
|
10
|
+
o.on "--help" do
|
11
|
+
puts o
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
module AwsSamYarnBuilder
|
2
|
+
class Package
|
3
|
+
class Dependency
|
4
|
+
def initialize(parent, name, version)
|
5
|
+
self.parent = parent
|
6
|
+
self.name = name
|
7
|
+
self.version = version
|
8
|
+
end
|
9
|
+
|
10
|
+
def local?
|
11
|
+
version.start_with? "file:"
|
12
|
+
end
|
13
|
+
|
14
|
+
def pack(output)
|
15
|
+
Package.extract_from_file!(File.join(local_path, "package.json")).pack(output)
|
16
|
+
end
|
17
|
+
|
18
|
+
def ==(o)
|
19
|
+
o.class == self.class && o.name == name
|
20
|
+
end
|
21
|
+
|
22
|
+
def hash
|
23
|
+
name.hash
|
24
|
+
end
|
25
|
+
|
26
|
+
alias_method :eql?, :==
|
27
|
+
|
28
|
+
attr_reader :name, :version
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
attr_writer :version, :name
|
33
|
+
attr_accessor :parent
|
34
|
+
|
35
|
+
def local_path
|
36
|
+
File.expand_path(File.join(File.dirname(parent.path), version.gsub(/^file:/, "")))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.extract_from_file!(file_path)
|
41
|
+
new file_path, JSON.parse(File.read(file_path))
|
42
|
+
end
|
43
|
+
|
44
|
+
def initialize(path, contents)
|
45
|
+
self.path = path
|
46
|
+
self.contents = contents.with_indifferent_access
|
47
|
+
end
|
48
|
+
|
49
|
+
def name
|
50
|
+
contents[:name]
|
51
|
+
end
|
52
|
+
|
53
|
+
def version
|
54
|
+
contents[:version]
|
55
|
+
end
|
56
|
+
|
57
|
+
def dependencies
|
58
|
+
@dependencies ||= contents[:dependencies].map { |name, version| Dependency.new(self, name, version) }
|
59
|
+
end
|
60
|
+
|
61
|
+
def dev_dependencies
|
62
|
+
@dev_dependencies ||= contents[:devDependencies].map { |name, version| Dependency.new(self, name, version) }
|
63
|
+
end
|
64
|
+
|
65
|
+
def has_sam_prebuild_script?
|
66
|
+
contents[:scripts].present? && contents[:scripts]["sam:prebuild"].present?
|
67
|
+
end
|
68
|
+
|
69
|
+
def pack(output)
|
70
|
+
change_to_directory do
|
71
|
+
execute_command("yarn run sam:prebuild") if has_sam_prebuild_script?
|
72
|
+
execute_command("yarn pack")
|
73
|
+
end
|
74
|
+
|
75
|
+
FileUtils.mv packaged_tarball_path, output
|
76
|
+
|
77
|
+
Dir.chdir output do
|
78
|
+
execute_command("tar zxvf #{packed_tarball_name}")
|
79
|
+
|
80
|
+
FileUtils.mkdir_p name
|
81
|
+
File.rename "package", name
|
82
|
+
|
83
|
+
FileUtils.rm packed_tarball_name
|
84
|
+
end
|
85
|
+
|
86
|
+
package_json_path = File.join(output, name, "package.json")
|
87
|
+
|
88
|
+
File.open(package_json_path, "w+") do |file|
|
89
|
+
file << JSON.pretty_generate(overrite_local_dependencies)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def build(output_name, output, tmp_directory)
|
94
|
+
tmp_package_path = File.join(tmp_directory, name)
|
95
|
+
|
96
|
+
yarn_lock_path = File.join(base_path, "yarn.lock")
|
97
|
+
|
98
|
+
FileUtils.cp yarn_lock_path, tmp_package_path
|
99
|
+
|
100
|
+
Dir.chdir tmp_package_path do
|
101
|
+
puts "Yarn Installing for #{name}"
|
102
|
+
|
103
|
+
execute_command("yarn install --ignore-scripts --production --pure-lockfile")
|
104
|
+
end
|
105
|
+
|
106
|
+
deploy_package_path = File.join(output, output_name)
|
107
|
+
|
108
|
+
FileUtils.rm_rf deploy_package_path
|
109
|
+
FileUtils.mv tmp_package_path, deploy_package_path
|
110
|
+
|
111
|
+
package_json_path = File.join(deploy_package_path, "package.json")
|
112
|
+
|
113
|
+
File.open(package_json_path, "w+") do |file|
|
114
|
+
file << JSON.pretty_generate(contents)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
attr_reader :path
|
119
|
+
|
120
|
+
protected
|
121
|
+
|
122
|
+
attr_accessor :contents
|
123
|
+
attr_writer :path
|
124
|
+
|
125
|
+
def overrite_local_dependencies
|
126
|
+
result = Marshal.load(Marshal.dump(contents))
|
127
|
+
|
128
|
+
result[:dependencies] = contents[:dependencies].inject({}) do |deps, (name, version)|
|
129
|
+
if version.start_with?("file:")
|
130
|
+
deps[name] = "file:../#{name}"
|
131
|
+
else
|
132
|
+
deps[name] = version
|
133
|
+
end
|
134
|
+
|
135
|
+
deps
|
136
|
+
end
|
137
|
+
|
138
|
+
result[:devDependencies] = contents[:devDependencies].inject({}) do |deps, (name, version)|
|
139
|
+
if version.start_with?("file:")
|
140
|
+
deps[name] = "file:../#{name}"
|
141
|
+
else
|
142
|
+
deps[name] = version
|
143
|
+
end
|
144
|
+
|
145
|
+
deps
|
146
|
+
end
|
147
|
+
|
148
|
+
result
|
149
|
+
end
|
150
|
+
|
151
|
+
def change_to_directory(&block)
|
152
|
+
Dir.chdir base_path, &block
|
153
|
+
end
|
154
|
+
|
155
|
+
def base_path
|
156
|
+
File.dirname(path)
|
157
|
+
end
|
158
|
+
|
159
|
+
def packaged_tarball_path
|
160
|
+
File.join(base_path, packed_tarball_name)
|
161
|
+
end
|
162
|
+
|
163
|
+
def packed_tarball_name
|
164
|
+
packed_name + ".tgz"
|
165
|
+
end
|
166
|
+
|
167
|
+
def packed_name
|
168
|
+
[name.gsub(/\//, "-").gsub(/@/, ""), "v#{version}"].join("-")
|
169
|
+
end
|
170
|
+
|
171
|
+
def execute_command(command)
|
172
|
+
if !command
|
173
|
+
return
|
174
|
+
end
|
175
|
+
|
176
|
+
system command
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module AwsSamYarnBuilder
|
4
|
+
class Template
|
5
|
+
class FunctionResource
|
6
|
+
def initialize(name, properties = {})
|
7
|
+
self.name = name
|
8
|
+
self.properties = properties
|
9
|
+
end
|
10
|
+
|
11
|
+
def path
|
12
|
+
properties["CodeUri"]
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :name
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
attr_accessor :properties
|
20
|
+
attr_writer :name
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.extract_from_file!(file_path)
|
24
|
+
new file_path, File.read(file_path)
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(path, contents)
|
28
|
+
self.path = path
|
29
|
+
self.contents = contents
|
30
|
+
end
|
31
|
+
|
32
|
+
def write_to_output(output)
|
33
|
+
File.open(File.join(output, "template.yaml"), "w+") do |file|
|
34
|
+
file << YAML.dump(document_with_transformed_function_paths)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def transform
|
39
|
+
document["Transform"]
|
40
|
+
end
|
41
|
+
|
42
|
+
def function_resources
|
43
|
+
@function_resources ||= raw_function_resources.map { |name, options| FunctionResource.new(name, options["Properties"]) }
|
44
|
+
end
|
45
|
+
|
46
|
+
protected
|
47
|
+
|
48
|
+
attr_accessor :contents, :path
|
49
|
+
|
50
|
+
def document
|
51
|
+
@document ||= YAML.load(contents)
|
52
|
+
end
|
53
|
+
|
54
|
+
def document_with_transformed_function_paths
|
55
|
+
transformed_document = Marshal.load(Marshal.dump(document))
|
56
|
+
|
57
|
+
raw_function_resources.each do |name, resource|
|
58
|
+
transformed_document["Resources"][name]["Properties"]["CodeUri"] = "./#{name}"
|
59
|
+
end
|
60
|
+
|
61
|
+
transformed_document
|
62
|
+
end
|
63
|
+
|
64
|
+
def raw_resources
|
65
|
+
document["Resources"]
|
66
|
+
end
|
67
|
+
|
68
|
+
def raw_function_resources
|
69
|
+
raw_resources.select { |name, options| options["Type"] == "AWS::Serverless::Function" }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aws_sam_yarn_builder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Allam
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: slop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.6.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.6.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.2.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.2.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: A command line program to produce builds for aws-sam-cli for nodejs/yarn
|
70
|
+
projects
|
71
|
+
email:
|
72
|
+
- eallam@icloud.com
|
73
|
+
executables:
|
74
|
+
- sam-build-yarn
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- aws_sam_yarn_builder.gemspec
|
85
|
+
- bin/sam-build-yarn
|
86
|
+
- lib/aws_sam_yarn_builder.rb
|
87
|
+
- lib/aws_sam_yarn_builder/build.rb
|
88
|
+
- lib/aws_sam_yarn_builder/option_parser.rb
|
89
|
+
- lib/aws_sam_yarn_builder/package.rb
|
90
|
+
- lib/aws_sam_yarn_builder/template.rb
|
91
|
+
- lib/aws_sam_yarn_builder/version.rb
|
92
|
+
homepage: https://github.com/ericallam/aws-sam-yarn-builder
|
93
|
+
licenses: []
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.7.6
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: A command line program to produce builds for aws-sam-cli for nodejs/yarn
|
115
|
+
projects
|
116
|
+
test_files: []
|