xaases 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +24 -4
- data/lib/xaases/api.rb +14 -0
- data/lib/xaases/aws/lambda_js.rb +16 -11
- data/lib/xaases/cli/help.rb +2 -1
- data/lib/xaases/cli.rb +22 -11
- data/lib/xaases/conf.rb +17 -5
- data/lib/xaases/error.rb +3 -0
- data/lib/xaases/js/function.rb +4 -0
- data/lib/xaases/js.rb +24 -6
- data/lib/xaases/serverless/yaml.rb +14 -3
- data/lib/xaases/version.rb +1 -1
- metadata +3 -3
- data/lib/xaases/cli/init.rb +0 -5
- data/lib/xaases/function.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20c01b0ec0fd646988062e2c636f5f87e9b4d336c6e3a0a5803059c3b7dd0c72
|
4
|
+
data.tar.gz: 1f4e2ab166e2e29accc17f637830ae9869837f3d57faa7623af95255d8d1655a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba9b23891348962ca8247bba003f0495f8888bc6b6e4de67f1860ba67cf7eb10c388e88c53b66db1006d2b9b57c76a8d3e604697319933606bbd312b161fbd39
|
7
|
+
data.tar.gz: 72b3ee56ac48a105e837176eb280276d63ea3ab3be2eaa7579731530408464e682b81745b5fd5a7da55ec20f69f392f8d32cb0c6fd89f0ad05c129a432622e94
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -22,15 +22,17 @@ $ xaases init
|
|
22
22
|
|
23
23
|
is create `xaases.yml`.
|
24
24
|
|
25
|
-
### Add
|
25
|
+
### Add table
|
26
26
|
|
27
27
|
```
|
28
|
-
$ xaases
|
28
|
+
$ xaases table <name> <columns...>
|
29
29
|
```
|
30
30
|
|
31
|
+
**Memo:** DynamoDB table support columns max of count is 2.
|
32
|
+
|
31
33
|
### Deploy to AWS
|
32
34
|
|
33
|
-
|
35
|
+
Need edit `serverless.yml` with
|
34
36
|
|
35
37
|
```
|
36
38
|
provider:
|
@@ -38,7 +40,25 @@ provider:
|
|
38
40
|
region: <region>
|
39
41
|
```
|
40
42
|
|
41
|
-
|
43
|
+
And run `sls deploy` command.
|
44
|
+
|
45
|
+
### Add API
|
46
|
+
|
47
|
+
```
|
48
|
+
$ xaases api GET /
|
49
|
+
```
|
50
|
+
|
51
|
+
Created API `GET /`, add to `serverless.yml` and generate `handler.js`
|
52
|
+
|
53
|
+
Generated `handler.js` content is
|
54
|
+
|
55
|
+
```js
|
56
|
+
module.exports.root = (event, context, callback) => {
|
57
|
+
callback(null, { statusCode: 200, body: "OK." });
|
58
|
+
};
|
59
|
+
```
|
60
|
+
|
61
|
+
You can edit anything of it.
|
42
62
|
|
43
63
|
## Development
|
44
64
|
|
data/lib/xaases/api.rb
ADDED
data/lib/xaases/aws/lambda_js.rb
CHANGED
@@ -2,10 +2,13 @@ require 'xaases/js'
|
|
2
2
|
module Xaases
|
3
3
|
module Aws
|
4
4
|
class LambdaJs
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@
|
5
|
+
attr_reader :minify
|
6
|
+
|
7
|
+
def initialize(minify: true)
|
8
|
+
@minify = minify
|
9
|
+
@js = Xaases::Js.new(minify: minify)
|
10
|
+
#@js.strict!
|
11
|
+
#@js.const(aws: "require('aws-sdk')")
|
9
12
|
end
|
10
13
|
|
11
14
|
def use_dynamo!
|
@@ -13,27 +16,29 @@ module Xaases
|
|
13
16
|
end
|
14
17
|
|
15
18
|
def export(name, content)
|
16
|
-
f = Xaases::Js::Function.new(:eve, :ctx, :cb)
|
19
|
+
#f = Xaases::Js::Function.new(:eve, :ctx, :cb)
|
20
|
+
f = Xaases::Js::Function.new(:event, :context, :callback)
|
21
|
+
f.content = content
|
17
22
|
@js.export(name, f)
|
18
23
|
end
|
19
24
|
|
20
25
|
def res(status, content)
|
21
26
|
#err = err ? err : 'null'
|
22
|
-
body = Xaases::Js.new.hash('statusCode' => status, 'body' => content)
|
27
|
+
body = Xaases::Js.new(minify: minify).hash('statusCode' => status, 'body' => content)
|
23
28
|
@js.call :callback, 'null', body
|
24
29
|
end
|
25
30
|
|
26
|
-
def
|
31
|
+
def dynamo_put(table, data, handler)
|
27
32
|
params = {
|
28
33
|
'TableName' => "'#{table}'",
|
29
|
-
'Item' => Xaases::Js.new.hash(data)
|
34
|
+
'Item' => Xaases::Js.new(minify: minify).hash(data)
|
30
35
|
}
|
31
|
-
params_js = Xaases::Js.new.hash(params)
|
32
|
-
@js.call
|
36
|
+
params_js = Xaases::Js.new(minify: minify).hash(params)
|
37
|
+
@js.call 'dyn.put', params_js, handler
|
33
38
|
end
|
34
39
|
|
35
40
|
def render
|
36
|
-
@js
|
41
|
+
@js.render
|
37
42
|
end
|
38
43
|
end
|
39
44
|
end
|
data/lib/xaases/cli/help.rb
CHANGED
data/lib/xaases/cli.rb
CHANGED
@@ -1,30 +1,41 @@
|
|
1
1
|
require 'xaases/cli/color'
|
2
|
+
require 'xaases/error'
|
2
3
|
require 'xaases/conf'
|
3
4
|
require 'xaases/serverless'
|
4
|
-
require 'xaases/aws/dynamodb'
|
5
5
|
|
6
6
|
cmd = ARGV.first
|
7
7
|
options = ARGV.slice(1..-1)
|
8
8
|
|
9
9
|
begin
|
10
10
|
case cmd
|
11
|
-
when '
|
12
|
-
|
11
|
+
when 'table'
|
12
|
+
require 'xaases/aws/dynamodb'
|
13
|
+
Xaases.table *options
|
13
14
|
sls = Xaases::Serverless::Yaml.new('serverless.yml', 'xaases')
|
14
|
-
|
15
|
-
sls.add_resource
|
15
|
+
key = options.first + 'DynamoDbTable'
|
16
|
+
sls.add_resource key, Xaases::Aws::Dynamodb.new(*options).to_hash
|
16
17
|
sls.write
|
17
|
-
|
18
|
-
when '
|
18
|
+
|
19
|
+
when 'api'
|
20
|
+
require 'xaases/aws/lambda_js'
|
21
|
+
Xaases.api *options
|
19
22
|
sls = Xaases::Serverless::Yaml.new('serverless.yml', 'xaases')
|
20
|
-
sls.add_function *options
|
23
|
+
name = sls.add_function *options
|
21
24
|
sls.write
|
22
|
-
|
25
|
+
|
26
|
+
res = Xaases::Aws::LambdaJs.new(minify: false)
|
27
|
+
res.res(200, '"OK."')
|
28
|
+
|
29
|
+
js = Xaases::Aws::LambdaJs.new(minify: false)
|
30
|
+
js.export name, res.render
|
31
|
+
f = File.open 'handler.js', 'a'
|
32
|
+
f.write js.render
|
33
|
+
|
23
34
|
when 'init', 'touch'
|
24
|
-
|
35
|
+
Xaases.init
|
25
36
|
else
|
26
37
|
require 'xaases/cli/help'
|
27
38
|
end
|
28
|
-
rescue => e
|
39
|
+
rescue Xaases::Error => e
|
29
40
|
Xaases::Color.failure e.message
|
30
41
|
end
|
data/lib/xaases/conf.rb
CHANGED
@@ -3,11 +3,16 @@ require 'yaml'
|
|
3
3
|
module Xaases
|
4
4
|
CONF_NAME = NAME + '.yml'
|
5
5
|
|
6
|
+
def self.init
|
7
|
+
YAML.dump({ 'Tables' => {}, 'APIs' => {} }, File.open(CONF_NAME, 'w'))
|
8
|
+
Color.warn "Created #{CONF_NAME}"
|
9
|
+
end
|
10
|
+
|
6
11
|
def self.load
|
7
12
|
begin
|
8
13
|
@@config = YAML.load_file(CONF_NAME) || {}
|
9
14
|
rescue Errno::ENOENT
|
10
|
-
raise "Require '#{CONF_NAME}' file, you need run at 'xaases init' command."
|
15
|
+
raise Error.new("Require '#{CONF_NAME}' file, you need run at 'xaases init' command.")
|
11
16
|
end
|
12
17
|
end
|
13
18
|
|
@@ -21,10 +26,17 @@ module Xaases
|
|
21
26
|
dump
|
22
27
|
end
|
23
28
|
|
24
|
-
def self.
|
25
|
-
edit do |
|
26
|
-
puts Color.yellow "Add #{name}"
|
27
|
-
|
29
|
+
def self.table name, *columns
|
30
|
+
edit do |config|
|
31
|
+
puts Color.yellow "Add table #{name}"
|
32
|
+
config['Tables'][name] = columns
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.api verb, path
|
37
|
+
edit do |config|
|
38
|
+
puts Color.yellow "Add API: #{verb} #{path}"
|
39
|
+
config['APIs'][verb + ' ' + path] = []
|
28
40
|
end
|
29
41
|
end
|
30
42
|
end
|
data/lib/xaases/error.rb
ADDED
data/lib/xaases/js/function.rb
CHANGED
data/lib/xaases/js.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'xaases/js/function'
|
2
2
|
module Xaases
|
3
3
|
class Js
|
4
|
-
|
4
|
+
attr_reader :minify
|
5
|
+
|
6
|
+
def initialize(minify: true)
|
7
|
+
@minify = minify
|
5
8
|
@s = ''
|
6
9
|
end
|
7
10
|
|
@@ -16,13 +19,23 @@ module Xaases
|
|
16
19
|
end
|
17
20
|
|
18
21
|
def call(name, *params)
|
19
|
-
|
22
|
+
if minify
|
23
|
+
@s += "#{name}(#{params.join(',')});"
|
24
|
+
else
|
25
|
+
@s += "#{name}(#{params.join(', ')});"
|
26
|
+
end
|
20
27
|
end
|
21
28
|
|
22
29
|
def hash(data)
|
23
|
-
|
24
|
-
|
25
|
-
|
30
|
+
if minify
|
31
|
+
@s += '{' + data.map do |key, value|
|
32
|
+
key.to_s + ':' + value.to_s
|
33
|
+
end.join(',') + '}'
|
34
|
+
else
|
35
|
+
@s += '{ ' + data.map do |key, value|
|
36
|
+
key.to_s + ': ' + value.to_s
|
37
|
+
end.join(', ') + ' }'
|
38
|
+
end
|
26
39
|
end
|
27
40
|
|
28
41
|
def if(*conditions)
|
@@ -40,7 +53,12 @@ module Xaases
|
|
40
53
|
end
|
41
54
|
|
42
55
|
def export(name, f)
|
43
|
-
|
56
|
+
if minify
|
57
|
+
@s += "module.exports.#{name}=(#{f.params.join(',')})=>{#{f.render}};"
|
58
|
+
else
|
59
|
+
content = f.render.split("\n").join("\n ")
|
60
|
+
@s += "module.exports.#{name} = (#{f.params.join(', ')}) => {\n #{content}\n};\n"
|
61
|
+
end
|
44
62
|
end
|
45
63
|
|
46
64
|
def render
|
@@ -27,11 +27,22 @@ module Xaases
|
|
27
27
|
@data['resources']['Resources'][name] = rs
|
28
28
|
end
|
29
29
|
|
30
|
-
def add_function(
|
31
|
-
|
32
|
-
|
30
|
+
def add_function(method, path)
|
31
|
+
method = method.downcase
|
32
|
+
file = 'index'
|
33
|
+
name = path.sub(/\A\//, '').sub(/\//, '_')
|
34
|
+
name = nil if name == ''
|
35
|
+
|
36
|
+
name = ['create', name].compact.join('_') if method == 'post'
|
37
|
+
name = ['update', name].compact.join('_') if method == 'put'
|
38
|
+
name = ['delete', name].compact.join('_') if method == 'delete'
|
39
|
+
|
40
|
+
name = 'root' if method == 'get' && !name
|
41
|
+
@data['functions'][name] = {
|
42
|
+
'handler' => "handler.#{name}",
|
33
43
|
'events' => [{ 'http' => { 'path' => path, 'method' => method }}]
|
34
44
|
}
|
45
|
+
name
|
35
46
|
end
|
36
47
|
|
37
48
|
def write
|
data/lib/xaases/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xaases
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- myun2
|
@@ -76,15 +76,15 @@ files:
|
|
76
76
|
- bin/setup
|
77
77
|
- exe/xaases
|
78
78
|
- lib/xaases.rb
|
79
|
+
- lib/xaases/api.rb
|
79
80
|
- lib/xaases/aws.rb
|
80
81
|
- lib/xaases/aws/dynamodb.rb
|
81
82
|
- lib/xaases/aws/lambda_js.rb
|
82
83
|
- lib/xaases/cli.rb
|
83
84
|
- lib/xaases/cli/color.rb
|
84
85
|
- lib/xaases/cli/help.rb
|
85
|
-
- lib/xaases/cli/init.rb
|
86
86
|
- lib/xaases/conf.rb
|
87
|
-
- lib/xaases/
|
87
|
+
- lib/xaases/error.rb
|
88
88
|
- lib/xaases/js.rb
|
89
89
|
- lib/xaases/js/function.rb
|
90
90
|
- lib/xaases/name.rb
|
data/lib/xaases/cli/init.rb
DELETED
data/lib/xaases/function.rb
DELETED