-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.js
85 lines (73 loc) · 2.53 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
/* eslint-env node */
'use strict';
var RSVP = require('rsvp');
var BasePlugin = require('ember-cli-deploy-plugin');
var CloudFront = require('./lib/cloudfront');
module.exports = {
name: require('./package').name,
createDeployPlugin: function (options) {
var DeployPlugin = BasePlugin.extend({
name: options.name,
defaultConfig: {
region: 'us-east-1',
objectPaths: ['/index.html'],
invalidationClient: function (context) {
return context.invalidationClient; // if you want to provide your own invalidation client to be used instead of one from this plugin
},
cloudfrontClient: function (context) {
return context.cloudfrontClient; // if you want to provide your own CloudFront client to be used instead of one from aws-sdk
},
waitForInvalidation: false,
},
requiredConfig: ['distribution', 'region'],
didActivate: function (/*context*/) {
var self = this;
var distribution = this.readConfig('distribution');
var objectPaths = this.readConfig('objectPaths');
var waitForInvalidation = this.readConfig('waitForInvalidation');
var cloudfront =
this.readConfig('invalidationClient') ||
new CloudFront({
plugin: this,
});
var distributions = Array.isArray(distribution)
? distribution
: [distribution];
var distributionInvalidations = distributions.map(function (
distribution
) {
var options = {
objectPaths: objectPaths,
distribution: distribution,
waitForInvalidation: waitForInvalidation,
};
self.log(
'preparing to create invalidation for CloudFront distribution `' +
distribution +
'`',
{ verbose: true }
);
return cloudfront
.invalidate(options)
.then(function (invalidationId) {
self.log(
'invalidation process finished for invalidation ' +
invalidationId,
{ verbose: true }
);
})
.catch(self._errorMessage.bind(self));
});
return RSVP.Promise.all(distributionInvalidations);
},
_errorMessage: function (error) {
this.log(error, { color: 'red' });
if (error) {
this.log(error.stack, { color: 'red' });
}
return RSVP.reject(error);
},
});
return new DeployPlugin();
},
};