11'use strict' ;
22var util = require ( 'util' ) ;
3- var ScriptBase = require ( '../script-base.js ' ) ;
3+ var yeoman = require ( 'yeoman-generator ' ) ;
44var exec = require ( 'child_process' ) . exec ;
55var chalk = require ( 'chalk' ) ;
6+ var path = require ( 'path' ) ;
67
78var Generator = module . exports = function Generator ( ) {
8- ScriptBase . apply ( this , arguments ) ;
9+ yeoman . generators . NamedBase . apply ( this , arguments ) ;
10+ this . argument ( 'deployedname' , { type : String , optional : true , required : false } ) ;
11+
12+ try {
13+ this . appname = require ( path . join ( process . cwd ( ) , 'bower.json' ) ) . name ;
14+ } catch ( e ) {
15+ this . appname = path . basename ( process . cwd ( ) ) ;
16+ }
17+
18+ this . deployedname = this . deployedname ? this . deployedname : this . _ . slugify ( this . _ . humanize ( this . appname ) ) ;
19+ this . sourceRoot ( path . join ( __dirname , '../templates/deploy' ) ) ;
920} ;
1021
11- util . inherits ( Generator , ScriptBase ) ;
22+ util . inherits ( Generator , yeoman . generators . NamedBase ) ;
23+
24+ Generator . prototype . askForName = function askForName ( ) {
25+ var done = this . async ( ) ;
26+
27+ var prompts = [ {
28+ name : 'deployedname' ,
29+ message : 'Name to deploy as:' ,
30+ default : this . appname
31+ } ] ;
32+
33+ this . prompt ( prompts , function ( props ) {
34+ this . deployedname = props . deployedname ;
35+ done ( ) ;
36+ } . bind ( this ) ) ;
37+ } ;
1238
1339Generator . prototype . checkInstallation = function checkInstallation ( ) {
1440 var done = this . async ( ) ;
@@ -41,7 +67,7 @@ Generator.prototype.checkInstallation = function checkInstallation() {
4167
4268Generator . prototype . copyProcfile = function copyProcfile ( ) {
4369 if ( this . name . toLowerCase ( ) !== "heroku" ) return ;
44- this . template ( '../deploy/ heroku/Procfile' , 'dist/Procfile' ) ;
70+ this . template ( 'heroku/Procfile' , 'dist/Procfile' ) ;
4571} ;
4672
4773Generator . prototype . gruntBuild = function gruntBuild ( ) {
@@ -62,7 +88,7 @@ Generator.prototype.gruntBuild = function gruntBuild() {
6288Generator . prototype . enableOpenShiftHotDeploy = function enableOpenshiftHotDeploy ( ) {
6389 if ( this . name . toLowerCase ( ) !== "openshift" ) return ;
6490 this . log ( "enabling HotDeploy for OpenShift" ) ;
65- this . template ( '../deploy/ openshift/hot_deploy' , 'dist/.openshift/markers/hot_deploy' ) ;
91+ this . template ( 'openshift/hot_deploy' , 'dist/.openshift/markers/hot_deploy' ) ;
6692} ;
6793
6894Generator . prototype . gitInit = function gitInit ( ) {
@@ -123,7 +149,7 @@ Generator.prototype.rhcAppShow = function rhcAppShow() {
123149 var done = this . async ( ) ;
124150
125151 this . log ( "Checking for an existing OpenShift hosting evironment..." ) ;
126- exec ( 'rhc app show ' + this . appname + ' --noprompt' , { cwd : 'dist' } , function ( err , stdout , stderr ) {
152+ exec ( 'rhc app show ' + this . deployedname + ' --noprompt' , { cwd : 'dist' } , function ( err , stdout , stderr ) {
127153 var lines = stdout . split ( '\n' ) ;
128154 var dist_repo = '' ;
129155 if ( stdout . search ( 'Not authenticated' ) >= 0 || stdout . search ( 'Invalid characters found in login' ) >= 0 ) {
@@ -148,7 +174,7 @@ Generator.prototype.rhcAppCreate = function rhcAppCreate() {
148174 if ( this . name . toLowerCase ( ) !== "openshift" || typeof this . dist_repo_url !== 'undefined' ) return ;
149175 var done = this . async ( ) ;
150176 this . log ( "Creating your OpenShift hosting evironment..." ) ;
151- exec ( 'rhc app create ' + this . appname + ' nodejs-0.10 mongodb-2.4 -s --noprompt --no-git NODE_ENV=production' , { cwd : 'dist' } , function ( err , stdout , stderr ) {
177+ exec ( 'rhc app create ' + this . deployedname + ' nodejs-0.10 mongodb-2.4 -s --noprompt --no-git NODE_ENV=production' , { cwd : 'dist' } , function ( err , stdout , stderr ) {
152178 var lines = stdout . split ( '\n' ) ;
153179 this . log ( stdout ) ;
154180 if ( stdout . search ( 'Not authenticated' ) >= 0 || stdout . search ( 'Invalid characters found in login' ) >= 0 ) {
@@ -198,7 +224,7 @@ Generator.prototype.gitForcePush = function gitForcePush() {
198224 var host_url = '' ;
199225 this . log ( 'stdout: ' + stdout ) ;
200226 var before_hostname = 'ssh://xxxxxxxxxxxxxxxxxxxxxxxx@' . length ;
201- var after_hostname = this . dist_repo_url . length - ( this . appname . length + 12 ) ;
227+ var after_hostname = this . dist_repo_url . length - ( this . deployedname . length + 12 ) ;
202228 host_url = 'http://' + this . dist_repo_url . slice ( before_hostname , after_hostname ) ;
203229
204230 this . log ( chalk . green ( 'You\'re all set! Your app should now be live at \n\t' + chalk . bold ( host_url ) ) ) ;
@@ -215,7 +241,7 @@ Generator.prototype.herokuCreate = function herokuCreate() {
215241 if ( this . name . toLowerCase ( ) !== "heroku" ) return ;
216242 var done = this . async ( ) ;
217243
218- exec ( 'heroku apps:create && heroku config:set NODE_ENV=production' , { cwd : 'dist' } , function ( err , stdout , stderr ) {
244+ exec ( 'heroku apps:create ' + this . deployedname + ' && heroku config:set NODE_ENV=production', { cwd : 'dist' } , function ( err , stdout , stderr ) {
219245 if ( err ) {
220246 this . log . error ( err ) ;
221247 } else {
0 commit comments