@@ -5,7 +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' ;
8+ import { formatMissingProjects , formatTimeDiff , isOutputTxt } from '../utils/functions' ;
99import Logger from '../utils/logger'
1010
1111export default class BuildHelper extends WorkerHelper {
@@ -17,15 +17,17 @@ export default class BuildHelper extends WorkerHelper {
1717
1818 constructor ( command ) {
1919 super ( command ) ;
20+ this . command = command ;
2021 }
2122
22- async init ( debug , compareWith ) {
23+ async init ( debug , compareWith , compareHash ) {
2324 this . cacher = new Cacher ( ) . cacher ;
25+ this . compareHash = compareHash ;
2426 this . startTime = process . hrtime ( ) ;
2527 if ( debug ) {
2628 this . debug = debug ;
2729 this . compareWith = compareWith ;
28- const debugJSON = await this . cacher . getDebugFile ( compareWith ) || { } ;
30+ const debugJSON = await this . cacher . getDebugFile ( compareWith , this . command ) || { } ;
2931 Hasher . updateDebugJSON ( debugJSON ) ;
3032 }
3133 }
@@ -85,11 +87,13 @@ export default class BuildHelper extends WorkerHelper {
8587 async builder ( buildProject ) {
8688 this . totalCount ++
8789 const root = ConfigHelper . projects [ buildProject ] ;
90+ const projectName = root . substr ( root . lastIndexOf ( '/' ) + 1 )
8891 // TODO: Non cacheable projects control
89- const { build : { outputs, script } } = ConfigHelper . getConfig ( buildProject , root ) ;
92+ const config = ConfigHelper . getConfig ( buildProject , root ) ;
93+ const { outputs, script} = config [ this . command ] ;
9094 const buildPath = path . join ( ROOT_PATH , root ) ;
9195 const hash = Hasher . getHash ( buildPath , script , this . debug , this . compareWith ) ;
92- const isCached = await this . cacher . isCached ( hash , root , outputs ) ;
96+ const isCached = await this . cacher . isCached ( hash , root , outputs , script ) ;
9397 if ( this . compareWith ) {
9498 const [ changedFiles , newFiles ] = Hasher . getUpdatedHashes ( ) ;
9599 if ( changedFiles . length || newFiles . length ) {
@@ -101,25 +105,29 @@ export default class BuildHelper extends WorkerHelper {
101105 Logger . log ( 3 , 'Cache does not exist for => ' , buildProject , hash ) ;
102106
103107 const startTime = process . hrtime ( ) ;
104- const output = await this . execute ( buildPath , script , hash , root , outputs ) ;
108+ const output = await this . execute ( buildPath , script , hash , root , outputs , projectName ) ;
105109 this . missingProjects . push ( { buildProject, time : process . hrtime ( startTime ) } ) ;
106110 if ( output instanceof Error ) {
107111 // process.exit(0);
112+ Logger . log ( 2 , 'Error in path ::' , buildPath )
108113 throw new Error ( output ) ;
109114 }
115+ if ( isOutputTxt ( outputs ) ) {
116+ Logger . log ( 2 , output . output )
117+ }
110118 this . built ++
111119 } else {
112120 if ( outputs . length ) {
113121 for ( const output of outputs ) {
114122 // const outputPath = path.join(ROOT_PATH, root, output);
115123 Logger . log ( 3 , 'Recovering from cache' , buildProject , 'with hash => ' , hash ) ;
116- const recoverResponse = await this . anotherJob ( hash , root , output ) ;
124+ const recoverResponse = await this . anotherJob ( hash , root , output , script , this . compareHash ) ;
117125 if ( recoverResponse instanceof Error ) {
118126 throw new Error ( recoverResponse ) ;
119127 }
120128 if ( ! recoverResponse ) {
121129 // TODO: will remove in for loop sorry for shitty code anyone who sees it :((
122- await this . execute ( buildPath , script , hash , root , outputs ) ;
130+ await this . execute ( buildPath , script , hash , root , outputs , projectName ) ;
123131 this . built ++
124132 } else {
125133 this . fromCache ++
@@ -150,13 +158,13 @@ export default class BuildHelper extends WorkerHelper {
150158▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌ ▐░▌▐░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌ ▐░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░▌ ▐░▌
151159 ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀ ▀
152160` ) ;
153- Logger . log ( 2 , `Total of ${ this . totalCount } project${ this . totalCount === 1 ? '' : 's' } has built .` ) ;
154- Logger . log ( 2 , `${ this . fromCache } project built from cache,` ) ;
155- Logger . log ( 2 , `${ this . built } project built without cache.` ) ;
161+ Logger . log ( 2 , `Total of ${ this . totalCount } project${ this . totalCount === 1 ? ' is ' : 's are ' } finished .` ) ;
162+ Logger . log ( 2 , `${ this . fromCache } projects used from cache,` ) ;
163+ Logger . log ( 2 , `${ this . built } projects used without cache.` ) ;
156164 Logger . log ( 2 , `Cache is missing for following projects => ${ formatMissingProjects ( this . missingProjects ) } ` ) ;
157- Logger . log ( 2 , `Total build took ${ formatTimeDiff ( process . hrtime ( this . startTime ) ) } .` ) ;
165+ Logger . log ( 2 , `Total process took ${ formatTimeDiff ( process . hrtime ( this . startTime ) ) } .` ) ;
158166 if ( this . debug && process . env . ZENITH_DEBUG_ID ) {
159- this . cacher . updateDebugFile ( Hasher . getDebugJSON ( ) ) ;
167+ this . cacher . updateDebugFile ( Hasher . getDebugJSON ( ) , this . command ) ;
160168 Logger . log ( 2 , 'DEBUG JSON UPDATED' ) ;
161169 }
162170 }
0 commit comments