1
1
'use strict' ;
2
2
var util = require ( 'util' ) ;
3
- var ScriptBase = require ( '../script-base.js ' ) ;
3
+ var yeoman = require ( 'yeoman-generator ' ) ;
4
4
var exec = require ( 'child_process' ) . exec ;
5
5
var chalk = require ( 'chalk' ) ;
6
+ var path = require ( 'path' ) ;
6
7
7
8
var 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' ) ) ;
9
20
} ;
10
21
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
+ } ;
12
38
13
39
Generator . prototype . checkInstallation = function checkInstallation ( ) {
14
40
var done = this . async ( ) ;
@@ -41,7 +67,7 @@ Generator.prototype.checkInstallation = function checkInstallation() {
41
67
42
68
Generator . prototype . copyProcfile = function copyProcfile ( ) {
43
69
if ( this . name . toLowerCase ( ) !== "heroku" ) return ;
44
- this . template ( '../deploy/ heroku/Procfile' , 'dist/Procfile' ) ;
70
+ this . template ( 'heroku/Procfile' , 'dist/Procfile' ) ;
45
71
} ;
46
72
47
73
Generator . prototype . gruntBuild = function gruntBuild ( ) {
@@ -62,7 +88,7 @@ Generator.prototype.gruntBuild = function gruntBuild() {
62
88
Generator . prototype . enableOpenShiftHotDeploy = function enableOpenshiftHotDeploy ( ) {
63
89
if ( this . name . toLowerCase ( ) !== "openshift" ) return ;
64
90
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' ) ;
66
92
} ;
67
93
68
94
Generator . prototype . gitInit = function gitInit ( ) {
@@ -123,7 +149,7 @@ Generator.prototype.rhcAppShow = function rhcAppShow() {
123
149
var done = this . async ( ) ;
124
150
125
151
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 ) {
127
153
var lines = stdout . split ( '\n' ) ;
128
154
var dist_repo = '' ;
129
155
if ( stdout . search ( 'Not authenticated' ) >= 0 || stdout . search ( 'Invalid characters found in login' ) >= 0 ) {
@@ -148,7 +174,7 @@ Generator.prototype.rhcAppCreate = function rhcAppCreate() {
148
174
if ( this . name . toLowerCase ( ) !== "openshift" || typeof this . dist_repo_url !== 'undefined' ) return ;
149
175
var done = this . async ( ) ;
150
176
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 ) {
152
178
var lines = stdout . split ( '\n' ) ;
153
179
this . log ( stdout ) ;
154
180
if ( stdout . search ( 'Not authenticated' ) >= 0 || stdout . search ( 'Invalid characters found in login' ) >= 0 ) {
@@ -198,7 +224,7 @@ Generator.prototype.gitForcePush = function gitForcePush() {
198
224
var host_url = '' ;
199
225
this . log ( 'stdout: ' + stdout ) ;
200
226
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 ) ;
202
228
host_url = 'http://' + this . dist_repo_url . slice ( before_hostname , after_hostname ) ;
203
229
204
230
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() {
215
241
if ( this . name . toLowerCase ( ) !== "heroku" ) return ;
216
242
var done = this . async ( ) ;
217
243
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 ) {
219
245
if ( err ) {
220
246
this . log . error ( err ) ;
221
247
} else {
0 commit comments