-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
67 lines (54 loc) · 1.96 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
/*eslint-env node*/
'use strict';
//const RSVP = require('rsvp');
const DeployPluginBase = require('ember-cli-deploy-plugin');
const CfnClient = require('./lib/cfn');
const Logger = require('./lib/logger');
module.exports = {
name: 'ember-cli-deploy-cloudformation',
createDeployPlugin: function(options) {
let DeployPlugin = DeployPluginBase.extend({
name: options.name,
defaultConfig: {},
requiredConfig: [],
configure(context) {
this.defaultConfig.stackName = `${context.project.name()}-${context.deployTarget}`;
this._super.configure.apply(this, arguments);
let templateBody = this.readConfig('templateBody');
let templateUrl = this.readConfig('templateURL');
if (!templateBody && !templateUrl) {
let message = `Missing required config: either 'templateBody' or 'templateURL' is required`;
this.log(message, { color: 'red' });
throw new Error(message);
}
},
setup() {
let options = Object.keys(this.pluginConfig)
.map((key) => ({ [key]: this.readConfig(key)}))
.reduce((result, item) => Object.assign(result, item), {});
this.cfnClient = this.readConfig('cfnClient') || new CfnClient(options);
this.cfnClient.logger = new Logger(this.log.bind(this));
return this.cfnClient.validateTemplate()
.catch(this._errorMessage.bind(this));
},
prepare(context) {
return this.cfnClient.createOrUpdateStack()
.then(() => this.cfnClient.fetchOutputs())
.then(outputs => {
context.cloudformation = {
outputs
};
})
.catch(this._errorMessage.bind(this));
},
_errorMessage(error) {
this.log(error, { color: 'red' });
if (error && error.stack) {
this.log(error.stack, { color: 'red' });
}
return Promise.reject(error);
}
});
return new DeployPlugin();
}
};