1- import * as nodeStatus from 'node-status' ;
21import chalk from 'chalk' ;
3- import { isString , find , isNil , isArray } from 'lodash' ;
2+ import { isString , isNil , isArray } from 'lodash' ;
43
54interface IStage {
65 steps : any [ ] ;
@@ -13,16 +12,29 @@ export class Status {
1312 steps : { [ step : string ] : boolean } = { } ;
1413
1514 get console ( ) {
16- return nodeStatus . console ( ) ;
15+ // Return the global console object methods
16+ return {
17+ log : global . console . log . bind ( global . console ) ,
18+ error : global . console . error . bind ( global . console ) ,
19+ warn : global . console . warn . bind ( global . console ) ,
20+ info : global . console . info . bind ( global . console )
21+ } ;
1722 }
1823
1924 constructor ( ) {
20- /* Initialize the status library */
21- this . stages = nodeStatus . addItem ( 'stages' , {
22- steps : [ ]
23- } ) ;
25+ /* Initialize the simple status system */
26+ this . stages = {
27+ steps : [ ] ,
28+ count : 0 ,
29+ doneStep : this . doneStep . bind ( this )
30+ } ;
31+ }
2432
25- nodeStatus . start ( ) ;
33+ private doneStep ( completed : boolean , message ?: string ) : void {
34+ const symbol = completed ? chalk . green ( '✓' ) : chalk . red ( '✗' ) ;
35+ if ( message ) {
36+ global . console . log ( `${ symbol } ${ message } ` ) ;
37+ }
2638 }
2739
2840 /**
@@ -37,22 +49,18 @@ export class Status {
3749 success = success && additionalDetails . findIndex ( item => item instanceof Error ) < 0 ;
3850
3951 const messageArray = getDetailsArray ( ) ;
52+ const symbol = success ? chalk . green ( '✓' ) : chalk . red ( '✗' ) ;
4053
41- if ( messageArray . length === 0 ) {
42- this . stages . doneStep ( success ) ;
43- } else {
44- // Add a newline before
45- messageArray . splice ( 0 , 0 , '' ) ;
46- this . stages . doneStep ( success , messageArray . join ( '\n * ' ) + '\n' ) ;
47- //FIXME `${chalk.bold.red('WARNING: one of the messages above was an error')}`)
48- }
49-
50- this . steps [ stage ] = false ;
54+ // Log the completion with symbol
55+ global . console . log ( `${ symbol } ${ stage } ` ) ;
5156
52- if ( ! find ( this . steps as any , ( item ) => item === true ) ) {
53- nodeStatus . stop ( ) ;
57+ if ( messageArray . length > 0 ) {
58+ messageArray . forEach ( msg => {
59+ global . console . log ( ` * ${ msg } ` ) ;
60+ } ) ;
5461 }
5562
63+ this . steps [ stage ] = false ;
5664
5765 // Helper:
5866 function getDetailsArray ( ) {
@@ -82,12 +90,13 @@ export class Status {
8290 }
8391
8492 /**
85- * Add a new stage and complete the previous stage .
93+ * Add a new stage and mark it as started .
8694 * @param stage Name of the stage.
8795 */
8896 add ( stage : string ) {
8997 this . stages . steps . push ( stage ) ;
9098 this . steps [ stage ] = true ;
99+ global . console . log ( chalk . cyan ( `○ ${ stage } ` ) ) ;
91100 }
92101}
93102
0 commit comments