1
1
'use strict' ;
2
- var util = require ( 'util' ) ;
3
- var yeoman = require ( 'yeoman-generator' ) ;
4
- var exec = require ( 'child_process' ) . exec ;
5
2
var chalk = require ( 'chalk' ) ;
6
- var path = require ( 'path' ) ;
3
+ var yeoman = require ( 'yeoman-generator' ) ;
4
+ var util = require ( 'util' ) ;
7
5
8
6
var Generator = module . exports = function Generator ( ) {
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' ) ) ;
7
+ yeoman . generators . Base . apply ( this , arguments ) ;
20
8
} ;
21
9
22
10
util . inherits ( Generator , yeoman . generators . NamedBase ) ;
23
11
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
- } ;
38
-
39
- Generator . prototype . checkInstallation = function checkInstallation ( ) {
40
- var done = this . async ( ) ;
41
- this . rhcInstalled = false ;
42
- this . herokuInstalled = false ;
43
- if ( this . name . toLowerCase ( ) === "openshift" ) {
44
- exec ( 'rhc --version' , function ( err ) {
45
- if ( err ) {
46
- this . log . error ( 'OpenShift\'s rhc command line interface is not available. ' +
47
- 'You can install it via RubyGems with: gem install rhc' ) ;
48
- } else {
49
- this . rhcInstalled = true ;
50
- }
51
- done ( ) ;
52
- } . bind ( this ) ) ;
53
- } else if ( this . name . toLowerCase ( ) === 'heroku' ) {
54
- exec ( 'heroku --version' , function ( err ) {
55
- if ( err ) {
56
- this . log . error ( 'You don\'t have the Heroku Toolbelt installed. ' +
57
- 'Grab it from https://toolbelt.heroku.com/' ) ;
58
- } else {
59
- this . herokuInstalled = true ;
60
- }
61
- done ( ) ;
62
- } . bind ( this ) ) ;
63
- } else {
64
- done ( ) ;
65
- }
66
- } ;
67
-
68
- Generator . prototype . copyProcfile = function copyProcfile ( ) {
69
- if ( this . name . toLowerCase ( ) !== "heroku" ) return ;
70
- this . template ( 'heroku/Procfile' , 'dist/Procfile' ) ;
71
- } ;
72
-
73
- Generator . prototype . gruntBuild = function gruntBuild ( ) {
74
- if ( this . name . toLowerCase ( ) !== "heroku" &&
75
- this . name . toLowerCase ( ) !== "openshift" ) return ;
76
- var done = this . async ( ) ;
77
-
78
- console . log ( chalk . bold ( 'Building dist folder, please wait...' ) ) ;
79
- exec ( 'grunt build' , function ( err , stdout ) {
80
- console . log ( 'stdout: ' + stdout ) ;
81
- if ( err ) {
82
- this . log . error ( err ) ;
83
- }
84
- done ( ) ;
85
- } . bind ( this ) ) ;
86
- } ;
87
-
88
- Generator . prototype . enableOpenShiftHotDeploy = function enableOpenshiftHotDeploy ( ) {
89
- if ( this . name . toLowerCase ( ) !== "openshift" ) return ;
90
- this . log ( "enabling HotDeploy for OpenShift" ) ;
91
- this . template ( 'openshift/hot_deploy' , 'dist/.openshift/markers/hot_deploy' ) ;
92
- } ;
93
-
94
- Generator . prototype . gitInit = function gitInit ( ) {
95
- var done = this . async ( ) ;
96
- if ( this . name . toLowerCase ( ) === "heroku" ) {
97
- exec ( 'git init && git add -A && git commit -m "Initial commit"' , { cwd : 'dist' } , function ( err ) {
98
- if ( err ) {
99
- this . log . error ( err ) ;
100
- }
101
- done ( ) ;
102
- } . bind ( this ) ) ;
103
- } else if ( this . name . toLowerCase ( ) === "openshift" ) {
104
- exec ( 'git init && git add -A && git commit -m "Generating a fresh angular-fullstack application"' , { cwd : 'dist' } , function ( err , stdout , stderr ) {
105
- this . log ( stdout ) ;
106
- if ( stdout . search ( 'nothing to commit' ) >= 0 ) {
107
- this . log ( 'Re-pushing the existing "dist" build...' ) ;
108
- } else if ( err ) {
109
- this . log . error ( err ) ;
110
- }
111
- done ( ) ;
112
- } . bind ( this ) ) ;
113
- } else {
114
- done ( ) ;
115
- }
116
- } ;
117
-
118
- Generator . prototype . gitRemoteCheck = function gitRemoteCheck ( ) {
119
- this . openshift_remote_exists = false ;
120
- if ( this . name . toLowerCase ( ) !== "openshift" || typeof this . dist_repo_url !== 'undefined' ) return ;
121
- var done = this . async ( ) ;
122
-
123
- this . log ( "Checking for an existing git remote named 'openshift'..." ) ;
124
- exec ( 'git remote -v' , { cwd : 'dist' } , function ( err , stdout , stderr ) {
125
- var lines = stdout . split ( '\n' ) ;
126
- var dist_repo = '' ;
127
- this . log ( 'stdout: ' + stdout ) ;
128
- if ( err ) {
129
- this . log . error ( err ) ;
130
- } else {
131
- var repo_url_finder = / o p e n s h i f t [ ] * / ;
132
- lines . forEach ( function ( line ) {
133
- if ( line . search ( repo_url_finder ) === 0 && dist_repo === '' ) {
134
- var dist_repo_detailed = line . slice ( line . match ( repo_url_finder ) [ 0 ] . length ) ;
135
- dist_repo = dist_repo_detailed . slice ( 0 , dist_repo_detailed . length - 7 ) ;
136
- } } ) ;
137
- if ( dist_repo !== '' ) {
138
- console . log ( "Found an existing git remote for this app: " + dist_repo ) ;
139
- this . dist_repo_url = dist_repo ;
140
- this . openshift_remote_exists = true ;
141
- }
142
- }
143
- done ( ) ;
144
- } . bind ( this ) ) ;
145
- } ;
146
-
147
- Generator . prototype . rhcAppShow = function rhcAppShow ( ) {
148
- if ( this . name . toLowerCase ( ) !== "openshift" || typeof this . dist_repo_url !== 'undefined' ) return ;
149
- var done = this . async ( ) ;
150
-
151
- this . log ( "Checking for an existing OpenShift hosting evironment..." ) ;
152
- exec ( 'rhc app show ' + this . deployedname + ' --noprompt' , { cwd : 'dist' } , function ( err , stdout , stderr ) {
153
- var lines = stdout . split ( '\n' ) ;
154
- var dist_repo = '' ;
155
- if ( stdout . search ( 'Not authenticated' ) >= 0 || stdout . search ( 'Invalid characters found in login' ) >= 0 ) {
156
- this . log . error ( 'Error: Not authenticated. Run "rhc setup" to login to your OpenShift account and try again.' ) ;
157
- } else if ( err ) {
158
- this . log . error ( err ) ;
159
- } else {
160
- this . log ( stdout ) ;
161
- var repo_url_finder = / * G i t U R L : * / ;
162
- lines . forEach ( function ( line ) {
163
- if ( line . search ( repo_url_finder ) === 0 ) {
164
- dist_repo = line . slice ( line . match ( repo_url_finder ) [ 0 ] . length ) ;
165
- console . log ( "Found an existing git remote for this app: " + dist_repo ) ;
166
- } } ) ;
167
- if ( dist_repo !== '' ) this . dist_repo_url = dist_repo ;
168
- }
169
- done ( ) ;
170
- } . bind ( this ) ) ;
171
- } ;
172
-
173
- Generator . prototype . rhcAppCreate = function rhcAppCreate ( ) {
174
- if ( this . name . toLowerCase ( ) !== "openshift" || typeof this . dist_repo_url !== 'undefined' ) return ;
175
- var done = this . async ( ) ;
176
- this . log ( "Creating your OpenShift hosting evironment..." ) ;
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 ) {
178
- var lines = stdout . split ( '\n' ) ;
179
- this . log ( stdout ) ;
180
- if ( stdout . search ( 'Not authenticated' ) >= 0 || stdout . search ( 'Invalid characters found in login' ) >= 0 ) {
181
- this . log . error ( 'Error: Not authenticated. Run "rhc setup" to login to your OpenShift account and try again.' ) ;
182
- } else if ( err ) {
183
- this . log . error ( err ) ;
184
- } else {
185
- var dist_repo = '' ;
186
- var repo_url_finder = / * G i t r e m o t e : * / ;
187
- lines . forEach ( function ( line ) {
188
- if ( line . search ( repo_url_finder ) === 0 ) {
189
- dist_repo = line . slice ( line . match ( repo_url_finder ) [ 0 ] . length ) ;
190
- } } ) ;
191
-
192
- if ( dist_repo !== '' ) this . dist_repo_url = dist_repo ;
193
- this . log ( "New remote git repo at: " + this . dist_repo_url ) ;
194
- }
195
- done ( ) ;
196
- } . bind ( this ) ) ;
197
- } ;
198
-
199
- Generator . prototype . gitRemoteAdd = function gitRemoteAdd ( ) {
200
- if ( this . name . toLowerCase ( ) !== "openshift" || typeof this . dist_repo_url === 'undefined' || this . openshift_remote_exists ) return ;
201
- var done = this . async ( ) ;
202
- this . log ( "Adding remote repo url: " + this . dist_repo_url ) ;
203
-
204
- exec ( 'git remote add openshift ' + this . dist_repo_url , { cwd : 'dist' } , function ( err , stdout , stderr ) {
205
- if ( err ) {
206
- this . log . error ( err ) ;
207
- } else {
208
- this . log ( 'stdout: ' + stdout ) ;
209
- this . openshift_remote_exists = true ;
210
- }
211
- done ( ) ;
212
- } . bind ( this ) ) ;
213
- } ;
214
-
215
- Generator . prototype . gitForcePush = function gitForcePush ( ) {
216
- if ( this . name . toLowerCase ( ) !== "openshift" || ! this . openshift_remote_exists ) return ;
217
- var done = this . async ( ) ;
218
- this . log ( chalk . green ( "Uploading your initial application code.\n This may take " + chalk . bold ( 'several minutes' ) + " depending on your connection speed..." ) ) ;
219
-
220
- exec ( 'git push -f openshift master' , { cwd : 'dist' } , function ( err , stdout , stderr ) {
221
- if ( err ) {
222
- this . log . error ( err ) ;
223
- } else {
224
- var host_url = '' ;
225
- this . log ( 'stdout: ' + stdout ) ;
226
- var before_hostname = 'ssh://xxxxxxxxxxxxxxxxxxxxxxxx@' . length ;
227
- var after_hostname = this . dist_repo_url . length - ( this . deployedname . length + 12 ) ;
228
- host_url = 'http://' + this . dist_repo_url . slice ( before_hostname , after_hostname ) ;
229
-
230
- this . log ( chalk . green ( 'You\'re all set! Your app should now be live at \n\t' + chalk . bold ( host_url ) ) ) ;
231
- this . log ( chalk . yellow ( 'After app modification run\n\t' + chalk . bold ( 'grunt build' ) +
232
- '\nThen enter the dist folder to commit these updates:\n\t' + chalk . bold ( 'cd dist && git commit -am "describe your changes here"' ) ) ) ;
233
- this . log ( chalk . green ( 'Finally, deploy your updated build to OpenShift with\n\t' + chalk . bold ( 'git push openshift master' ) ) ) ;
234
- this . openshift_host_url = host_url ;
235
- }
236
- done ( ) ;
237
- } . bind ( this ) ) ;
238
- } ;
239
-
240
- Generator . prototype . herokuCreate = function herokuCreate ( ) {
241
- if ( this . name . toLowerCase ( ) !== "heroku" ) return ;
242
- var done = this . async ( ) ;
243
-
244
- exec ( 'heroku apps:create ' + this . deployedname + ' && heroku config:set NODE_ENV=production' , { cwd : 'dist' } , function ( err , stdout , stderr ) {
245
- if ( err ) {
246
- this . log . error ( err ) ;
247
- } else {
248
- console . log ( 'stdout: ' + stdout ) ;
249
- console . log ( chalk . green ( 'You\'re all set! Now push to heroku with\n\t' + chalk . bold ( 'git push heroku master' ) +
250
- '\nfrom your new ' + chalk . bold ( 'dist' ) + ' folder' ) ) ;
251
- console . log ( chalk . yellow ( 'After app modification run\n\t' + chalk . bold ( 'grunt build' ) +
252
- '\nthen commit and push the dist folder' ) ) ;
253
- }
254
- done ( ) ;
255
- } . bind ( this ) ) ;
256
- } ;
12
+ Generator . prototype . deprecated = function deprecated ( ) {
13
+ this . log ( chalk . yellow ( chalk . bold ( 'yo angular-fullstack:deploy' ) + ' is deprecated, instead use: \n' ) +
14
+ chalk . green ( 'yo angular-fullstack:heroku' ) + ' or ' + chalk . green ( 'yo angular-fullstack:openshift' ) ) ;
15
+ } ;
0 commit comments