@@ -198,23 +198,28 @@ function runWithGulp(argv, taskInstance){
198198 } ) ;
199199 var downloadGulp = false ;
200200 return deferred . promise . then (
201- function ( ) {
201+ function ( ) {
202202 downloadGulp = true ;
203- return downloadDefaultGulpfile ( ) ;
203+ return downloadDefaultGulpfile ( cmdName ) . then (
204+ installGulpfilePackages ,
205+ function ( err ) {
206+ console . error ( 'There was an error downloading the default gulpfile: ' + err ) ;
207+ process . exit ( 1 ) ;
208+ }
209+ ) . then (
210+ function ( ) {
211+ console . success ( 'Npm packages installed successfully. Try running \'' + cmdName + '\' again.' ) ;
212+ } ,
213+ function ( ) {
214+ console . warn ( 'There was an error installing the packages required by the gulpfile.' ) ;
215+ console . warn ( 'You\'ll need to install the following packages manually: ' ) ;
216+ console . warn ( ' ' + requires . join ( ' ' ) ) ;
217+ }
218+ ) ;
204219 } ,
205- function ( ) {
220+ function ( ) {
206221 return Q . fcall ( taskInstance . run . bind ( taskInstance ) , Cli , argv ) ;
207222 }
208- ) . then (
209- function ( ) {
210- if ( downloadGulp ) {
211- console . success ( 'Successfully downloaded gulpfile. Try running \'' + cmdName + '\' again.' ) ;
212- }
213- } ,
214- function ( err ) {
215- console . error ( 'There was an error downloading the default gulpfile: ' + err ) ;
216- process . exit ( 1 ) ;
217- }
218223 ) ;
219224 }
220225 }
@@ -254,7 +259,7 @@ function downloadDefaultGulpfile(){
254259 var branch = project . get ( 'typescript' ) ? 'typescript' : 'master' ;
255260 var url = 'https://raw.githubusercontent.com/driftyco/ionic2-app-base/' + branch + '/gulpfile.js' ;
256261
257- console . info ( ( 'Downloading default gulpfile from: ' + url ) ) ;
262+ console . info ( '\nDownloading default gulpfile from: ' + url ) ;
258263
259264 fileStream . on ( 'open' , function ( ) {
260265 https . get ( url , function ( res ) {
@@ -273,6 +278,26 @@ function downloadDefaultGulpfile(){
273278 return deferred . promise ;
274279}
275280
281+ function installGulpfilePackages ( cmdName ) {
282+ var detective = require ( 'detective' ) ;
283+ var requires = detective ( fs . readFileSync ( 'gulpfile.js' ) ) ;
284+ var deferred = Q . defer ( ) ;
285+
286+ console . success ( 'Successfully downloaded gulpfile.\n' ) ;
287+ console . info ( 'Now installing npm packages used by the gulpfile: ' ) ;
288+ console . info ( ' ' + requires . join ( ' ' ) + '\n' ) ;
289+
290+ var npmInstall = require ( 'child_process' ) . spawn ( 'npm' , [ 'install' , '--save-dev' ] . concat ( requires ) ) ;
291+ npmInstall . stdout . on ( 'data' , function ( data ) { logging . logger . debug ( data ) } ) ;
292+ npmInstall . stderr . on ( 'data' , function ( data ) { logging . logger . debug ( data ) } ) ;
293+ npmInstall . on ( 'error' , function ( err ) { console . error ( err ) } ) ;
294+ npmInstall . on ( 'exit' , function ( code ) {
295+ code !== 0 ? deferred . reject ( ) : deferred . resolve ( ) ;
296+ } ) ;
297+
298+ return deferred . promise ;
299+ }
300+
276301
277302function logEvents ( gulpInst , finalTaskNames ) {
278303 gulpInst . on ( 'task_start' , function ( e ) {
0 commit comments