1- require ( 'colors' ) ;
2-
31var Cli = { } ;
42var IonicAppLib = require ( 'ionic-app-lib' ) ;
53var IonicStats = require ( './utils/stats' ) ;
@@ -19,6 +17,7 @@ var log = Logging.logger;
1917var Q = require ( 'q' ) ;
2018var helpUtil = require ( './utils/help' ) ;
2119var EOL = require ( 'os' ) . EOL ;
20+ var chalk = require ( 'chalk' ) ;
2221
2322Cli . ALL_TASKS = Tasks ;
2423Cli . IONIC_DASH = 'https://apps.ionic.io' ;
@@ -154,7 +153,7 @@ Cli.run = function run(processArgv) {
154153 // For v2, print a warning as this is most likely not what they want
155154 if ( ! fs . existsSync ( 'node_modules' ) ) {
156155 if ( argv . v2 ) {
157- log . warn ( 'WARN: No node_modules directory found, do you need to run npm install?' . yellow ) ;
156+ log . warn ( chalk . yellow ( 'WARN: No node_modules directory found, do you need to run npm install?' ) ) ;
158157 }
159158 log . debug ( 'node_modules directory not found, not running gulp hooks' ) ;
160159
@@ -173,7 +172,7 @@ Cli.run = function run(processArgv) {
173172 log . info ( '\nDo you need to run `npm install`?\n' ) ;
174173 process . exit ( 1 ) ;
175174 }
176- log . error ( '\nThere is an error in your gulpfile: ' . red ) ;
175+ log . error ( chalk . red ( '\nThere is an error in your gulpfile: ' ) ) ;
177176 log . error ( e . stack + '\n' ) ;
178177 process . exit ( 1 ) ;
179178 }
@@ -188,6 +187,7 @@ Cli.run = function run(processArgv) {
188187 }
189188
190189 if ( ! gulpLoaded ) {
190+
191191 // warn if no build file and it's a command that requires a build step
192192 // but still run the command with no hooks
193193 if ( Cli . isBuildCommand ( taskName ) && argv . v2 && ! npmScripts ) {
@@ -216,8 +216,8 @@ Cli.runWithGulp = function runWithGulp(argv, taskInstance, rawCliArguments) {
216216 } catch ( e ) {
217217
218218 // Empty gulpfile (or one that doesn't require gulp?), and no gulp
219- log . error ( '\nGulpfile detected, but gulp is not installed' . red ) ;
220- log . error ( 'Do you need to run `npm install`?\n' . red ) ;
219+ log . error ( chalk . red ( '\nGulpfile detected, but gulp is not installed' ) ) ;
220+ log . error ( chalk . red ( 'Do you need to run `npm install`?\n' ) ) ;
221221 return process . exit ( 1 ) ;
222222 }
223223
@@ -231,9 +231,9 @@ Cli.runWithGulp = function runWithGulp(argv, taskInstance, rawCliArguments) {
231231 beforeHookPromise = Cli . runGulpHook ( gulp , beforeHook ) ;
232232
233233 } else if ( Cli . isBuildCommand ( cmdName ) && argv . v2 ) {
234- log . warn ( ( 'WARN: No \'' + beforeHook + '\' gulp task found!' ) . yellow ) ;
235- log . warn ( ( 'If your app requires a build step, you may want to ensure it runs before ' +
236- cmdName + '.\n' ) . yellow ) ;
234+ log . warn ( chalk . yellow ( 'WARN: No \'' + beforeHook + '\' gulp task found!' ) ) ;
235+ log . warn ( chalk . yellow ( 'If your app requires a build step, you may want to ensure it runs before ' +
236+ cmdName + '.\n' ) ) ;
237237 }
238238
239239 // run beforeHook
@@ -333,7 +333,7 @@ Cli.runNpmHook = function runNpmHook(hook) {
333333 spawned . stdout . pipe ( process . stdout ) ;
334334 spawned . stdout . on ( 'data' , function ( data ) {
335335 var dataLines = data . toString ( ) . split ( EOL ) ;
336- for ( var i = 0 ; i < dataLines . length ; i ++ ) {
336+ for ( var i = 0 ; i < dataLines . length ; i += 1 ) {
337337 if ( dataLines [ i ] . length ) {
338338 if ( dataLines [ i ] . indexOf ( 'watch ready' ) > - 1 ) {
339339 return q . resolve ( ) ;
@@ -348,7 +348,7 @@ Cli.runNpmHook = function runNpmHook(hook) {
348348 }
349349 return q . resolve ( ) ;
350350 } ) ;
351-
351+
352352 // If this process ends ensure that we killed the spawned child
353353 process . on ( 'exit' , function ( ) {
354354 spawned . kill ( ) ;
@@ -367,8 +367,6 @@ Cli.loadNpmScripts = function loadNpmScripts() {
367367 } catch ( e ) {
368368 throw e ;
369369 }
370-
371- return undefined ;
372370} ;
373371
374372Cli . logEvents = function logEvents ( gulpInst , finalTaskNames ) {
@@ -379,14 +377,14 @@ Cli.logEvents = function logEvents(gulpInst, finalTaskNames) {
379377
380378 // TODO: batch these
381379 // so when 5 tasks start at once it only logs one time with all 5
382- gutil . log ( 'Starting' , '\'' + e . task . cyan + '\'...' ) ;
380+ gutil . log ( 'Starting' , '\'' + chalk . cyan ( e . task ) + '\'...' ) ;
383381 } ) ;
384382
385383 gulpInst . on ( 'task_stop' , function ( e ) {
386384 var time = prettyTime ( e . hrDuration ) ;
387385 gutil . log (
388- 'Finished' , '\'' + e . task . cyan + '\'' ,
389- 'after' , time . magenta
386+ 'Finished' , '\'' + chalk . cyan ( e . task ) + '\'' ,
387+ 'after' , chalk . magenta ( time )
390388 ) ;
391389 if ( finalTaskNames . indexOf ( e . task ) > - 1 ) {
392390 log . info ( ) ;
@@ -397,20 +395,12 @@ Cli.logEvents = function logEvents(gulpInst, finalTaskNames) {
397395 var msg = Cli . formatGulpError ( e ) ;
398396 var time = prettyTime ( e . hrDuration ) ;
399397 gutil . log (
400- '\'' + e . task . cyan + '\'' ,
401- 'errored after' . red ,
402- time . magenta
398+ '\'' + chalk . cyan ( e . task ) + '\'' ,
399+ chalk . red ( 'errored after' ) ,
400+ chalk . magenta ( time )
403401 ) ;
404402 gutil . log ( msg ) ;
405403 } ) ;
406-
407- // gulpInst.on('task_not_found', function(err) {
408- // gutil.log(
409- // ('Task \'' + err.task + '\' is not in your gulpfile').red
410- // );
411- // gutil.log('Please check the documentation for proper gulpfile formatting');
412- // process.exit(1);
413- // });
414404} ;
415405
416406// Format orchestrator errors
@@ -472,13 +462,13 @@ Cli.printVersionWarning = function printVersionWarning(version, npmVersion) {
472462 }
473463
474464 if ( npmVersion && npmVersion !== version . trim ( ) ) {
475- log . warn ( '\n------------------------------------\n' . red ) ;
476- log . warn ( 'Ionic CLI is out of date:\n' . bold . yellow ) ;
477- log . warn ( ( ' * Locally installed version: ' + version + '\n' ) . yellow ) ;
478- log . warn ( ( ' * Latest version: ' + npmVersion + '\n' ) . yellow ) ;
479- log . warn ( ( ' * https://github.com/driftyco/ionic-cli/blob/master/CHANGELOG.md\n' ) . yellow ) ;
480- log . warn ( ' * Run ' . yellow + 'npm install -g ionic' . bold + ' to update\n' . yellow ) ;
481- log . warn ( '------------------------------------\n\n' . red ) ;
465+ log . warn ( chalk . red ( '\n------------------------------------\n' ) ) ;
466+ log . warn ( chalk . yellow . bold ( 'Ionic CLI is out of date:\n' ) ) ;
467+ log . warn ( chalk . yellow ( ' * Locally installed version: ' + version + '\n' ) ) ;
468+ log . warn ( chalk . yellow ( ' * Latest version: ' + npmVersion + '\n' ) ) ;
469+ log . warn ( chalk . yellow ( ' * https://github.com/driftyco/ionic-cli/blob/master/CHANGELOG.md\n' ) ) ;
470+ log . warn ( chalk . yellow ( ' * Run ' ) + chalk . bold ( 'npm install -g ionic' ) + chalk . yellow ( ' to update\n' ) ) ;
471+ log . warn ( chalk . red ( '------------------------------------\n\n' ) ) ;
482472 }
483473} ;
484474
@@ -614,10 +604,10 @@ Cli.printNewsUpdates = function printNewsUpdates(skipNewsCheck) {
614604
615605 for ( var i = 0 , j = messagesJson . list . length ; i < j ; i += 1 ) {
616606 var entry = messagesJson . list [ i ] ;
617- var entryMessage = [ '+ ' , entry . name , '\n' , '+ ' , entry . action . blue . bold , '\n+\n' ] . join ( '' ) ;
607+ var entryMessage = [ '+ ' , entry . name , '\n' , '+ ' , chalk . blue . bold ( entry . action ) , '\n+\n' ] . join ( '' ) ;
618608 log . info ( entryMessage ) ;
619609 }
620- log . info ( '+---------------------------------------------------------+\n' . green ) ;
610+ log . info ( chalk . green ( '+---------------------------------------------------------+\n' ) ) ;
621611 } catch ( ex ) {
622612 q . reject ( 'Error occurred in downloading the CLI messages:' , ex ) ;
623613 appLibUtils . fail ( ex ) ;
@@ -639,7 +629,7 @@ Cli.gatherInfo = function gatherInfo() {
639629} ;
640630
641631Cli . handleUncaughtExceptions = function handleUncaughtExceptions ( err ) {
642- log . error ( 'An uncaught exception occurred and has been reported to Ionic' . red . bold ) ;
632+ log . error ( chalk . red . bold ( 'An uncaught exception occurred and has been reported to Ionic' ) ) ;
643633 var errorMessage = typeof err === 'string' ? err : err . message ;
644634 appLibUtils . errorHandler ( errorMessage ) ;
645635 process . exit ( 1 ) ;
@@ -655,10 +645,10 @@ Cli.attachErrorHandling = function attachErrorHandling() {
655645 var info = Cli . gatherInfo ( ) ;
656646 var ionicCliVersion = info . ionic_cli ;
657647 if ( stack && stack . length > 0 ) {
658- process . stderr . write ( '\n' + stack . bold + '\n\n' ) ;
648+ process . stderr . write ( '\n' + chalk . bold ( stack ) + '\n\n' ) ;
659649 }
660- process . stderr . write ( '\n' + errorMessage . bold ) ;
661- process . stderr . write ( ( ' (CLI v' + ionicCliVersion + ')' ) . bold + '\n' ) ;
650+ process . stderr . write ( '\n' + chalk . bold ( errorMessage ) ) ;
651+ process . stderr . write ( chalk . bold ( ' (CLI v' + ionicCliVersion + ')' ) + '\n' ) ;
662652
663653 Info . printInfo ( info ) ;
664654 }
0 commit comments