forked from serverless-heaven/serverless-aws-alias
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
186 lines (159 loc) · 4.33 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
'use strict';
/**
* Serverless AWS alias plugin
*/
const BbPromise = require('bluebird')
, _ = require('lodash')
, Path = require('path')
, validate = require('./lib/validate')
, configureAliasStack = require('./lib/configureAliasStack')
, createAliasStack = require('./lib/createAliasStack')
, updateAliasStack = require('./lib/updateAliasStack')
, aliasRestructureStack = require('./lib/aliasRestructureStack')
, stackInformation = require('./lib/stackInformation')
, listAliases = require('./lib/listAliases')
, removeAlias = require('./lib/removeAlias')
, logs = require('./lib/logs')
, collectUserResources = require('./lib/collectUserResources')
, uploadAliasArtifacts = require('./lib/uploadAliasArtifacts');
class AwsAlias {
constructor(serverless, options) {
this._serverless = serverless;
this._options = options || {};
this._provider = this._serverless.getProvider('aws');
/**
* Load stack helpers from Serverless installation.
*/
const monitorStack = require(
Path.join(this._serverless.config.serverlessPath,
'plugins',
'aws',
'lib',
'monitorStack')
);
const setBucketName = require(
Path.join(this._serverless.config.serverlessPath,
'plugins',
'aws',
'lib',
'setBucketName')
);
_.assign(
this,
validate,
collectUserResources,
configureAliasStack,
createAliasStack,
updateAliasStack,
listAliases,
logs,
removeAlias,
aliasRestructureStack,
stackInformation,
uploadAliasArtifacts,
setBucketName,
monitorStack
);
this._commands = {
alias: {
commands: {
remove: {
usage: 'Remove a deployed alias',
lifecycleEvents: [
'remove'
],
options: {
alias: {
usage: 'Name of the alias',
shortcut: 'a',
required: true
},
verbose: {
usage: 'Enable verbose output',
shortcut: 'v',
required: false
}
}
}
}
}
};
this._hooks = {
'before:package:initialize': () => BbPromise.bind(this)
.then(this.validate),
'before:aws:package:finalize:mergeCustomProviderResources': () => BbPromise.bind(this)
.then(this.collectUserResources),
'before:deploy:deploy': () => BbPromise.bind(this)
.then(this.validate)
.then(this.configureAliasStack),
'before:aws:deploy:deploy:createStack': () => BbPromise.bind(this)
.then(this.aliasStackLoadCurrentCFStackAndDependencies)
.spread(this.aliasRestructureStack),
'after:aws:deploy:deploy:createStack': () => BbPromise.bind(this)
.then(this.createAliasStack),
'after:aws:deploy:deploy:uploadArtifacts': () => BbPromise.bind(this)
.then(this.setBucketName)
.then(this.uploadAliasArtifacts),
'after:aws:deploy:deploy:updateStack': () => BbPromise.bind(this)
.then(this.updateAliasStack),
'after:info:info': () => BbPromise.bind(this)
.then(this.validate)
.then(this.listAliases),
// Override the logs command - must be, because the $LATEST filter
// in the original logs command is not easy to change without hacks.
'logs:logs': () => BbPromise.bind(this)
.then(this.validate)
.then(this.logsValidate)
.then(this.logsGetLogStreams)
.then(this.logsShowLogs),
'alias:remove:remove': () => BbPromise.bind(this)
.then(this.validate)
.then(this.aliasStackLoadCurrentCFStackAndDependencies)
.spread(this.removeAlias)
};
// Patch hooks to override our event replacements
const pluginManager = this.serverless.pluginManager;
const logHooks = pluginManager.hooks['logs:logs'];
_.pullAllWith(logHooks, [ 'AwsLogs' ], (a, b) => a.pluginName === b);
}
/**
* Expose the supported commands as read-only property.
*/
get commands() {
return this._commands;
}
/**
* Expose the supported hooks as read-only property.
*/
get hooks() {
return this._hooks;
}
/**
* Expose the options as read-only property.
*/
get options() {
return this._options;
}
/**
* Expose the supported provider as read-only property.
*/
get provider() {
return this._provider;
}
/**
* Expose the serverless object as read-only property.
*/
get serverless() {
return this._serverless;
}
/**
* Expose the stack name as read-only property.
*/
get stackName() {
return this._stackName;
}
_cleanup() {
this._serverless.cli.log('Cleanup !!!!');
}
}
module.exports = AwsAlias;