You've already forked serverless-offline
mirror of
https://github.com/encounter/serverless-offline.git
synced 2026-03-30 11:37:53 -07:00
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const _ = require('lodash');
|
|
const sinon = require('sinon');
|
|
|
|
module.exports = class ServerlessBuilder {
|
|
constructor(serverless) {
|
|
const serverlessDefaults = {
|
|
service: {
|
|
provider: {
|
|
name: 'aws',
|
|
stage: 'dev',
|
|
region: 'us-east-1',
|
|
runtime: 'nodejs4.3',
|
|
},
|
|
functions: {},
|
|
getFunction(functionName) {
|
|
return this.functions[functionName];
|
|
},
|
|
},
|
|
cli: {
|
|
log: sinon.stub(),
|
|
},
|
|
version: '1.0.2',
|
|
config: {
|
|
servicePath: '',
|
|
},
|
|
};
|
|
this.serverless = _.merge(serverlessDefaults, serverless);
|
|
this.serverless.service.getFunction = this.serverless.service.getFunction.bind(this.serverless.service);
|
|
}
|
|
|
|
addApiKeys(keys) {
|
|
this.serverless.service.provider = Object.assign(this.serverless.service.provider, { apiKeys: keys });
|
|
}
|
|
|
|
addFunction(functionName, functionConfig) {
|
|
this.serverless.service.functions[functionName] = functionConfig;
|
|
}
|
|
|
|
addCustom(prop, value) {
|
|
const newCustomProp = {};
|
|
newCustomProp[prop] = value;
|
|
this.serverless.service.custom = Object.assign(this.serverless.service.custom || {}, newCustomProp);
|
|
}
|
|
|
|
toObject() {
|
|
return this.serverless;
|
|
}
|
|
};
|