This repository was archived by the owner on Aug 27, 2025. It is now read-only.
forked from kpfefferle/ember-cli-deploy-cloudfront
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
74 lines (63 loc) · 2.41 KB
/
index.js
File metadata and controls
74 lines (63 loc) · 2.41 KB
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
/* eslint-env node */
'use strict';
const RSVP = require('rsvp');
const BasePlugin = require('ember-cli-deploy-plugin');
const CloudFront = require('./lib/cloudfront');
module.exports = {
name: require('./package').name,
createDeployPlugin: function (options) {
const 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*/) {
const distribution = this.readConfig('distribution');
const objectPaths = this.readConfig('objectPaths');
const waitForInvalidation = this.readConfig('waitForInvalidation');
const cloudfront =
this.readConfig('invalidationClient') ||
new CloudFront({
plugin: this,
});
const distributions = Array.isArray(distribution)
? distribution
: [distribution];
const distributionInvalidations = distributions.map((currDistribution) => {
const options = {
objectPaths: objectPaths,
distribution: currDistribution,
waitForInvalidation: waitForInvalidation,
};
this.log(`preparing to create invalidation for CloudFront distribution '${currDistribution}'`, { verbose: true });
return cloudfront
.invalidate(options)
.then((invalidationId) => {
this.log(`invalidation process finished for invalidation ${invalidationId}`, { verbose: true });
})
.catch((error) => {
this._errorMessage(error);
});
});
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();
},
};