|
1 | 1 | 'use strict'; |
2 | 2 | var util = require('util'); |
3 | 3 | var yeoman = require('yeoman-generator'); |
4 | | -var exec = require('child_process').exec; |
| 4 | +var childProcess = require('child_process'); |
5 | 5 | var chalk = require('chalk'); |
6 | 6 | var path = require('path'); |
| 7 | +var exec = childProcess.exec; |
| 8 | +var spawn = childProcess.spawn; |
7 | 9 |
|
8 | 10 | var Generator = module.exports = function Generator() { |
9 | 11 | yeoman.generators.Base.apply(this, arguments); |
@@ -66,14 +68,14 @@ Generator.prototype.gitRemoteCheck = function gitRemoteCheck() { |
66 | 68 | if(this.abort || typeof this.dist_repo_url !== 'undefined') return; |
67 | 69 | var done = this.async(); |
68 | 70 |
|
69 | | - this.log(chalk.bold("\nChecking for an existing git remote named '"+this.deployedName+"'...")); |
| 71 | + this.log(chalk.bold("\nChecking for an existing git remote named '"+'openshift'+"'...")); |
70 | 72 | exec('git remote -v', { cwd: 'dist' }, function (err, stdout, stderr) { |
71 | 73 | var lines = stdout.split('\n'); |
72 | 74 | var dist_repo = ''; |
73 | 75 | if (err && stderr.search('DL is deprecated') === -1) { |
74 | 76 | this.log.error(err); |
75 | 77 | } else { |
76 | | - var repo_url_finder = new RegExp(this.deployedName+"[ ]*"); |
| 78 | + var repo_url_finder = new RegExp('openshift'+"[ ]*"); |
77 | 79 | lines.forEach(function(line) { |
78 | 80 | if(line.search(repo_url_finder) === 0 && dist_repo === '') { |
79 | 81 | var dist_repo_detailed = line.slice(line.match(repo_url_finder)[0].length); |
@@ -166,7 +168,7 @@ Generator.prototype.gitRemoteAdd = function gitRemoteAdd() { |
166 | 168 | var done = this.async(); |
167 | 169 | this.log(chalk.bold("\nAdding remote repo url: "+this.dist_repo_url)); |
168 | 170 |
|
169 | | - var child = exec('git remote add '+this.deployedName+' '+this.dist_repo_url, { cwd: 'dist' }, function (err, stdout, stderr) { |
| 171 | + var child = exec('git remote add '+'openshift'+' '+this.dist_repo_url, { cwd: 'dist' }, function (err, stdout, stderr) { |
170 | 172 | if (err) { |
171 | 173 | this.log.error(err); |
172 | 174 | } else { |
@@ -229,58 +231,70 @@ Generator.prototype.gitCommit = function gitInit() { |
229 | 231 | }; |
230 | 232 |
|
231 | 233 | Generator.prototype.gitForcePush = function gitForcePush() { |
232 | | - if(this.abort || !this.openshift_remote_exists ) return; |
| 234 | + if (this.abort || !this.openshift_remote_exists) return; |
233 | 235 | var done = this.async(); |
234 | | - this.log(chalk.bold("\nUploading your initial application code.\n This may take "+chalk.cyan('several minutes')+" depending on your connection speed...")); |
| 236 | + this.log(chalk.bold("\nUploading your initial application code.\n This may take " + chalk.cyan('several minutes') + " depending on your connection speed...")); |
235 | 237 |
|
236 | | - var child = exec('git push -f '+this.deployedName+' master', { cwd: 'dist' }, function (err, stdout, stderr) { |
237 | | - if (err) { |
238 | | - this.log.error(err); |
239 | | - } else { |
240 | | - var host_url = ''; |
241 | | - var hasWarning = false; |
242 | | - var before_hostname = this.dist_repo_url.indexOf('@') + 1; |
243 | | - var after_hostname = this.dist_repo_url.length - ( this.deployedName.length + 12 ); |
244 | | - host_url = 'http://' + this.dist_repo_url.slice(before_hostname, after_hostname); |
245 | | - |
246 | | - if(this.filters.socketio) { |
247 | | - this.log(chalk.yellow('Openshift websockets use port 8000, you will need to update the client to connect to the correct port for sockets to work.\n\t' + 'in `/client/app/components/socket/socket.service`: ' + chalk.bold('var ioSocket = io.connect(\'' + host_url + ':8000' + '\')' + '\n'))); |
248 | | - hasWarning = true; |
249 | | - } |
| 238 | + var push = spawn('git', ['push', '-f', 'openshift', 'master'], {cwd: 'dist'}); |
| 239 | + var error = null; |
250 | 240 |
|
251 | | - if(this.filters.facebookAuth) { |
252 | | - this.log(chalk.yellow('You will need to set environment variables for facebook auth:\n\t' + |
253 | | - chalk.bold('rhc set-env FACEBOOK_ID=id -a ' + this.deployedName + '\n\t') + |
254 | | - chalk.bold('rhc set-env FACEBOOK_SECRET=secret -a ' + this.deployedName + '\n'))); |
255 | | - hasWarning = true; |
256 | | - } |
257 | | - if(this.filters.googleAuth) { |
258 | | - this.log(chalk.yellow('You will need to set environment variables for google auth:\n\t' + |
259 | | - chalk.bold('rhc set-env GOOGLE_ID=id -a ' + this.deployedName + '\n\t') + |
260 | | - chalk.bold('rhc set-env GOOGLE_SECRET=secret -a ' + this.deployedName + '\n'))); |
261 | | - hasWarning = true; |
262 | | - } |
263 | | - if(this.filters.twitterAuth) { |
264 | | - this.log(chalk.yellow('You will need to set environment variables for twitter auth:\n\t' + |
265 | | - chalk.bold('rhc set-env TWITTER_ID=id -a ' + this.deployedName + '\n\t') + |
266 | | - chalk.bold('rhc set-env TWITTER_SECRET=secret -a ' + this.deployedName + '\n'))); |
267 | | - hasWarning = true; |
268 | | - } |
| 241 | + push.stderr.on('data', function (data) { |
| 242 | + var output = data.toString(); |
| 243 | + this.log.error(output); |
| 244 | + }.bind(this)); |
269 | 245 |
|
270 | | - this.log(chalk.green('\nYour app should now be live at \n\t' + chalk.bold(host_url))); |
271 | | - if(hasWarning) { |
272 | | - this.log(chalk.green('\nYou may need to address the issues mentioned above and restart the server for the app to work correctly \n\t' + |
273 | | - 'rhc app-restart -a ' + this.deployedName)); |
274 | | - } |
275 | | - this.log(chalk.yellow('After app modification run\n\t' + chalk.bold('grunt build') + |
276 | | - '\nThen enter the dist folder to commit these updates:\n\t' + chalk.bold('cd dist && git add -A && git commit -m "describe your changes here"'))); |
277 | | - this.log(chalk.green('Finally, deploy your updated build to OpenShift with\n\t' + chalk.bold('git push -f '+this.deployedName+' master'))); |
| 246 | + push.stdout.on('data', function (data) { |
| 247 | + var output = data.toString(); |
| 248 | + this.log.stdin(output); |
| 249 | + }.bind(this)); |
| 250 | + |
| 251 | + push.on('exit', function (code) { |
| 252 | + if (code !== 0) { |
| 253 | + this.abort = true; |
| 254 | + return done(); |
278 | 255 | } |
279 | 256 | done(); |
280 | 257 | }.bind(this)); |
| 258 | +}; |
281 | 259 |
|
282 | | - child.stdout.on('data', function(data) { |
283 | | - var output = data.toString(); |
284 | | - this.log(output); |
| 260 | +Generator.prototype.restartApp = function restartApp() { |
| 261 | + if(this.abort || !this.openshift_remote_exists ) return; |
| 262 | + this.log(chalk.bold("\nRestarting your openshift app.\n")); |
| 263 | + |
| 264 | + var child = exec('rhc app restart -a ' + this.deployedName, function(err, stdout, stderr) { |
| 265 | + |
| 266 | + var host_url = ''; |
| 267 | + var hasWarning = false; |
| 268 | + var before_hostname = this.dist_repo_url.indexOf('@') + 1; |
| 269 | + var after_hostname = this.dist_repo_url.length - ( 'openshift'.length + 12 ); |
| 270 | + host_url = 'http://' + this.dist_repo_url.slice(before_hostname, after_hostname); |
| 271 | + |
| 272 | + if(this.filters.facebookAuth) { |
| 273 | + this.log(chalk.yellow('You will need to set environment variables for facebook auth:\n\t' + |
| 274 | + chalk.bold('rhc set-env FACEBOOK_ID=id -a ' + this.deployedName + '\n\t') + |
| 275 | + chalk.bold('rhc set-env FACEBOOK_SECRET=secret -a ' + this.deployedName + '\n'))); |
| 276 | + hasWarning = true; |
| 277 | + } |
| 278 | + if(this.filters.googleAuth) { |
| 279 | + this.log(chalk.yellow('You will need to set environment variables for google auth:\n\t' + |
| 280 | + chalk.bold('rhc set-env GOOGLE_ID=id -a ' + this.deployedName + '\n\t') + |
| 281 | + chalk.bold('rhc set-env GOOGLE_SECRET=secret -a ' + this.deployedName + '\n'))); |
| 282 | + hasWarning = true; |
| 283 | + } |
| 284 | + if(this.filters.twitterAuth) { |
| 285 | + this.log(chalk.yellow('You will need to set environment variables for twitter auth:\n\t' + |
| 286 | + chalk.bold('rhc set-env TWITTER_ID=id -a ' + this.deployedName + '\n\t') + |
| 287 | + chalk.bold('rhc set-env TWITTER_SECRET=secret -a ' + this.deployedName + '\n'))); |
| 288 | + hasWarning = true; |
| 289 | + } |
| 290 | + |
| 291 | + this.log(chalk.green('\nYour app should now be live at \n\t' + chalk.bold(host_url))); |
| 292 | + if(hasWarning) { |
| 293 | + this.log(chalk.green('\nYou may need to address the issues mentioned above and restart the server for the app to work correctly \n\t' + |
| 294 | + 'rhc app-restart -a ' + this.deployedName)); |
| 295 | + } |
| 296 | + this.log(chalk.yellow('After app modification run\n\t' + chalk.bold('grunt build') + |
| 297 | + '\nThen enter the dist folder to commit these updates:\n\t' + chalk.bold('cd dist && git add -A && git commit -m "describe your changes here"'))); |
| 298 | + this.log(chalk.green('Finally, deploy your updated build to OpenShift with\n\t' + chalk.bold('git push -f '+'openshift'+' master'))); |
285 | 299 | }.bind(this)); |
286 | 300 | }; |
0 commit comments