You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.4 KiB

8 years ago
'use strict';
const BbPromise = require('bluebird');
const validate = require('./lib/validate');
const compile = require('./lib/compile');
const wpwatch = require('./lib/wpwatch');
8 years ago
const cleanup = require('./lib/cleanup');
const run = require('./lib/run');
const serve = require('./lib/serve');
const packExternalModules = require('./lib/packExternalModules');
8 years ago
class ServerlessWebpack {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options;
Object.assign(
this,
validate,
compile,
wpwatch,
cleanup,
run,
serve,
packExternalModules
8 years ago
);
this.commands = {
webpack: {
usage: 'Bundle with Webpack',
lifecycleEvents: [
'validate',
'compile',
],
8 years ago
options: {
out: {
usage: 'Path to output directory',
shortcut: 'o',
},
},
commands: {
invoke: {
usage: 'Run a function locally from the webpack output bundle',
lifecycleEvents: [
'invoke',
],
options: {
function: {
usage: 'Name of the function',
shortcut: 'f',
required: true,
},
path: {
usage: 'Path to JSON file holding input data',
shortcut: 'p',
},
},
},
watch: {
usage: 'Run a function from the webpack output bundle every time the source is changed',
lifecycleEvents: [
'watch',
],
options: {
function: {
usage: 'Name of the function',
shortcut: 'f',
required: true,
},
path: {
usage: 'Path to JSON file holding input data',
shortcut: 'p',
},
},
},
serve: {
usage: 'Simulate the API Gateway and serves lambdas locally',
lifecycleEvents: [
'serve',
],
options: {
port: {
usage: 'The local server port',
shortcut: 'p',
},
},
},
},
},
};
8 years ago
this.hooks = {
'before:deploy:createDeploymentArtifacts': () => BbPromise.bind(this)
8 years ago
.then(this.validate)
.then(this.compile)
.then(this.packExternalModules),
8 years ago
'after:deploy:createDeploymentArtifacts': () => BbPromise.bind(this)
8 years ago
.then(this.cleanup),
'webpack:validate': () => BbPromise.bind(this)
.then(this.validate),
'webpack:compile': () => BbPromise.bind(this)
.then(this.compile)
.then(this.packExternalModules),
'webpack:invoke:invoke': () => BbPromise.bind(this)
.then(this.validate)
.then(this.compile)
.then(this.run)
.then(out => this.serverless.cli.consoleLog(out)),
'webpack:watch:watch': () => BbPromise.bind(this)
.then(this.validate)
.then(this.watch),
'webpack:serve:serve': () => BbPromise.bind(this)
.then(this.validate)
.then(this.serve),
'before:offline:start': () => BbPromise.bind(this)
.then(this.validate)
.then(this.wpwatch),
8 years ago
};
}
}
module.exports = ServerlessWebpack;