forked from envoy/ember-cli-deploy-gcs-index
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
137 lines (119 loc) · 4.15 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
/* jshint node: true */
'use strict';
var DeployPluginBase = require('ember-cli-deploy-plugin');
var GCS = require('./lib/gcs');
var joinUriSegments = require('./lib/util/join-uri-segments');
module.exports = {
name: 'ember-cli-deploy-gcs-index',
createDeployPlugin: function(options) {
var DeployPlugin = DeployPluginBase.extend({
name: options.name,
GCS: GCS,
defaultConfig: {
filePattern: 'index.html',
prefix: '',
acl: 'public-read',
distDir: function(context) {
return context.distDir;
},
revisionKey: function(context) {
var revisionKey = context.revisionData && context.revisionData.revisionKey;
return context.commandOptions.revision || revisionKey;
},
gzippedFiles: function(context) {
return context.gzippedFiles || [];
},
allowOverwrite: false
},
requiredConfig: ['bucket', 'projectId'],
upload: function(/* context */) {
var projectId = this.readConfig('projectId');
var keyFilename = this.readConfig('keyFilename');
var bucket = this.readConfig('bucket');
var prefix = this.readConfig('prefix');
var acl = this.readConfig('acl');
var revisionKey = this.readConfig('revisionKey');
var distDir = this.readConfig('distDir');
var filePattern = this.readConfig('filePattern');
var gzippedFiles = this.readConfig('gzippedFiles');
var allowOverwrite = this.readConfig('allowOverwrite');
var filePath = joinUriSegments(distDir, filePattern);
var options = {
bucket: bucket,
prefix: prefix,
acl: acl,
filePattern: filePattern,
filePath: filePath,
revisionKey: revisionKey,
gzippedFilePaths: gzippedFiles,
allowOverwrite: allowOverwrite
};
this.log('preparing to upload revision to Google Cloud Storage bucket `' + bucket + '`', { verbose: true });
var gcs = new this.GCS({
plugin: this,
keyFilename: keyFilename,
projectId: projectId
});
return gcs.upload(options);
},
activate: function(/* context */) {
var projectId = this.readConfig('projectId');
var keyFilename = this.readConfig('keyFilename');
var bucket = this.readConfig('bucket');
var prefix = this.readConfig('prefix');
var acl = this.readConfig('acl');
var revisionKey = this.readConfig('revisionKey');
var filePattern = this.readConfig('filePattern');
var options = {
bucket: bucket,
prefix: prefix,
acl: acl,
filePattern: filePattern,
revisionKey: revisionKey
};
this.log('preparing to activate `' + revisionKey + '`', { verbose: true });
var gcs = new this.GCS({
plugin: this,
keyFilename: keyFilename,
projectId: projectId
});
return gcs.activate(options);
},
fetchRevisions: function(context) {
return this._list(context)
.then(function(revisions) {
return {
revisions: revisions
};
});
},
fetchInitialRevisions: function(context) {
return this._list(context)
.then(function(revisions) {
return {
initialRevisions: revisions
};
});
},
_list: function(/* context */) {
var projectId = this.readConfig('projectId');
var keyFilename = this.readConfig('keyFilename');
var bucket = this.readConfig('bucket');
var prefix = this.readConfig('prefix');
var filePattern = this.readConfig('filePattern');
var options = {
bucket: bucket,
prefix: prefix,
filePattern: filePattern
};
var gcs = new this.GCS({
plugin: this,
keyFilename: keyFilename,
projectId: projectId
});
return gcs.fetchRevisions(options);
}
});
return new DeployPlugin();
}
};