lambchop 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/bin/lambchop +1 -0
- data/lib/lambchop/client.rb +27 -10
- data/lib/lambchop/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af92c0434b1eaee3913c61dabd3c37ef13331bb9
|
4
|
+
data.tar.gz: fd47747f8ce5b91ac328f6657068ac66ada0623c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5cb59aadc02c8d4d3e4920bbf8b7019ba04be442620311ffb7cffd61ad5bb8f51826dfc105d75be7274da981199bd0f4065b6caf7dacaa91d416fcd5cd0940f
|
7
|
+
data.tar.gz: 5ea2cc893308c21336f04243d1e241742734769eeb48aa8970a19575f847e1c9f0b9387dacae01fcdcb91761a8e86ccafe5b7ae47f51d310205665b69fe39026
|
data/README.md
CHANGED
@@ -38,6 +38,7 @@ timeout: 3 # default: 3
|
|
38
38
|
memory_size: 128 # default: 128
|
39
39
|
role: arn:aws:iam::NNNNNNNNNNNN:role/lambda_exec_role
|
40
40
|
handler: test.handler
|
41
|
+
include_files: */* # default: nil
|
41
42
|
# Handler module name is filename.
|
42
43
|
# `handler:` is `index.handler` when filename is `index.js`
|
43
44
|
*/
|
@@ -179,6 +180,17 @@ START RequestId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
|
179
180
|
└── node_modules/
|
180
181
|
```
|
181
182
|
|
183
|
+
## Include extra files
|
184
|
+
|
185
|
+
```javascript
|
186
|
+
#!/usr/bin/env lambchop
|
187
|
+
/*
|
188
|
+
...
|
189
|
+
include_files: *.txt
|
190
|
+
*/
|
191
|
+
...
|
192
|
+
```
|
193
|
+
|
182
194
|
## Diff
|
183
195
|
```sh
|
184
196
|
$ lambchop-diff
|
data/bin/lambchop
CHANGED
@@ -27,6 +27,7 @@ timeout: 3 # default: 3
|
|
27
27
|
memory_size: 128 # default: 128
|
28
28
|
handler: test.handler # Module name is filename, e.g. index.js -> index.handler
|
29
29
|
role: arn:aws:iam::NNNNNNNNNNNN:role/any_lambda_exec_role
|
30
|
+
include_files: */* # default: nil
|
30
31
|
*/
|
31
32
|
EOS
|
32
33
|
exit 1
|
data/lib/lambchop/client.rb
CHANGED
@@ -21,11 +21,11 @@ class Lambchop::Client
|
|
21
21
|
config, src = Lambchop::Utils.parse_magic_comment(src)
|
22
22
|
|
23
23
|
config['function_name'] ||= File.basename(@path, '.js')
|
24
|
-
function_name = config['function_name']
|
25
|
-
|
26
24
|
config['runtime'] ||= 'nodejs'
|
25
|
+
function_name = config['function_name']
|
26
|
+
include_files = config.delete('include_files')
|
27
27
|
|
28
|
-
create_or_update_function(config, src)
|
28
|
+
create_or_update_function(config, src, include_files)
|
29
29
|
|
30
30
|
exit if @options[:detach]
|
31
31
|
|
@@ -37,10 +37,10 @@ class Lambchop::Client
|
|
37
37
|
|
38
38
|
private
|
39
39
|
|
40
|
-
def create_or_update_function(config, src)
|
40
|
+
def create_or_update_function(config, src, include_files)
|
41
41
|
params = {}
|
42
42
|
config.each {|k, v| params[k.to_sym] = v }
|
43
|
-
buf, node_modules = zip_source(src)
|
43
|
+
buf, node_modules, extra_files = zip_source(src, include_files)
|
44
44
|
|
45
45
|
begin
|
46
46
|
params[:code] = {:zip_file => buf.string}
|
@@ -61,6 +61,7 @@ class Lambchop::Client
|
|
61
61
|
raise e
|
62
62
|
end
|
63
63
|
end
|
64
|
+
|
64
65
|
resp_h = {}
|
65
66
|
|
66
67
|
[
|
@@ -80,13 +81,15 @@ class Lambchop::Client
|
|
80
81
|
|
81
82
|
$stderr.puts('Function was uploaded:')
|
82
83
|
$stderr.puts(JSON.pretty_generate(resp_h))
|
83
|
-
$stderr.puts('Node modules:')
|
84
|
-
$stderr.puts(JSON.
|
84
|
+
$stderr.puts('Node modules: ' + JSON.dump(node_modules))
|
85
|
+
$stderr.puts('Extra files: ' + JSON.dump(extra_files))
|
85
86
|
end
|
86
87
|
|
87
|
-
def zip_source(src)
|
88
|
+
def zip_source(src, include_files)
|
88
89
|
src_dir = File.dirname(@path)
|
90
|
+
script_file = File.basename(@path)
|
89
91
|
node_modules = []
|
92
|
+
extra_files = []
|
90
93
|
|
91
94
|
Dir.glob("#{src_dir}/node_modules/**/*") do |file|
|
92
95
|
if File.file?(file)
|
@@ -94,20 +97,34 @@ class Lambchop::Client
|
|
94
97
|
end
|
95
98
|
end
|
96
99
|
|
100
|
+
if include_files
|
101
|
+
Dir.glob(include_files) do |file|
|
102
|
+
next unless File.file?(file)
|
103
|
+
next if node_modules.include?(file)
|
104
|
+
next if file.sub(%r|\A#{src_dir}/|, '') == script_file
|
105
|
+
extra_files << file
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
97
109
|
buf = Zip::OutputStream.write_buffer do |out|
|
98
|
-
out.put_next_entry(
|
110
|
+
out.put_next_entry(script_file)
|
99
111
|
out.write(src)
|
100
112
|
|
101
113
|
node_modules.each do |file|
|
102
114
|
out.put_next_entry(file.sub(%r|\A#{src_dir}/|, ''))
|
103
115
|
out.write(open(file, &:read))
|
104
116
|
end
|
117
|
+
|
118
|
+
extra_files.each do |file|
|
119
|
+
out.put_next_entry(file.sub(%r|\A#{src_dir}/|, ''))
|
120
|
+
out.write(open(file, &:read))
|
121
|
+
end
|
105
122
|
end
|
106
123
|
|
107
124
|
node_modules = node_modules.map {|file|
|
108
125
|
file.sub(%r|\A#{src_dir}/|, '').split('/', 3)[1]
|
109
126
|
}.uniq.sort
|
110
127
|
|
111
|
-
[buf, node_modules]
|
128
|
+
[buf, node_modules, extra_files]
|
112
129
|
end
|
113
130
|
end
|
data/lib/lambchop/version.rb
CHANGED