Last active
August 29, 2015 14:27
-
-
Save lusentis/8447640e08f1110ab308 to your computer and use it in GitHub Desktop.
Lambda Toolkit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*eslint quotes: [0] */ | |
/*global desc, task, watchTask, complete, jake */ | |
var assert = require('assert'); | |
assert(process.env.NODE_ENV, 'NODE_ENV must be set'); | |
var EXEC_OPTS = { printStdout: true, printStderr: true }; | |
desc('Build the source with webpack'); | |
task('build', { async: true }, function () { | |
jake.exec('node_modules/.bin/webpack --config webpack.config.js', EXEC_OPTS, function () { | |
jake.logger.log('Build done.'); | |
complete(); | |
}); | |
}); | |
desc('Test with a sample event'); | |
task('test', ['build'], { async: true }, function () { | |
jake.exec("node -e \"var fs=require('fs');var event=JSON.parse(fs.readFileSync(__dirname+'/event.json'));var terminate=function(){console.log('Function done');console.log.apply(console,arguments)};var index=require('./dist/index');index.handler(event,{done:terminate,fail:terminate,succeed:terminate});\"", EXEC_OPTS, function () { | |
jake.logger.log('Test done.'); | |
complete(); | |
}); | |
}); | |
desc('Watch and re-test on change'); | |
watchTask('watch', ['test'], { async: true }, function () { | |
this.watchFiles.include([ | |
'./src/**/*.js', | |
]); | |
}); | |
desc('Build then watch'); | |
task('default', ['build', 'watch']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "xxx", | |
"version": "1.0.0", | |
"description": "", | |
"main": "", | |
"scripts": { | |
"build": "node_modules/.bin/webpack --config webpack.config.js", | |
"test": "node -e \"var fs=require('fs');var event=JSON.parse(fs.readFileSync(__dirname+'/event.json'));var terminate=function(){console.log('Function done');console.log.apply(console,arguments)};var index=require('./dist/index');index.handler(event,{done:terminate,fail:terminate,succeed:terminate});\"", | |
"build-test": "npm run-script -s build && npm run-script -s test", | |
"watch": "nodemon -w src/** -x npm -- run-script -s build-test" | |
}, | |
"author": "", | |
"license": "", | |
"dependencies": { | |
"babel-core": "^5.8.22", | |
"babel-loader": "^5.3.2", | |
"source-map-support": "^0.3.2", | |
"webpack": "^1.11.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var event = JSON.parse(fs.readFileSync(__dirname + '/event.json')); | |
var terminate = function() { | |
console.log('Function done'); | |
console.log.apply(console, arguments); | |
}; | |
var index = require('./dist/index'); | |
index.handler(event, { | |
done: terminate, | |
fail: terminate, | |
succeed: terminate, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// some code from http://jlongster.com/Backend-Apps-with-Webpack--Part-I | |
var webpack = require('webpack'); | |
var path = require('path'); | |
var fs = require('fs'); | |
function includeDir(dirName) { | |
fs.readdirSync(dirName) | |
.filter(function(x) { | |
return ['.bin'].indexOf(x) === -1; | |
}) | |
.forEach(function(mod) { | |
nodeModules[mod] = 'commonjs ' + mod; | |
}); | |
} | |
var nodeModules = {}; | |
includeDir('node_modules'); | |
includeDir('../../node_modules'); | |
module.exports = { | |
entry: './src/index.js', | |
target: 'node', | |
node: { | |
__filename: true, | |
__dirname: true, | |
}, | |
output: { | |
library: 'handler', | |
libraryTarget: 'commonjs2', | |
path: __dirname + '/dist', | |
filename: 'index.js', | |
}, | |
module: { | |
loaders: [ | |
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel' }, | |
], | |
}, | |
externals: nodeModules, | |
devtool: 'sourcemap', | |
plugins: [ | |
new webpack.BannerPlugin('require("source-map-support").install();', { raw: true, entryOnly: false }), | |
], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment