-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
129 lines (117 loc) · 3.95 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
'use strict';
const BbPromise = require('bluebird'),
_ = require('lodash');
const validate = require('./lib/validate'),
configure = require('./lib/configure'),
buildSwagger = require('./lib/buildSwagger');
// cleanup = require('./lib/cleanup');
class SlsSwag {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options;
this.provider = 'aws';
this.awsProvider = this.serverless.getProvider('aws');
this.globalSwagConfig = {};
this.swagDefObj = {};
//Why is this not already done by framework? https://github.com/serverless/serverless/issues/2631
this.options.stage = this.options.stage
|| (this.serverless.service.defaults && this.serverless.service.defaults.stage)
|| 'dev';
this.options.region = this.options.region
|| (this.serverless.service.defaults && this.serverless.service.defaults.region)
|| 'us-east-1';
Object.assign(
this,
validate,
configure,
buildSwagger
);
this.commands = {
swag: {
usage: 'Enterprise mgmt of APIG and Lambda',
lifecycleEvents: [
'help',
],
options: {},
commands: {
"apig-import": {
usage: 'Import API Gateway (overwrite or merge with -p). --region supported',
lifecycleEvents: [
'initialize',
'configure',
'buildSwagger',
'import',
'cleanup'
],
options: {
regex: {
usage: 'Regex of resource paths to import (merge mode)',
shortcut: 'e',
},
methods: {
usage: 'CSV of methods to import. Ex: -m PUT,GET -e "^u" Ex2: -m PUT',
shortcut: 'm',
},
noConfirm: {
usage: 'Only valid if -e or -m specified. Don\'t confirm before importing matched paths/methods',
shortcut: 'n',
},
out: {
usage: 'Full path to where you want the swagger.json file stored. Default is swagger.json next to serverless.yml',
shortcut: 'o',
},
},
},
"func-deploy": {
usage: 'Deploy HTTP evented Lambdas via AWS APIs. --stage and --region supported',
lifecycleEvents: [
'initialize',
'configure',
'package',
'deploy',
'cleanup'
],
options: {
regex: {
usage: 'Regex of functions to deploy',
shortcut: 'e',
},
},
}
},
},
};
this.hooks = {
//Handle `sls swat apig-import`
'swag:apig-import:initialize': () => BbPromise.bind(this)
.then(this.validate)
.then(this.globalConfig)
.then(this.buildCoreSwagger)
.then(() => {
let q = [];
const functionNames = this.serverless.service.getAllFunctions();
for (const fName of functionNames) {
q.push(this.genSwaggerPathObj(fName)
.then(spo => _.extend(this.swagDefObj.paths, spo)));
}
return BbPromise.all(q);
})
.then(() => {
console.log(this.swagDefObj);
}),
//
// //Handle `sls deploy function`
// 'before:deploy:function:packageFunction': () => BbPromise.bind(this)
// .then(this.validate)
// .then(this.globalConfig)
// .then(() => this.bundle(this.options.function)),
//
//Handle `sls swag`
'swag:help': () => BbPromise.bind(this)
.then(() => {
this.serverless.cli.log('Must specify a swag command. Run "serverless swag -h"');
}),
};
}
}
module.exports = SlsSwag;