From 3e89dc09e03bf37928b363c641c2f2bce7fa9f11 Mon Sep 17 00:00:00 2001 From: IamDadicus Date: Fri, 15 May 2015 20:23:19 +0100 Subject: [PATCH 1/2] Dynamic event construction Supports constructing event objects on the fly rather than loading static json files. --- lib/event.js.example | 5 +++++ lib/main.js | 15 +++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 lib/event.js.example diff --git a/lib/event.js.example b/lib/event.js.example new file mode 100644 index 00000000..61696a11 --- /dev/null +++ b/lib/event.js.example @@ -0,0 +1,5 @@ +{ + "key": "value", + "key2": "value2", + "other_key": "other_value" +} diff --git a/lib/main.js b/lib/main.js index 2e56298c..14b58274 100644 --- a/lib/main.js +++ b/lib/main.js @@ -29,12 +29,12 @@ Lambda.prototype._createSampleFile = function(file) { Lambda.prototype.setup = function() { console.log('Running setup.'); this._createSampleFile('.env'); - this._createSampleFile('event.json'); - console.log('Setup done. Edit the .env and event.json files as needed.'); + this._createSampleFile('event.js'); + console.log('Setup done. Edit the .env and event.js files as needed.'); }; Lambda.prototype.run = function(program) { - this._createSampleFile('event.json'); + this._createSampleFile('event.js'); var dir = program.directory; var splitHandler = program.handler.split('.'); @@ -42,9 +42,12 @@ Lambda.prototype.run = function(program) { var handlername = splitHandler[1]; var handler = require(process.cwd() + '/' + filename)[handlername]; - var event = require(process.cwd() + '/event.json'); - - this._runHandler(handler, event); + var event = require(process.cwd() + '/event.js'); + var this_instance = this; + + event.feed( function(event) { + this_instance._runHandler(handler, event); + }); }; Lambda.prototype._runHandler = function(handler, event) { From 7d574cfa488f573d023d5bda335ceb54725238c5 Mon Sep 17 00:00:00 2001 From: IamDadicus Date: Tue, 9 Jun 2015 20:33:18 +0100 Subject: [PATCH 2/2] modified fail,succeed and done functions to be more lambda-esq --- lib/main.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 14b58274..30d4a965 100644 --- a/lib/main.js +++ b/lib/main.js @@ -9,6 +9,7 @@ var path = require('path'); var async = require('async'); var zip = new require('node-zip')(); var wrench = require('wrench'); +var util = require('util'); var Lambda = function() { this.version = packageJson.version; @@ -53,15 +54,16 @@ Lambda.prototype.run = function(program) { Lambda.prototype._runHandler = function(handler, event) { var context = { succeed: function(result) { - console.log('succeed: ' + result); + console.log('succeed:\n' + util.inspect(result, {depth: 5})); process.exit(0); }, fail: function(error) { - console.log('fail: ' + error); + console.log('fail:\n' + util.inspect(error, {depth: 5})); process.exit(-1); }, - done: function() { - process.exit(0); + done: function(error, result) { + console.log('done:\n' + util.inspect(Array.slice(arguments), {depth: 5})); + process.exit( error ? -1 : 0); } };