1
1
/* jshint node: true */
2
2
'use strict' ;
3
3
4
- var RSVP = require ( 'rsvp' ) ;
5
- var path = require ( 'path' ) ;
6
- var fs = require ( 'fs' ) ;
4
+ let path = require ( 'path' ) ;
5
+ let fs = require ( 'fs' ) ;
7
6
8
- var denodeify = require ( 'rsvp' ) . denodeify ;
9
- var readFile = denodeify ( fs . readFile ) ;
10
-
11
- var DeployPluginBase = require ( 'ember-cli-deploy-plugin' ) ;
7
+ let DeployPluginBase = require ( 'ember-cli-deploy-plugin' ) ;
12
8
13
9
module . exports = {
14
10
name : 'ember-cli-deploy-redis' ,
15
11
16
- createDeployPlugin : function ( options ) {
12
+ createDeployPlugin ( options ) {
17
13
var Redis = require ( './lib/redis' ) ;
18
14
19
15
var DeployPlugin = DeployPluginBase . extend ( {
20
16
name : options . name ,
21
17
defaultConfig : {
22
18
host : 'localhost' ,
23
- port : function ( context ) {
19
+ port ( context ) {
24
20
if ( context . tunnel && context . tunnel . srcPort ) {
25
21
return context . tunnel . srcPort ;
26
22
} else {
@@ -29,27 +25,27 @@ module.exports = {
29
25
} ,
30
26
filePattern : 'index.html' ,
31
27
maxRecentUploads : 10 ,
32
- distDir : function ( context ) {
28
+ distDir ( context ) {
33
29
return context . distDir ;
34
30
} ,
35
- keyPrefix : function ( context ) {
36
- return context . project . name ( ) + ' :index' ;
31
+ keyPrefix ( context ) {
32
+ return ` ${ context . project . name ( ) } :index` ;
37
33
} ,
38
34
activationSuffix : 'current' ,
39
35
activeContentSuffix : 'current-content' ,
40
- didDeployMessage : function ( context ) {
36
+ didDeployMessage ( context ) {
41
37
var revisionKey = context . revisionData && context . revisionData . revisionKey ;
42
38
var activatedRevisionKey = context . revisionData && context . revisionData . activatedRevisionKey ;
43
39
if ( revisionKey && ! activatedRevisionKey ) {
44
- return " Deployed but did not activate revision " + revisionKey + ". "
45
- + " To activate, run: "
46
- + " ember deploy:activate " + context . deployTarget + " --revision=" + revisionKey + "\n" ;
40
+ return ` Deployed but did not activate revision ${ revisionKey } . `
41
+ + ` To activate, run: `
42
+ + ` ember deploy:activate ${ context . deployTarget } --revision=${ revisionKey } ` + "\n" ;
47
43
}
48
44
} ,
49
- revisionKey : function ( context ) {
45
+ revisionKey ( context ) {
50
46
return context . commandOptions . revision || ( context . revisionData && context . revisionData . revisionKey ) ;
51
47
} ,
52
- redisDeployClient : function ( context , pluginHelper ) {
48
+ redisDeployClient ( context , pluginHelper ) {
53
49
var redisLib = context . _redisLib ;
54
50
var options = {
55
51
url : pluginHelper . readConfig ( 'url' ) ,
@@ -65,11 +61,11 @@ module.exports = {
65
61
return new Redis ( options , redisLib ) ;
66
62
} ,
67
63
68
- revisionData : function ( context ) {
64
+ revisionData ( context ) {
69
65
return context . revisionData ;
70
66
}
71
67
} ,
72
- configure : function ( /* context */ ) {
68
+ configure ( /* context */ ) {
73
69
this . log ( 'validating config' , { verbose : true } ) ;
74
70
75
71
if ( ! this . pluginConfig . url ) {
@@ -78,7 +74,7 @@ module.exports = {
78
74
var redisUrlRegexp = new RegExp ( '^redis://' ) ;
79
75
80
76
if ( ! this . pluginConfig . url . match ( redisUrlRegexp ) ) {
81
- throw new Error ( ' Your Redis URL appears to be missing the "redis://" protocol. Update your URL to: redis://' + this . pluginConfig . url ) ;
77
+ throw new Error ( ` Your Redis URL appears to be missing the "redis://" protocol. Update your URL to: redis://${ this . pluginConfig . url } ` ) ;
82
78
}
83
79
}
84
80
@@ -87,109 +83,110 @@ module.exports = {
87
83
this . log ( 'config ok' , { verbose : true } ) ;
88
84
} ,
89
85
90
- upload : function ( /* context */ ) {
91
- var redisDeployClient = this . readConfig ( 'redisDeployClient' ) ;
92
- var revisionKey = this . readConfig ( 'revisionKey' ) ;
93
- var distDir = this . readConfig ( 'distDir' ) ;
94
- var filePattern = this . readConfig ( 'filePattern' ) ;
95
- var keyPrefix = this . readConfig ( 'keyPrefix' ) ;
96
- var filePath = path . join ( distDir , filePattern ) ;
97
-
98
- this . log ( 'Uploading `' + filePath + '`' , { verbose : true } ) ;
99
- return this . _readFileContents ( filePath )
100
- . then ( redisDeployClient . upload . bind ( redisDeployClient , keyPrefix , revisionKey , this . readConfig ( 'revisionData' ) ) )
101
- . then ( this . _uploadSuccessMessage . bind ( this ) )
102
- . then ( function ( key ) {
103
- return { redisKey : key } ;
104
- } )
105
- . catch ( this . _errorMessage . bind ( this ) ) ;
86
+ async upload ( /* context */ ) {
87
+ let redisDeployClient = this . readConfig ( 'redisDeployClient' ) ;
88
+ let revisionKey = this . readConfig ( 'revisionKey' ) ;
89
+ let distDir = this . readConfig ( 'distDir' ) ;
90
+ let filePattern = this . readConfig ( 'filePattern' ) ;
91
+ let keyPrefix = this . readConfig ( 'keyPrefix' ) ;
92
+ let filePath = path . join ( distDir , filePattern ) ;
93
+
94
+ this . log ( `Uploading \`${ filePath } \`` , { verbose : true } ) ;
95
+ try {
96
+ let fileContents = await this . _readFileContents ( filePath ) ;
97
+ let key = await redisDeployClient . upload ( keyPrefix , revisionKey , this . readConfig ( 'revisionData' ) , fileContents ) ;
98
+ this . _logUploadSuccessMessage ( key ) ;
99
+ return { redisKey : key } ;
100
+ } catch ( e ) {
101
+ this . _logErrorMessage ( e ) ;
102
+ throw e ;
103
+ }
106
104
} ,
107
105
108
- willActivate : function ( /* context */ ) {
109
- var redisDeployClient = this . readConfig ( 'redisDeployClient' ) ;
110
- var keyPrefix = this . readConfig ( 'keyPrefix' ) ;
106
+ async willActivate ( /* context */ ) {
107
+ let redisDeployClient = this . readConfig ( 'redisDeployClient' ) ;
108
+ let keyPrefix = this . readConfig ( 'keyPrefix' ) ;
111
109
112
- var revisionKey = redisDeployClient . activeRevision ( keyPrefix ) ;
110
+ let previousRevisionKey = await redisDeployClient . activeRevision ( keyPrefix ) ;
111
+ return {
112
+ revisionData : {
113
+ previousRevisionKey
114
+ }
115
+ } ;
116
+ } ,
113
117
114
- return RSVP . resolve ( revisionKey ) . then ( function ( previousRevisionKey ) {
118
+ async activate ( /* context */ ) {
119
+ let redisDeployClient = this . readConfig ( 'redisDeployClient' ) ;
120
+ let revisionKey = this . readConfig ( 'revisionKey' ) ;
121
+ let keyPrefix = this . readConfig ( 'keyPrefix' ) ;
122
+ let activationSuffix = this . readConfig ( 'activationSuffix' ) ;
123
+ let activeContentSuffix = this . readConfig ( 'activeContentSuffix' ) ;
124
+
125
+ this . log ( `Activating revision \`${ revisionKey } \`` , { verbose : true } ) ;
126
+ try {
127
+ await redisDeployClient . activate ( keyPrefix , revisionKey , activationSuffix , activeContentSuffix ) ;
128
+ this . log ( `✔ Activated revision \`${ revisionKey } \`` , { } ) ;
115
129
return {
116
130
revisionData : {
117
- previousRevisionKey : previousRevisionKey
131
+ activatedRevisionKey : revisionKey
118
132
}
119
133
} ;
120
- } ) ;
121
- } ,
122
-
123
- activate : function ( /* context */ ) {
124
- var redisDeployClient = this . readConfig ( 'redisDeployClient' ) ;
125
- var revisionKey = this . readConfig ( 'revisionKey' ) ;
126
- var keyPrefix = this . readConfig ( 'keyPrefix' ) ;
127
- var activationSuffix = this . readConfig ( 'activationSuffix' ) ;
128
- var activeContentSuffix = this . readConfig ( 'activeContentSuffix' ) ;
129
-
130
- this . log ( 'Activating revision `' + revisionKey + '`' , { verbose : true } ) ;
131
- return RSVP . resolve ( redisDeployClient . activate ( keyPrefix , revisionKey , activationSuffix , activeContentSuffix ) )
132
- . then ( this . log . bind ( this , '✔ Activated revision `' + revisionKey + '`' , { } ) )
133
- . then ( function ( ) {
134
- return {
135
- revisionData : {
136
- activatedRevisionKey : revisionKey
137
- }
138
- } ;
139
- } )
140
- . catch ( this . _errorMessage . bind ( this ) ) ;
134
+ } catch ( e ) {
135
+ this . _logErrorMessage ( e ) ;
136
+ throw e ;
137
+ }
141
138
} ,
142
139
143
- didDeploy : function ( /* context */ ) {
140
+ didDeploy ( /* context */ ) {
144
141
var didDeployMessage = this . readConfig ( 'didDeployMessage' ) ;
145
142
if ( didDeployMessage ) {
146
143
this . log ( didDeployMessage ) ;
147
144
}
148
145
} ,
149
146
150
- fetchInitialRevisions : function ( /* context */ ) {
151
- var redisDeployClient = this . readConfig ( 'redisDeployClient' ) ;
152
- var keyPrefix = this . readConfig ( 'keyPrefix' ) ;
153
-
154
- this . log ( 'Listing initial revisions for key: `' + keyPrefix + '`' , { verbose : true } ) ;
155
- return RSVP . resolve ( redisDeployClient . fetchRevisions ( keyPrefix ) )
156
- . then ( function ( revisions ) {
157
- return {
158
- initialRevisions : revisions
159
- } ;
160
- } )
161
- . catch ( this . _errorMessage . bind ( this ) ) ;
147
+ async fetchInitialRevisions ( /* context */ ) {
148
+ let redisDeployClient = this . readConfig ( 'redisDeployClient' ) ;
149
+ let keyPrefix = this . readConfig ( 'keyPrefix' ) ;
150
+
151
+ this . log ( `Listing initial revisions for key: \`${ keyPrefix } \`` , { verbose : true } ) ;
152
+ try {
153
+ let initialRevisions = await redisDeployClient . fetchRevisions ( keyPrefix ) ;
154
+ return {
155
+ initialRevisions
156
+ } ;
157
+ } catch ( e ) {
158
+ this . _logErrorMessage ( e ) ;
159
+ throw e ;
160
+ }
162
161
} ,
163
162
164
- fetchRevisions : function ( /* context */ ) {
165
- var redisDeployClient = this . readConfig ( 'redisDeployClient' ) ;
166
- var keyPrefix = this . readConfig ( 'keyPrefix' ) ;
167
-
168
- this . log ( 'Listing revisions for key: `' + keyPrefix + '`' ) ;
169
- return RSVP . resolve ( redisDeployClient . fetchRevisions ( keyPrefix ) )
170
- . then ( function ( revisions ) {
171
- return {
172
- revisions : revisions
173
- } ;
174
- } )
175
- . catch ( this . _errorMessage . bind ( this ) ) ;
163
+ async fetchRevisions ( /* context */ ) {
164
+ let redisDeployClient = this . readConfig ( 'redisDeployClient' ) ;
165
+ let keyPrefix = this . readConfig ( 'keyPrefix' ) ;
166
+
167
+ this . log ( `Listing revisions for key: \`${ keyPrefix } \`` ) ;
168
+ try {
169
+ let revisions = await redisDeployClient . fetchRevisions ( keyPrefix ) ;
170
+ return {
171
+ revisions
172
+ } ;
173
+ } catch ( e ) {
174
+ this . _logErrorMessage ( e ) ;
175
+ throw e ;
176
+ }
176
177
} ,
177
178
178
- _readFileContents : function ( path ) {
179
- return readFile ( path )
180
- . then ( function ( buffer ) {
181
- return buffer . toString ( ) ;
182
- } ) ;
179
+ async _readFileContents ( path ) {
180
+ let buffer = await fs . promises . readFile ( path ) ;
181
+ return buffer . toString ( ) ;
183
182
} ,
184
183
185
- _uploadSuccessMessage : function ( key ) {
186
- this . log ( 'Uploaded with key `' + key + '`' , { verbose : true } ) ;
187
- return RSVP . resolve ( key ) ;
184
+ _logUploadSuccessMessage ( key ) {
185
+ this . log ( `Uploaded with key \`${ key } \`` , { verbose : true } ) ;
188
186
} ,
189
187
190
- _errorMessage : function ( error ) {
188
+ _logErrorMessage ( error ) {
191
189
this . log ( error , { color : 'red' } ) ;
192
- return RSVP . reject ( error ) ;
193
190
}
194
191
} ) ;
195
192
0 commit comments