hecks 0.1.4.rc → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/bin/hecks +1 -1
  3. data/bin/hecks-package +65 -0
  4. data/bin/hecks_console +6 -4
  5. data/bin/hecks_serverless +6 -0
  6. data/lib/cli/build.rb +1 -0
  7. data/lib/cli/command_runner.rb +20 -17
  8. data/lib/cli/console.rb +2 -0
  9. data/lib/cli/generate.rb +6 -4
  10. data/lib/cli/hecks-cli.rb +27 -0
  11. data/lib/cli/test.rb +10 -9
  12. data/lib/console/commands.rb +5 -6
  13. data/lib/console/hecks-console.rb +1 -0
  14. data/lib/hecks.rb +5 -6
  15. data/lib/packager/README.md +0 -0
  16. data/lib/packager/app_runner.rb +21 -0
  17. data/lib/packager/args.rb +26 -0
  18. data/lib/packager/compatibility/fixnum.rb +6 -0
  19. data/lib/packager/hecks.rb +39 -0
  20. data/lib/packager/query_runner.rb +21 -0
  21. data/lib/packager/resources/Dockerfile +11 -0
  22. data/lib/packager/resources/app_binary +7 -0
  23. data/lib/packager/{templates/binary_package/build/resources/bundle/config → resources/bundle_config} +0 -0
  24. data/lib/packager/resources/traveling-ruby-20150715-2.2.2-linux-x86_64.tar.gz +0 -0
  25. data/lib/packager/resources/traveling-ruby-20150715-2.2.2-osx.tar.gz +0 -0
  26. data/lib/serverless/Domain +32 -0
  27. data/lib/serverless/cli.rb +75 -0
  28. data/lib/serverless/resources/command_name.js +5 -0
  29. data/lib/serverless/resources/environment.js +7 -0
  30. data/lib/serverless/resources/handler.js.tt +28 -0
  31. data/lib/serverless/resources/run_binary.js +22 -0
  32. data/lib/serverless/resources/serverless.yml +20 -0
  33. metadata +90 -38
  34. data/lib/cli.rb +0 -28
  35. data/lib/cli/package.rb +0 -13
  36. data/lib/console.rb +0 -23
  37. data/lib/packager.rb +0 -2
  38. data/lib/packager/generate_binary_package.rb +0 -105
  39. data/lib/packager/generate_lambda_package.rb +0 -26
  40. data/lib/packager/templates/binary_package/build/linux-x86_64/lib/app/hello.rb +0 -1
  41. data/lib/packager/templates/binary_package/build/resources/%domain_name%.rb.tt +0 -17
  42. data/lib/packager/templates/binary_package/build/resources/Dockerfile.tt +0 -8
  43. data/lib/packager/templates/binary_package/build/resources/Gemfile.tt +0 -4
  44. data/lib/packager/templates/binary_package/build/resources/wrapper.tt +0 -13
  45. data/lib/packager/templates/lambda_package/handler.js.tt +0 -12
  46. data/lib/packager/templates/lambda_package/serverless.yml.tt +0 -100
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -e
3
+ SELFDIR="`dirname \"$0\"`"
4
+ SELFDIR="`cd \"$SELFDIR\" && pwd`"
5
+ export BUNDLE_GEMFILE="$SELFDIR/Gemfile"
6
+ unset BUNDLE_IGNORE_CONFIG
7
+ exec "$SELFDIR/ruby/bin/ruby" -rbundler/setup -rreadline "$SELFDIR/lib/hecks.rb" "$@"
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # New builder format (drop the types!):
4
+ # Pizzas::Pizza(:name, :description)
5
+ # *Toppings
6
+ # named_by :Chef
7
+ # Pizzas::Chef(:name)
8
+ #
9
+ # Orders::Order
10
+ # \*LineItem(:pizza_name, :quantity, :price)
11
+ # \Pizzas::Pizza
12
+ # NOTE: Domain should generate english sentences
13
+ # A pizza has many toppings, a name, and a description
14
+ # A pizza is named by a chef
15
+ # A chef has a name
16
+ # An Order has many line items
17
+ # A Line Item has a a pizza, pizza_name, a quantity and a price
18
+
19
+
20
+ DOMAIN ||= HecksDomainBuilder.build "pizza_builder" do |pizza_builder|
21
+ pizza_builder.module 'Pizzas' do |pizzas|
22
+ pizzas.head("Pizza").attributes('name:string', 'description:string', 'toppings:[topping]', 'chef:chef')
23
+ pizzas.value("Topping").attributes('name:string')
24
+ pizzas.value("Chef").attributes('name:string')
25
+ end
26
+
27
+ pizza_builder.module 'Orders' do |orders|
28
+ orders.head("Order").attributes('line_items:[line_item]')
29
+ orders.value("LineItem").attributes('pizza_name:string', 'quantity:integer', 'price:currency', "pizza:pizzas::pizza")
30
+ orders.reference("pizzas::pizza")
31
+ end
32
+ end
@@ -0,0 +1,75 @@
1
+ module HecksServerless
2
+ # Generators to build a serverless config
3
+ class CLI < Thor
4
+ include Thor::Actions
5
+ package_name 'hecks_serverless'
6
+ SELF_PATH = File.dirname(__FILE__)
7
+ DESCRIPTION = "Generate domain functions on lambda"
8
+ COMMAND_NAME = "generate"
9
+ RESOURCES_FOLDER = "#{SELF_PATH}/resources"
10
+ SERVERLESS_FILE = "serverless.yml"
11
+ CRUD_METHODS = %w{create read update delete}
12
+ HANDLER_TEMPLATE = 'handler.js'
13
+ ENVIRONMENT_FILE = 'environment.js'
14
+
15
+ desc COMMAND_NAME, DESCRIPTION
16
+ def generate
17
+ create_serverless_file
18
+ create_domain_module_files
19
+ insert_handlers_into_serverless_file
20
+ end
21
+
22
+ def self.source_root
23
+ RESOURCES_FOLDER
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :locals
29
+
30
+ def insert_handlers_into_serverless_file
31
+ insert_into_file SERVERLESS_FILE, handlers, :after => "functions:"
32
+ end
33
+
34
+ def create_serverless_file
35
+ copy_file SERVERLESS_FILE
36
+ end
37
+
38
+ def create_domain_module_files
39
+ domain_modules.each { |dmodule| create_handler_files(dmodule) }
40
+ end
41
+
42
+ def create_handler_files(dmodule)
43
+ self.locals = {domain_module: dmodule.name.downcase}
44
+ template HANDLER_TEMPLATE, "serverless/#{dmodule.name.downcase}.js"
45
+ copy_file ENVIRONMENT_FILE, 'serverless/environment.js'
46
+ copy_file 'run_binary.js', 'serverless/run_binary.js'
47
+ copy_file 'command_name.js', 'serverless/command_name.js'
48
+ end
49
+
50
+ def locals=(value)
51
+ @locals ||= {}
52
+ @locals.merge!(value)
53
+ end
54
+
55
+ def handlers
56
+ "\n" + domain_modules.flat_map { |mod| crud(mod) }.join("\n")
57
+ end
58
+
59
+ def crud(domain_module)
60
+ self.locals = {domain_module: domain_module.name.downcase}
61
+ CRUD_METHODS.flat_map {|function| line(function, domain_module)}
62
+ end
63
+
64
+ def domain_modules
65
+ DOMAIN.domain_modules.values
66
+ end
67
+
68
+ def line(function, domain_module)
69
+ <<-HEREDOC
70
+ #{domain_module.name.downcase}_#{function}:
71
+ handler: serverless/#{domain_module.name.downcase}.#{function}
72
+ HEREDOC
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,5 @@
1
+ var environment = require('./environment')
2
+
3
+ module.exports = function (context, event, command) {
4
+ return "package/" + environment(context['functionName']) + "/app -m pizzas -c " + command + " -d '" + JSON.stringify(event) + "'"
5
+ }
@@ -0,0 +1,7 @@
1
+ module.exports = function (functionName) {
2
+ if(functionName.indexOf('-dev-') > -1) {
3
+ return 'osx'
4
+ } else {
5
+ return 'linux'
6
+ }
7
+ }
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+ var runBinary = require('./run_binary')
3
+ var commandName = require('./command_name')
4
+ const exec = require('child_process').exec
5
+
6
+ module.exports.create = (event, context, callback) => {
7
+ exec(commandName(context, event, 'create'), (err, stdout, stderr) => {
8
+ callback(null, runBinary('create', '<%= locals[:domain_module] %>', err, stdout, stderr, event));
9
+ });
10
+ };
11
+
12
+ module.exports.read = (event, context, callback) => {
13
+ exec(commandName(context, event, 'read'), (err, stdout, stderr) => {
14
+ callback(null, runBinary('read', '<%= locals[:domain_module] %>', err, stdout, stderr, event));
15
+ });
16
+ };
17
+
18
+ module.exports.update = (event, context, callback) => {
19
+ exec(commandName(context, event, 'update'), (err, stdout, stderr) => {
20
+ callback(null, runBinary('update', '<%= locals[:domain_module] %>', err, stdout, stderr, event));
21
+ });
22
+ };
23
+
24
+ module.exports.delete = (event, context, callback) => {
25
+ exec(commandName(context, event, 'delete'), (err, stdout, stderr) => {
26
+ callback(null, runBinary('delete', '<%= locals[:domain_module] %>', err, stdout, stderr, event));
27
+ });
28
+ };
@@ -0,0 +1,22 @@
1
+ module.exports = function(command, module, err, stdout, stderr, event) {
2
+ if (err) { console.error(err); return }
3
+
4
+ var result = JSON.parse(stdout)
5
+
6
+ if(result && result.errors) {
7
+ var statusCode = Object.keys(result.errors).length > 0 ? 500 : 200
8
+ } else {
9
+ var statusCode = 200
10
+ }
11
+
12
+ return {
13
+ statusCode: statusCode,
14
+ body: {
15
+ command: command,
16
+ module: module,
17
+ input: event,
18
+ result: result,
19
+ errors: result ? result.errors : []
20
+ }
21
+ };
22
+ }
@@ -0,0 +1,20 @@
1
+ service: pizza-builder
2
+ provider:
3
+ name: aws
4
+ runtime: nodejs4.3
5
+ iamRoleStatements:
6
+ - Effect: Allow
7
+ Action:
8
+ - dynamodb:Query
9
+ - dynamodb:Scan
10
+ - dynamodb:GetItem
11
+ - dynamodb:PutItem
12
+ - dynamodb:UpdateItem
13
+ - dynamodb:DeleteItem
14
+ Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/*"
15
+ package:
16
+ exclude:
17
+ - spec/**
18
+ - tmp/**
19
+ - package/osx/**
20
+ functions:
metadata CHANGED
@@ -1,85 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hecks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4.rc
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Young
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-14 00:00:00.000000000 Z
11
+ date: 2017-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hecks-application
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '0.0'
19
+ version: 0.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: '0.0'
26
+ version: 0.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: hecks-domain
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: '0.0'
33
+ version: 0.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: '0.0'
40
+ version: 0.2.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: hecks-adapters
42
+ name: hecks-adapters-sql-database
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: '0.0'
47
+ version: 0.2.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: '0.0'
54
+ version: 0.2.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: activesupport
56
+ name: hecks-adapters-resource-server
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: '5.0'
61
+ version: 0.2.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.2.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: hecks-adapters-dynamodb
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.2.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
67
81
  - !ruby/object:Gem::Version
68
- version: '5.0'
82
+ version: 0.2.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: thor
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0.19'
89
+ version: '0.10'
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0.19'
96
+ version: '0.10'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: codeclimate-test-reporter
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -150,37 +164,75 @@ dependencies:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0.10'
167
+ - !ruby/object:Gem::Dependency
168
+ name: vcr
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '3.0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '3.0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: webmock
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '2.3'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '2.3'
153
195
  description: Make the Domain the center of your programming world
154
196
  email: chris@example.com
155
197
  executables:
156
198
  - hecks
157
199
  - hecks_console
200
+ - hecks-package
201
+ - hecks_serverless
158
202
  extensions: []
159
203
  extra_rdoc_files: []
160
204
  files:
161
205
  - bin/hecks
206
+ - bin/hecks-package
162
207
  - bin/hecks_console
163
- - lib/cli.rb
208
+ - bin/hecks_serverless
164
209
  - lib/cli/build.rb
165
210
  - lib/cli/command_runner.rb
166
211
  - lib/cli/console.rb
167
212
  - lib/cli/generate.rb
168
- - lib/cli/package.rb
213
+ - lib/cli/hecks-cli.rb
169
214
  - lib/cli/test.rb
170
- - lib/console.rb
171
215
  - lib/console/commands.rb
216
+ - lib/console/hecks-console.rb
172
217
  - lib/hecks.rb
173
- - lib/packager.rb
174
- - lib/packager/generate_binary_package.rb
175
- - lib/packager/generate_lambda_package.rb
176
- - lib/packager/templates/binary_package/build/linux-x86_64/lib/app/hello.rb
177
- - lib/packager/templates/binary_package/build/resources/%domain_name%.rb.tt
178
- - lib/packager/templates/binary_package/build/resources/Dockerfile.tt
179
- - lib/packager/templates/binary_package/build/resources/Gemfile.tt
180
- - lib/packager/templates/binary_package/build/resources/bundle/config
181
- - lib/packager/templates/binary_package/build/resources/wrapper.tt
182
- - lib/packager/templates/lambda_package/handler.js.tt
183
- - lib/packager/templates/lambda_package/serverless.yml.tt
218
+ - lib/packager/README.md
219
+ - lib/packager/app_runner.rb
220
+ - lib/packager/args.rb
221
+ - lib/packager/compatibility/fixnum.rb
222
+ - lib/packager/hecks.rb
223
+ - lib/packager/query_runner.rb
224
+ - lib/packager/resources/Dockerfile
225
+ - lib/packager/resources/app_binary
226
+ - lib/packager/resources/bundle_config
227
+ - lib/packager/resources/traveling-ruby-20150715-2.2.2-linux-x86_64.tar.gz
228
+ - lib/packager/resources/traveling-ruby-20150715-2.2.2-osx.tar.gz
229
+ - lib/serverless/Domain
230
+ - lib/serverless/cli.rb
231
+ - lib/serverless/resources/command_name.js
232
+ - lib/serverless/resources/environment.js
233
+ - lib/serverless/resources/handler.js.tt
234
+ - lib/serverless/resources/run_binary.js
235
+ - lib/serverless/resources/serverless.yml
184
236
  homepage: https://github.com/chrisyoung/heckson
185
237
  licenses:
186
238
  - MIT
@@ -196,9 +248,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
196
248
  version: '0'
197
249
  required_rubygems_version: !ruby/object:Gem::Requirement
198
250
  requirements:
199
- - - ">"
251
+ - - ">="
200
252
  - !ruby/object:Gem::Version
201
- version: 1.3.1
253
+ version: '0'
202
254
  requirements: []
203
255
  rubyforge_project:
204
256
  rubygems_version: 2.6.10
data/lib/cli.rb DELETED
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'active_support/inflector'
3
- require_relative 'cli/generate'
4
- require_relative 'cli/package'
5
- require_relative 'cli/test'
6
- require_relative 'cli/console'
7
- require_relative 'cli/command_runner'
8
- require_relative 'cli/build'
9
-
10
- module Hecks
11
- class CLI < Thor
12
- package_name 'hecks'
13
-
14
- desc 'generate', 'generate'
15
- subcommand('generate', Generate)
16
-
17
- desc 'package', 'package'
18
- subcommand('package', Package) if File.file?('Domain')
19
-
20
- desc 'test', 'test'
21
- subcommand('test', Test) if File.file?('hecks.gemspec')
22
-
23
- long_desc 'Generate a domain'
24
- method_option :dryrun, aliases: '-d', type: :boolean, desc: 'Output commands without running'
25
-
26
- register(Hecks::Domain::CLI::New, 'new', 'new', 'Create a new Domain') if File.file?('Domain')
27
- end
28
- end