@@ -26,20 +26,34 @@ module.exports = {
26
26
} ) ;
27
27
}
28
28
29
- function _beginMessage ( ui , indexPath ) {
29
+ function _beginUploadMessage ( ui , indexPath ) {
30
30
ui . write ( blue ( '| ' ) ) ;
31
31
ui . write ( blue ( '- Uploading `' + indexPath + '`\n' ) ) ;
32
32
33
33
return Promise . resolve ( ) ;
34
34
}
35
35
36
+ function _beginActivateMessage ( ui , revisionKey ) {
37
+ ui . write ( blue ( '| ' ) ) ;
38
+ ui . write ( blue ( '- Activating revision `' + revisionKey + '`\n' ) ) ;
39
+
40
+ return Promise . resolve ( ) ;
41
+ }
42
+
36
43
function _successMessage ( ui , key ) {
37
44
ui . write ( blue ( '| ' ) ) ;
38
45
ui . write ( blue ( '- Uploaded with key `' + key + '`\n' ) ) ;
39
46
40
47
return Promise . resolve ( key ) ;
41
48
}
42
49
50
+ function _activationSuccessMessage ( ui , revisionKey ) {
51
+ ui . write ( blue ( '| ' ) ) ;
52
+ ui . write ( blue ( '- ✔ Activated revision `' + revisionKey + '`\n' ) ) ;
53
+
54
+ return Promise . resolve ( ) ;
55
+ }
56
+
43
57
function _errorMessage ( ui , error ) {
44
58
ui . write ( blue ( '| ' ) ) ;
45
59
ui . write ( red ( '- ' + error + '`\n' ) ) ;
@@ -56,30 +70,56 @@ module.exports = {
56
70
var config = deployment . config [ this . name ] = deployment . config [ this . name ] || { } ;
57
71
var projectName = deployment . project . name ( ) ;
58
72
59
- return validateConfig ( ui , config , projectName )
60
- . then ( function ( ) {
61
- ui . write ( blue ( '| ' ) ) ;
62
- ui . writeLine ( blue ( '- config ok' ) ) ;
63
- } ) ;
73
+ return this . _resolvePipelineData ( config , context )
74
+ . then ( validateConfig . bind ( this , ui , config , projectName ) ) ;
64
75
} ,
65
76
66
77
upload : function ( context ) {
67
- var deployment = context . deployment ;
68
- var ui = deployment . ui ;
69
- var config = deployment . config [ this . name ] || { } ;
70
- var redis = context . redisClient || new Redis ( config ) ;
71
- var tag = context . tag ;
78
+ var deployment = context . deployment ;
79
+ var ui = deployment . ui ;
80
+ var config = deployment . config [ this . name ] || { } ;
81
+ var redis = context . redisClient || new Redis ( config ) ;
82
+ var revisionKey = this . _resolveConfigValue ( 'revisionKey' , config , context ) ;
72
83
73
84
var filePattern = config . filePattern ;
74
85
75
- return _beginMessage ( ui , filePattern )
86
+ return _beginUploadMessage ( ui , filePattern )
76
87
. then ( _readFileContents . bind ( this , filePattern ) )
77
- . then ( redis . upload . bind ( redis , config . keyPrefix , tag ) )
88
+ . then ( redis . upload . bind ( redis , config . keyPrefix , revisionKey ) )
78
89
. then ( _successMessage . bind ( this , ui ) )
79
90
. then ( function ( key ) {
80
91
return { redisKey : key }
81
92
} )
82
93
. catch ( _errorMessage . bind ( this , ui ) ) ;
94
+ } ,
95
+
96
+ activate : function ( context ) {
97
+ var deployment = context . deployment ;
98
+ var ui = deployment . ui ;
99
+ var config = deployment . config [ this . name ] || { } ;
100
+ var redis = context . redisClient || new Redis ( config ) ;
101
+ var revisionKey = this . _resolveConfigValue ( 'revisionKey' , config , context ) ;
102
+
103
+ return _beginActivateMessage ( ui , revisionKey )
104
+ . then ( redis . activate . bind ( redis , config . keyPrefix , revisionKey ) )
105
+ . then ( _activationSuccessMessage . bind ( this , ui , revisionKey ) )
106
+ . catch ( _errorMessage . bind ( this , ui ) ) ;
107
+ } ,
108
+
109
+ _resolvePipelineData : function ( config , context ) {
110
+ config . revisionKey = config . revisionKey || function ( context ) {
111
+ return context . deployment . commandLineArgs . revisionKey || context . revisionKey ;
112
+ } ;
113
+
114
+ return Promise . resolve ( ) ;
115
+ } ,
116
+
117
+ _resolveConfigValue : function ( key , config , context ) {
118
+ if ( typeof config [ key ] === 'function' ) {
119
+ return config [ key ] ( context ) ;
120
+ }
121
+
122
+ return config [ key ] ;
83
123
}
84
124
} ;
85
125
}
0 commit comments