@@ -5,6 +5,7 @@ import Cacher from './Cacher';
55import Hasher from './Hasher' ;
66import WorkerHelper from './WorkerHelper' ;
77import ConfigHelper from './ConfigHelper' ;
8+ import { formatMissingProjects , formatTimeDiff } from '../utils/functions' ;
89
910export default class BuildHelper extends WorkerHelper {
1011 projects = new Map ( ) ;
@@ -17,8 +18,11 @@ export default class BuildHelper extends WorkerHelper {
1718 super ( command ) ;
1819 }
1920
20- async init ( debug , compareWith ) {
21+ async init ( debug , compareWith , logLevel , logFunction ) {
2122 this . cacher = new Cacher ( ) . cacher ;
23+ this . logLevel = logLevel ;
24+ this . startTime = process . hrtime ( ) ;
25+ this . log = logFunction ( this . logLevel )
2226 if ( debug ) {
2327 this . debug = debug ;
2428 this . compareWith = compareWith ;
@@ -39,7 +43,7 @@ export default class BuildHelper extends WorkerHelper {
3943 } ) ;
4044 } catch ( error ) {
4145 if ( error . code === 'ENOENT' ) {
42- console . log ( 'Package.json file not found in the project!' ) ;
46+ this . log ( 2 , 'Package.json file not found in the project!' ) ;
4347 throw error ;
4448 } else {
4549 throw error ;
@@ -90,14 +94,16 @@ export default class BuildHelper extends WorkerHelper {
9094 if ( this . compareWith ) {
9195 const [ changedFiles , newFiles ] = Hasher . getUpdatedHashes ( ) ;
9296 if ( changedFiles . length || newFiles . length ) {
93- console . log ( `Hash mismatched: \n Changed files => \n - ${ changedFiles . join ( '\n' ) } \n New files => \n - ${ newFiles . join ( '\n' ) } ` ) ;
97+ this . log ( 3 , `Hash mismatched: \n Changed files => \n - ${ changedFiles . join ( '\n' ) } \n New files => \n - ${ newFiles . join ( '\n' ) } ` ) ;
9498 Hasher . emptyUpdatedHashes ( ) ;
9599 }
96100 }
97101 if ( ! isCached ) {
98- console . log ( 'Cache does not exist for => ' , buildProject , hash ) ;
99- this . missingProjects . push ( buildProject ) ;
102+ this . log ( 3 , 'Cache does not exist for => ' , buildProject , hash ) ;
103+
104+ const startTime = process . hrtime ( ) ;
100105 const output = await this . execute ( buildPath , script , hash , root , outputs ) ;
106+ this . missingProjects . push ( { buildProject, time : process . hrtime ( startTime ) } ) ;
101107 if ( output instanceof Error ) {
102108 // process.exit(0);
103109 throw new Error ( output ) ;
@@ -107,7 +113,7 @@ export default class BuildHelper extends WorkerHelper {
107113 if ( outputs . length ) {
108114 for ( const output of outputs ) {
109115 // const outputPath = path.join(ROOT_PATH, root, output);
110- console . log ( 'Recovering from cache' , buildProject , 'with hash => ' , hash ) ;
116+ this . log ( 3 , 'Recovering from cache' , buildProject , 'with hash => ' , hash ) ;
111117 const recoverResponse = await this . anotherJob ( hash , root , output ) ;
112118 if ( recoverResponse instanceof Error ) {
113119 throw new Error ( recoverResponse ) ;
@@ -132,7 +138,7 @@ export default class BuildHelper extends WorkerHelper {
132138 if ( ! projects . length ) {
133139 if ( ! stats . pendingTasks && ! stats . activeTasks ) {
134140 this . pool . terminate ( ) ;
135- console . log ( `
141+ this . log ( 2 , `
136142▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄ ▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄ ▄
137143▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░▌ ▐░░▌▐░░░░░░░░░░░▌▐░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░▌ ▐░▌
138144▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀█░▌▐░▌░▌ ▐░▐░▌▐░█▀▀▀▀▀▀▀█░▌▐░▌ ▐░█▀▀▀▀▀▀▀▀▀ ▀▀▀▀█░█▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀█░▌▐░▌
@@ -143,15 +149,16 @@ export default class BuildHelper extends WorkerHelper {
143149▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▀
144150▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄█░▌▐░▌ ▐░▌▐░▌ ▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄▄▄ ▐░▌ ▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄█░▌ ▄
145151▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌ ▐░▌▐░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌ ▐░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░▌ ▐░▌
146- ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀ ▀
152+ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀ ▀
147153` ) ;
148- console . log ( `Total of ${ this . totalCount } project has built.` ) ;
149- console . log ( `${ this . fromCache } project built from cache,` )
150- console . log ( `${ this . built } project built without cache.` ) ;
151- console . log ( `Cache is missing for following projects => \n${ this . missingProjects . join ( '\n' ) } ` ) ;
154+ this . log ( 2 , `Total of ${ this . totalCount } project${ this . totalCount === 1 ? '' : 's' } has built.` ) ;
155+ this . log ( 2 , `${ this . fromCache } project built from cache,` ) ;
156+ this . log ( 2 , `${ this . built } project built without cache.` ) ;
157+ this . log ( 2 , `Cache is missing for following projects => ${ formatMissingProjects ( this . missingProjects ) } ` ) ;
158+ this . log ( 2 , `Total build took ${ formatTimeDiff ( process . hrtime ( this . startTime ) ) } .` ) ;
152159 if ( this . debug && process . env . ZENITH_DEBUG_ID ) {
153160 this . cacher . updateDebugFile ( Hasher . getDebugJSON ( ) ) ;
154- console . log ( 'DEBUG JSON UPDATED' ) ;
161+ this . log ( 2 , 'DEBUG JSON UPDATED' ) ;
155162 }
156163 }
157164 return ;
0 commit comments