@@ -14,7 +14,8 @@ var Cli = module.exports,
1414 settings = require ( '../package.json' ) ,
1515 Tasks = require ( './tasks/cliTasks' ) ,
1616 Utils = IonicAppLib . utils ,
17- logging = IonicAppLib . logging ,
17+ Logging = IonicAppLib . logging ,
18+ log = Logging . logger ,
1819 Q = require ( 'q' ) ,
1920 semver = require ( 'semver' ) ,
2021 gutil = require ( 'gulp-util' ) ,
@@ -28,7 +29,7 @@ Cli.IONIC_API = '/api/v1/';
2829Cli . PRIVATE_PATH = '.ionic' ;
2930
3031// This is where the logger for the app-lib can be configured (or replaced).
31- logging . logger . level = 'info' ;
32+ log . level = 'info' ;
3233
3334
3435// Cli.dev = function dev() {
@@ -52,7 +53,6 @@ Cli.run = function run(processArgv) {
5253 //execute, grab those options, and reparse the arguments.
5354 var argv = optimist ( processArgv . slice ( 2 ) ) . argv ;
5455
55- Cli . setUpConsoleLoggingHelpers ( ) ;
5656 Cli . attachErrorHandling ( ) ;
5757 Cli . checkLatestVersion ( ) ;
5858
@@ -74,7 +74,7 @@ Cli.run = function run(processArgv) {
7474 }
7575
7676 if ( argv . verbose ) {
77- logging . logger . level = 'debug' ;
77+ log . level = 'debug' ;
7878 }
7979
8080 if ( argv . help || argv . h ) {
@@ -84,7 +84,7 @@ Cli.run = function run(processArgv) {
8484 if ( argv [ 'stats-opt-out' ] ) {
8585 IonicConfig . set ( 'statsOptOut' , true ) ;
8686 IonicConfig . save ( ) ;
87- logging . logger . info ( 'Successful stats opt-out' ) ;
87+ log . info ( 'Successful stats opt-out' ) ;
8888 return ;
8989 } else {
9090 IonicStats . t ( ) ;
@@ -94,7 +94,7 @@ Cli.run = function run(processArgv) {
9494 if ( ! taskSetting ) {
9595 return Cli . printAvailableTasks ( ) ;
9696 }
97- logging . logger . debug ( 'Task setting:' , taskSetting ) ;
97+ log . debug ( 'Task setting:' , taskSetting ) ;
9898 var booleanOptions = Cli . getBooleanOptionsForTask ( taskSetting ) ;
9999 argv = optimist ( processArgv . slice ( 2 ) ) . boolean ( booleanOptions ) . argv ;
100100 var taskModule = Cli . lookupTask ( taskSetting . module ) ;
@@ -105,19 +105,18 @@ Cli.run = function run(processArgv) {
105105 var root = Utils . cdIonicRoot ( ) ;
106106 var project = IonicProject . load ( root ) ;
107107 argv . v2 = project && project . get ( 'v2' ) ;
108- argv . v2 && logging . logger . debug ( 'Ionic 2 project.' ) ;
108+ argv . v2 && log . debug ( 'Ionic 2 project.' ) ;
109109
110110 if ( fs . existsSync ( 'node_modules' ) ) {
111111 //run with gulp hooks
112112 return runWithGulp ( argv , taskInstance ) ;
113113 } else if ( argv . v2 ) {
114- console . warn ( 'WARN: No node_modules directory found, do you need to run npm install?' ) ;
114+ log . warn ( 'WARN: No node_modules directory found, do you need to run npm install?' ) ;
115115 }
116116 }
117117 return Q . fcall ( taskInstance . run . bind ( taskInstance ) , Cli , argv ) ;
118118
119119 } catch ( ex ) {
120- logging . logger . debug ( 'Cli.Run - Error' , ex ) ;
121120 return Utils . fail ( ex ) ;
122121 }
123122} ;
@@ -128,20 +127,20 @@ function runWithGulp(argv, taskInstance){
128127 var afterHook = cmdName + ':after' ;
129128
130129 if ( loadGulpfile ( ) ) {
131- logging . logger . debug ( 'Gulpfile found' ) ;
130+ log . verbose ( 'Gulpfile found' ) ;
132131
133132 try {
134133 var gulp = require ( path . resolve ( process . cwd ( ) + '/node_modules/gulp' ) ) ;
135134 } catch ( e ) {
136135 // Empty gulpfile (or one that doesn't require gulp?), and no gulp
137- console . error ( '\nGulpfile detected, but gulp is not installed' ) ;
138- console . error ( 'Do you need to run `npm install`?\n' ) ;
136+ log . error ( '\nGulpfile detected, but gulp is not installed' ) ;
137+ log . error ( 'Do you need to run `npm install`?\n' ) ;
139138 process . exit ( 1 ) ;
140139 }
141140 logEvents ( gulp , [ beforeHook , afterHook ] ) ;
142141
143142 if ( gulp . tasks [ beforeHook ] ) {
144- console . info ( '\nRunning \'' + beforeHook + '\' gulp task before ' + cmdName ) ;
143+ log . info ( '\nRunning \'' + beforeHook + '\' gulp task before ' + cmdName ) ;
145144 }
146145 return Q . nfcall ( gulp . start . bind ( gulp ) , beforeHook ) . then (
147146 function ( ) {
@@ -152,41 +151,41 @@ function runWithGulp(argv, taskInstance){
152151 //if there is no hook task, but it's a v2 app and a command that usually needs a hook
153152 if ( e . missingTask && / s e r v e | b u i l d | r u n | e m u l a t e | u p l o a d / . test ( cmdName ) && argv . v2 ) {
154153 var taskName = ( cmdName === 'serve' ) ? 'watch' : 'build' ;
155- console . warn ( 'WARN: No \'' + beforeHook + '\' gulp task found!' ) ;
154+ log . warn ( 'WARN: No \'' + beforeHook + '\' gulp task found!' ) ;
156155
157156 //The task exists, but there are no hooks for it
158157 //They have the old config file, so we're safe to yell at them
159158 //With new config, may intentionally not have hooks if running their own build
160159 if ( gulp . tasks [ taskName ] && fs . existsSync ( 'ionic.config.js' ) ) {
161- console . info ( 'Your gulpfile contains a \'' + taskName + '\' task already! Add:\n' )
162- console . log ( ' gulp.task(\'' + cmdName + ':before\', [\'' + taskName + '\']);\n' ) ;
163- console . info ( 'to your gulpfile to have Ionic CLI run \'' + taskName + '\' before ' + cmdName + '.\n' ) ;
160+ log . info ( 'Your gulpfile contains a \'' + taskName + '\' task already! Add:\n' )
161+ log . info ( ' gulp.task(\'' + cmdName + ':before\', [\'' + taskName + '\']);\n' ) ;
162+ log . info ( 'to your gulpfile to have Ionic CLI run \'' + taskName + '\' before ' + cmdName + '.\n' ) ;
164163 } else {
165- console . warn ( 'If your app requires a build step, you may want to ensure it runs before ' + cmdName + '.\n' ) ;
164+ log . warn ( 'If your app requires a build step, you may want to ensure it runs before ' + cmdName + '.\n' ) ;
166165 }
167166 }
168167 // Only some commands return promises, so wrap it
169168 return Q . fcall ( taskInstance . run . bind ( taskInstance ) , Cli , argv ) ;
170169 }
171170 ) . then ( function ( ) {
172171 if ( gulp . tasks [ afterHook ] ) {
173- console . info ( '\nRunning \'' + afterHook + '\' gulp task after ' + cmdName ) ;
172+ log . info ( '\nRunning \'' + afterHook + '\' gulp task after ' + cmdName ) ;
174173 }
175174 return Q . nfcall ( gulp . start . bind ( gulp ) , afterHook ) ;
176175 } ) ;
177176 }
178177
179178 //No gulpfile
180179 if ( / s e r v e | b u i l d | r u n | e m u l a t e | u p l o a d / . test ( cmdName ) && argv . v2 ) {
181- console . warn ( 'WARN: No gulpfile found!' ) ;
182- console . warn ( 'If your app requires a build step, you may want to ensure it runs before ' + cmdName + '.\n' ) ;
180+ log . warn ( 'WARN: No gulpfile found!' ) ;
181+ log . warn ( 'If your app requires a build step, you may want to ensure it runs before ' + cmdName + '.\n' ) ;
183182
184183 if ( fs . existsSync ( 'ionic.config.js' ) ) {
185184 var inquirer = require ( 'inquirer' ) ;
186185 var deferred = Q . defer ( ) ;
187186
188- console . info ( 'Looks like you are using the deprecated ionic.config.js and have no gulpfile!' ) ;
189- console . info ( 'As of beta.21 the Ionic CLI relies on gulp hooks to build your web assets\n' ) ;
187+ log . info ( 'Looks like you are using the deprecated ionic.config.js and have no gulpfile!' ) ;
188+ log . info ( 'As of beta.21 the Ionic CLI relies on gulp hooks to build your web assets\n' ) ;
190189 inquirer . prompt ( [ {
191190 type : 'confirm' ,
192191 name : 'downloadGulp' ,
@@ -202,17 +201,17 @@ function runWithGulp(argv, taskInstance){
202201 return downloadDefaultGulpfile ( cmdName ) . then (
203202 installGulpfilePackages ,
204203 function ( err ) {
205- console . error ( 'There was an error downloading the default gulpfile: ' + err ) ;
204+ log . error ( 'There was an error downloading the default gulpfile: ' + err ) ;
206205 process . exit ( 1 ) ;
207206 }
208207 ) . then (
209208 function ( ) {
210- console . success ( 'Npm packages installed successfully. Try running \'' + cmdName + '\' again.' ) ;
209+ log . info ( 'Npm packages installed successfully. Try running \'' + cmdName + '\' again.' ) ;
211210 } ,
212211 function ( ) {
213- console . warn ( 'There was an error installing the packages required by the gulpfile.' ) ;
214- console . warn ( 'You\'ll need to install the following packages manually: ' ) ;
215- console . warn ( ' ' + requires . join ( ' ' ) ) ;
212+ log . warn ( 'There was an error installing the packages required by the gulpfile.' ) ;
213+ log . warn ( 'You\'ll need to install the following packages manually: ' ) ;
214+ log . warn ( ' ' + requires . join ( ' ' ) ) ;
216215 }
217216 ) ;
218217 } ,
@@ -236,17 +235,17 @@ function loadGulpfile(){
236235 } catch ( e ) {
237236 if ( e . code === 'MODULE_NOT_FOUND' ) {
238237 if ( e . message . indexOf ( names [ i ] ) === - 1 ) {
239- console . log ( 'Uh oh! Looks like you\'re missing a module in your gulpfile:' ) ;
240- console . error ( e . message ) ;
241- console . log ( '\nDo you need to run `npm install`?\n' ) ;
238+ log . info ( 'Uh oh! Looks like you\'re missing a module in your gulpfile:' ) ;
239+ log . error ( e . message ) ;
240+ log . info ( '\nDo you need to run `npm install`?\n' ) ;
242241 process . exit ( 1 ) ;
243242 } else {
244243 // ignore missing gulpfile
245244 continue
246245 }
247246 }
248- console . error ( 'There is an error in your gulpfile: ' )
249- console . error ( e . stack ) ;
247+ log . error ( 'There is an error in your gulpfile: ' )
248+ log . error ( e . stack ) ;
250249 process . exit ( 1 ) ;
251250 }
252251 }
@@ -261,7 +260,7 @@ function downloadDefaultGulpfile(){
261260 var branch = project . get ( 'typescript' ) ? 'typescript' : 'master' ;
262261 var url = 'https://raw.githubusercontent.com/driftyco/ionic2-app-base/' + branch + '/gulpfile.js' ;
263262
264- console . info ( '\nDownloading default gulpfile from: ' + url ) ;
263+ log . info ( '\nDownloading default gulpfile from: ' + url ) ;
265264
266265 fileStream . on ( 'open' , function ( ) {
267266 https . get ( url , function ( res ) {
@@ -285,14 +284,16 @@ function installGulpfilePackages(cmdName){
285284 var requires = detective ( fs . readFileSync ( 'gulpfile.js' ) ) ;
286285 var deferred = Q . defer ( ) ;
287286
288- console . success ( 'Successfully downloaded gulpfile.\n' ) ;
289- console . info ( 'Now installing npm packages used by the gulpfile: ' ) ;
290- console . info ( ' ' + requires . join ( ' ' ) + '\n' ) ;
287+ log . info ( 'Successfully downloaded gulpfile.\n' . green ) ;
288+ log . info ( 'Now installing npm packages used by the gulpfile: ' ) ;
289+ log . info ( ' ' + requires . join ( ' ' ) + '\n' ) ;
291290
292291 var npmInstall = require ( 'child_process' ) . spawn ( 'npm' , [ 'install' , '--save-dev' ] . concat ( requires ) ) ;
293- npmInstall . stdout . on ( 'data' , function ( data ) { logging . logger . debug ( data ) } ) ;
294- npmInstall . stderr . on ( 'data' , function ( data ) { logging . logger . debug ( data ) } ) ;
295- npmInstall . on ( 'error' , function ( err ) { console . error ( err ) } ) ;
292+ npmInstall . stdout . on ( 'data' , function ( data ) { log . debug ( data ) } ) ;
293+ npmInstall . stderr . on ( 'data' , function ( data ) { log . debug ( data ) } ) ;
294+ npmInstall . on ( 'error' , function ( err ) {
295+ log . error ( 'Error in gulp npm install: ' + err . stack ) ;
296+ } ) ;
296297 npmInstall . on ( 'exit' , function ( code ) {
297298 code !== 0 ? deferred . reject ( ) : deferred . resolve ( ) ;
298299 } ) ;
@@ -315,7 +316,7 @@ function logEvents(gulpInst, finalTaskNames) {
315316 'after' , time . magenta
316317 ) ;
317318 if ( finalTaskNames . indexOf ( e . task ) > - 1 ) {
318- console . log ( ) ;
319+ log . info ( ) ;
319320 }
320321 } ) ;
321322
@@ -380,64 +381,6 @@ Cli.getBooleanOptionsForTask = function getBooleanOptionsForTask(task) {
380381 return booleanOptions ;
381382} ;
382383
383- Cli . setUpConsoleLoggingHelpers = function setUpConsoleLoggingHelpers ( ) {
384- colors . setTheme ( {
385- silly : 'rainbow' ,
386- input : 'grey' ,
387- small : 'grey' ,
388- verbose : 'cyan' ,
389- prompt : [ 'yellow' , 'bold' ] ,
390- info : 'white' ,
391- data : 'grey' ,
392- help : 'cyan' ,
393- warn : 'yellow' ,
394- debug : 'blue' ,
395- error : 'red'
396- } ) ;
397-
398- var consoleInfo = console . info ;
399- console . info = function ( ) {
400- if ( arguments . length === 1 && ! arguments [ 0 ] ) return ;
401- var msg = '' ;
402- for ( var n in arguments ) {
403- msg += arguments [ n ] + ' ' ;
404- }
405- consoleInfo . call ( console , msg . cyan . bold ) ;
406- } ;
407-
408- var consoleWarn = console . warn ;
409- console . warn = function ( ) {
410- if ( arguments . length === 1 && ! arguments [ 0 ] ) return ;
411- var msg = '' ;
412- for ( var n in arguments ) {
413- msg += arguments [ n ] + ' ' ;
414- }
415- consoleWarn . call ( console , msg . yellow . bold ) ;
416- } ;
417-
418- var consoleError = console . error ;
419- console . error = function ( ) {
420- if ( arguments . length === 1 && ! arguments [ 0 ] ) return ;
421- var msg = ' ✗' ;
422- for ( var n in arguments ) {
423- msg += ' ' + arguments [ n ] ;
424- }
425- consoleError . call ( console , msg . red . bold ) ;
426- } ;
427-
428- console . success = function ( ) {
429- if ( arguments . length === 1 && ! arguments [ 0 ] ) return ;
430- var msg = ' ✓' ;
431- for ( var n in arguments ) {
432- msg += ' ' + arguments [ n ] ;
433- }
434- console . log ( msg . green . bold ) ;
435- } ;
436-
437- //Default level is set to 'info'
438- IonicAppLib . logging . createDefaultLogger ( ) ;
439- } ;
440-
441384Cli . lookupTask = function lookupTask ( module ) {
442385 try {
443386 var taskModule = require ( module ) . IonicTask ;
@@ -694,7 +637,7 @@ Cli.processExit = function processExit(code) {
694637} ;
695638
696639Cli . version = function version ( ) {
697- console . log ( settings . version + '\n' ) ;
640+ log . info ( settings . version + '\n' ) ;
698641} ;
699642
700643Cli . printNewsUpdates = function printNewsUpdates ( skipNewsCheck ) {
@@ -736,11 +679,8 @@ Cli.printNewsUpdates = function printNewsUpdates(skipNewsCheck) {
736679 }
737680 process . stdout . write ( '+---------------------------------------------------------+\n' . green ) ;
738681 } catch ( ex ) {
739- console . log ( 'ex' , ex . stack ) ;
740682 q . reject ( 'Error occurred in downloading the CLI messages:' , ex )
741683 Utils . fail ( ex ) ;
742- q . reject ( ex ) ;
743- return
744684 }
745685 q . resolve ( messagesJson ) ;
746686 } else {
@@ -780,17 +720,17 @@ Cli.handleUncaughtExceptions = function handleUncaughtExceptions(err, url) {
780720Cli . attachErrorHandling = function attachErrorHandling ( ) {
781721 Utils . errorHandler = function errorHandler ( msg , taskHelp ) {
782722 try {
783- logging . logger . debug ( 'Cli.Utils.errorHandler msg' , msg , typeof msg ) ;
723+ log . debug ( 'Cli.Utils.errorHandler msg' , msg , typeof msg ) ;
784724 var stack = typeof msg == 'string' ? '' : msg . stack ;
785725 var errorMessage = typeof msg == 'string' ? msg : msg . message ;
786726 if ( msg ) {
787727 var info = Cli . gatherInfo ( ) ;
788728 var ionicCliVersion = info . ionic_cli ;
789729 if ( stack && stack . length > 0 ) {
790- process . stderr . write ( '\n' + stack . error . bold + '\n\n' ) ;
730+ process . stderr . write ( '\n' + stack . bold + '\n\n' ) ;
791731 }
792- process . stderr . write ( '\n' + errorMessage . error . bold ) ;
793- process . stderr . write ( ( ' (CLI v' + ionicCliVersion + ')' ) . error . bold + '\n' ) ;
732+ process . stderr . write ( '\n' + errorMessage . bold ) ;
733+ process . stderr . write ( ( ' (CLI v' + ionicCliVersion + ')' ) . bold + '\n' ) ;
794734
795735 Info . printInfo ( info ) ;
796736 }
@@ -828,7 +768,7 @@ Cli.doRuntimeCheck = function doRuntimeCheck(version) {
828768 try {
829769 versionHasBeenChecked = semver . satisfies ( version , lastVersionChecked ) ;
830770 } catch ( ex ) {
831- console . log ( ex ) ;
771+ log . info ( ex ) ;
832772 }
833773
834774 if ( ! lastVersionChecked || ! versionHasBeenChecked ) {
0 commit comments