@@ -5,6 +5,7 @@ var childProcess = require('child_process');
55var net = require ( 'net' ) ;
66var readline = require ( 'readline' ) ;
77var url = require ( 'url' ) ;
8+ var timeoutSeconds = 50 ;
89
910module . exports = {
1011 startAngularCliBuilder : function startAngularCliBuilder ( callback , appName ) {
@@ -14,7 +15,9 @@ module.exports = {
1415 '--watch'
1516 ] ) ;
1617 proc . stdout . pipe ( process . stdout ) ;
17- waitForLine ( proc . stdout , / c h u n k / , function ( ) { callback ( ) } ) ;
18+ waitForLine ( proc . stdout , / c h u n k / , function ( ) { callback ( ) } , timeoutSeconds * 1000 , function ( ) {
19+ callback ( 'The ng build process timed out after ' + timeoutSeconds + ' seconds. Check the output log for error information.' ) ;
20+ } ) ;
1821 } ,
1922
2023 startAngularCliServer : function startAngularCliServer ( callback , options ) {
@@ -42,20 +45,36 @@ module.exports = {
4245 callback ( null , {
4346 Port : parseInt ( devServerUrl . port )
4447 } ) ;
48+ } , timeoutSeconds * 1000 , function ( ) {
49+ callback ( 'The @angular/cli service did not start within the timeout period of ' + timeoutSeconds + ' seconds. Check the output log for error information.' ) ;
4550 } ) ;
4651 } ) ;
4752 }
4853} ;
4954
50- function waitForLine ( stream , regex , callback ) {
55+ function waitForLine ( stream , regex , successCallback , timeoutMilliseconds , timeoutCallback ) {
5156 var lineReader = readline . createInterface ( { input : stream } ) ;
5257 var listener = function ( line ) {
5358 var matches = regex . exec ( line ) ;
5459 if ( matches ) {
5560 lineReader . removeListener ( 'line' , listener ) ;
56- callback ( matches ) ;
61+ if ( timeoutId !== null ) {
62+ clearTimeout ( timeoutId ) ;
63+ }
64+ successCallback ( matches ) ;
5765 }
5866 } ;
67+
68+ var timeoutId = null ;
69+ if ( timeoutMilliseconds > 0 ) {
70+ timeoutId = setTimeout ( function ( ) {
71+ lineReader . removeListener ( 'line' , listener ) ;
72+ if ( timeoutCallback ) {
73+ timeoutCallback ( ) ;
74+ }
75+ } , timeoutMilliseconds ) ;
76+ }
77+
5978 lineReader . addListener ( 'line' , listener ) ;
6079}
6180
0 commit comments