@@ -31,7 +31,7 @@ Generator.prototype.askForRoute = function askForRoute() {
31
31
}
32
32
] ;
33
33
34
- this . prompt ( prompts , function ( props ) {
34
+ this . prompt ( prompts , function ( props ) {
35
35
this . routeName = this . _ . slugify ( props . routeName ) ;
36
36
done ( ) ;
37
37
} . bind ( this ) ) ;
@@ -41,10 +41,10 @@ Generator.prototype.checkInstallation = function checkInstallation() {
41
41
if ( this . abort ) return ;
42
42
var done = this . async ( ) ;
43
43
44
- exec ( 'cf --version' , function ( err ) {
44
+ exec ( 'cf --version' , function ( err ) {
45
45
if ( err ) {
46
46
this . log . error ( 'You don\'t have the Cloud Foundry CLI installed. ' +
47
- 'Grab it from https://github.com/cloudfoundry/cli' ) ;
47
+ 'Grab it from https://github.com/cloudfoundry/cli' ) ;
48
48
this . abort = true ;
49
49
}
50
50
done ( ) ;
@@ -63,7 +63,7 @@ Generator.prototype.askForApiEndpoint = function askForApiEndpoint() {
63
63
}
64
64
] ;
65
65
66
- this . prompt ( prompts , function ( props ) {
66
+ this . prompt ( prompts , function ( props ) {
67
67
this . apiEndpoint = props . apiEndpoint ;
68
68
done ( ) ;
69
69
} . bind ( this ) ) ;
@@ -75,7 +75,7 @@ Generator.prototype.cfInit = function cfInit() {
75
75
76
76
this . log ( chalk . bold ( 'Setting Cloud Foundry api endpoint' ) ) ;
77
77
this . mkdir ( 'dist' ) ;
78
- var child = exec ( 'cf api ' + this . apiEndpoint , { cwd : 'dist' } , function ( err , stdout , stderr ) {
78
+ var child = exec ( 'cf api ' + this . apiEndpoint , { cwd : 'dist' } , function ( err , stdout , stderr ) {
79
79
if ( err ) {
80
80
this . abort = true ;
81
81
this . log . error ( err ) ;
@@ -91,7 +91,7 @@ Generator.prototype.cfInit = function cfInit() {
91
91
done ( ) ;
92
92
} . bind ( this ) ) ;
93
93
94
- child . stdout . on ( 'data' , function ( data ) {
94
+ child . stdout . on ( 'data' , function ( data ) {
95
95
this . log ( this . _ . trim ( data . toString ( ) , "\n\r" ) ) ;
96
96
} . bind ( this ) ) ;
97
97
}
@@ -101,7 +101,7 @@ Generator.prototype.copyProcfile = function copyProcfile() {
101
101
var done = this . async ( ) ;
102
102
this . log ( chalk . bold ( 'Creating Procfile and manifest.yml' ) ) ;
103
103
genUtils . processDirectory ( this , '.' , './dist' ) ;
104
- this . conflicter . resolve ( function ( err ) {
104
+ this . conflicter . resolve ( function ( err ) {
105
105
done ( ) ;
106
106
} ) ;
107
107
} ;
@@ -111,10 +111,10 @@ Generator.prototype.gruntBuild = function gruntBuild() {
111
111
var done = this . async ( ) ;
112
112
113
113
this . log ( chalk . bold ( '\nBuilding dist folder, please wait...' ) ) ;
114
- var child = exec ( 'grunt build' , function ( err , stdout ) {
114
+ var child = exec ( 'grunt build' , function ( err , stdout ) {
115
115
done ( ) ;
116
116
} . bind ( this ) ) ;
117
- child . stdout . on ( 'data' , function ( data ) {
117
+ child . stdout . on ( 'data' , function ( data ) {
118
118
this . log ( data . toString ( ) ) ;
119
119
} . bind ( this ) ) ;
120
120
} ;
@@ -126,8 +126,44 @@ Generator.prototype.cfPush = function cfPush() {
126
126
this . log ( chalk . bold ( "\nUploading your initial application code.\n This may take " + chalk . cyan ( 'several minutes' ) + " depending on your connection speed..." ) ) ;
127
127
128
128
var randomRoute = this . routeName === '' ? '--random-route' : '' ;
129
- var child = exec ( [ 'cf push' , this . appname , randomRoute ] . join ( ' ' ) , { cwd : 'dist' } , function ( err , stdout , stderr ) {
129
+ var child = exec ( [ 'cf push' , this . appname , randomRoute , ' --no-start' ] . join ( ' ' ) , { cwd : 'dist' } , function ( err , stdout , stderr ) {
130
130
if ( err ) {
131
+ this . abort = true ;
132
+ this . log . error ( err ) ;
133
+ } else {
134
+ this . log ( 'stdout: ' + stdout ) ;
135
+ }
136
+ done ( ) ;
137
+ } . bind ( this ) ) ;
138
+ child . stdout . on ( 'data' , function ( data ) {
139
+ this . log ( this . _ . trim ( data . toString ( ) , "\n\r" ) ) ;
140
+ } . bind ( this ) ) ;
141
+ } ;
142
+
143
+ Generator . prototype . cfSetEnvVars = function cfSetEnvVars ( ) {
144
+ if ( this . abort ) return ;
145
+ var done = this . async ( ) ;
146
+
147
+ var child = exec ( 'cf set-env ' + this . appname + ' NODE_ENV production' , { cwd : 'dist' } , function ( err , stdout , stderr ) {
148
+ if ( err ) {
149
+ this . abort = true ;
150
+ this . log . error ( err ) ;
151
+ }
152
+ done ( ) ;
153
+
154
+ } . bind ( this ) ) ;
155
+ child . stdout . on ( 'data' , function ( data ) {
156
+ this . log ( this . _ . trim ( data . toString ( ) , "\n\r" ) ) ;
157
+ } . bind ( this ) ) ;
158
+ } ;
159
+
160
+ Generator . prototype . cfStart = function cfStart ( ) {
161
+ if ( this . abort ) return ;
162
+ var done = this . async ( ) ;
163
+
164
+ var child = exec ( 'cf start ' + this . appname , { cwd : 'dist' } , function ( err , stdout , stderr ) {
165
+ if ( err ) {
166
+ this . abort = true ;
131
167
this . log . error ( err ) ;
132
168
} else {
133
169
var hasWarning = false ;
@@ -139,36 +175,35 @@ Generator.prototype.cfPush = function cfPush() {
139
175
140
176
if ( this . filters . facebookAuth ) {
141
177
this . log ( chalk . yellow ( 'You will need to set environment variables for facebook auth. From `/dist`:\n\t' +
142
- chalk . bold ( 'cf set-env ' + this . appName + ' FACEBOOK_ID appId\n\t' ) +
143
- chalk . bold ( 'cf set-env ' + this . appName + ' FACEBOOK_SECRET secret\n' ) ) ) ;
178
+ chalk . bold ( 'cf set-env ' + this . appname + ' FACEBOOK_ID appId\n\t' ) +
179
+ chalk . bold ( 'cf set-env ' + this . appname + ' FACEBOOK_SECRET secret\n' ) ) ) ;
144
180
hasWarning = true ;
145
181
}
146
182
if ( this . filters . googleAuth ) {
147
183
this . log ( chalk . yellow ( 'You will need to set environment variables for google auth. From `/dist`:\n\t' +
148
- chalk . bold ( 'cf set-env ' + this . appName + ' GOOGLE_ID appId\n\t' ) +
149
- chalk . bold ( 'cf set-env ' + this . appName + ' GOOGLE_SECRET secret\n' ) ) ) ;
184
+ chalk . bold ( 'cf set-env ' + this . appname + ' GOOGLE_ID appId\n\t' ) +
185
+ chalk . bold ( 'cf set-env ' + this . appname + ' GOOGLE_SECRET secret\n' ) ) ) ;
150
186
hasWarning = true ;
151
187
}
152
188
if ( this . filters . twitterAuth ) {
153
189
this . log ( chalk . yellow ( 'You will need to set environment variables for twitter auth. From `/dist`:\n\t' +
154
- chalk . bold ( 'cf set-env ' + this . appName + ' TWITTER_ID appId\n\t' ) +
155
- chalk . bold ( 'cf set-env ' + this . appName + ' TWITTER_SECRET secret\n' ) ) ) ;
190
+ chalk . bold ( 'cf set-env ' + this . appname + ' TWITTER_ID appId\n\t' ) +
191
+ chalk . bold ( 'cf set-env ' + this . appname + ' TWITTER_SECRET secret\n' ) ) ) ;
156
192
hasWarning = true ;
157
193
}
158
194
159
195
this . log ( chalk . green ( '\nYour app should now be live.' ) ) ;
160
196
if ( hasWarning ) {
161
197
this . log ( chalk . green ( '\nYou may need to address the issues mentioned above and restart the server for the app to work correctly.' ) ) ;
162
198
}
163
- /*
164
- todo: build grunt plugin grunt-cf-deploy and add to this generator
165
- this.log(chalk.yellow('After app modification run\n\t' + chalk.bold('grunt build') +
166
- '\nThen deploy with\n\t' + chalk.bold('grunt cfDeploy')));
167
- */
199
+ this . log ( chalk . yellow ( 'After app modification run\n\t' + chalk . bold ( 'grunt build' ) +
200
+ '\nThen deploy (from dist directory ) with\n\t' + chalk . bold ( 'cf push' ) ) ) ;
168
201
}
169
202
done ( ) ;
203
+
170
204
} . bind ( this ) ) ;
171
- child . stdout . on ( 'data' , function ( data ) {
205
+ child . stdout . on ( 'data' , function ( data ) {
172
206
this . log ( this . _ . trim ( data . toString ( ) , "\n\r" ) ) ;
173
207
} . bind ( this ) ) ;
174
- } ;
208
+
209
+ } ;
0 commit comments