import { Task } from './types' ; import config from '@config' ; import { CACHE_LOCATION } from '@file-client' ; const CI_TEMPLATE_TASK_REGEXP = /\]\[/ ; /**
 * Format seconds into display format, e.g. 36092 -> 10h 1m 32s
 */ function formatSeconds ( timeSeconds ) { const hours = Math . floor ( timeSeconds / 3600 ) ; const minutes = Math . floor ( ( timeSeconds % 3600 ) / 60 ) ; const seconds = Math . floor ( timeSeconds % 60 ) ; return [ hours && `${ hours }h` , minutes && `${ minutes }m` , seconds && `${ seconds }s` , ] . filter ( Boolean ) . join ( ' ' ) ; } export const TASK_TEMPLATE = ( task ) : string => { switch ( task . step ) { case 'START' : return `[STARTING] ${ task . repository }` ; case 'CLONE' : return `[CLONING] ${ task . repository }` ; case 'PULL' : return `[PULLING] ${ task . repository }` ; case 'READ' : return `[READING] ${ task . repository }` ; case 'LINT' : { const status = task . currentFileIndex === 0 ? '' : `${ task . currentFileIndex }/` ; return `[LINTING] ${ task . repository } - ${ status }${ task . fileCount } files` ; } default : return `Unknown step ${ task . step }` ; } } ; export const REPOSITORIES_STATUS_TEMPLATE = ( scannedRepositories ) : string => `Repositories (${ scannedRepositories }/${ config . repositories . length })` ; export const CI_STATUS_TEMPLATE = ( scannedRepositories , errorCount , tasks ) : string => `[INFO/STATUS] ${ REPOSITORIES_STATUS_TEMPLATE ( scannedRepositories ) }
[INFO/STATUS] Errors (${ errorCount })
${ tasks . map ( task => CI_TASK_TEMPLATE ( task ) ) . join ( '\n' ) }\n` ; export const CACHE_STATUS_TEMPLATE = ( repositoriesCount , location ) : string => `[INFO] Cached repositories (${ repositoriesCount }) at ${ location }` ; const CI_TASK_TEMPLATE = ( task ) : string => `[INFO]${ TASK_TEMPLATE ( task ) }` . replace ( CI_TEMPLATE_TASK_REGEXP , '/' ) ; export const LINT_END_TEMPLATE = ( repository , errorCount ) : string => errorCount > 0 ? `[ERROR] ${ repository } ${ errorCount } errors` : `[SUCCESS] ${ repository }` ; export const LINT_SLOW_TEMPLATE = ( lintTime , file ) : string => { const path = file . replace ( `${ CACHE_LOCATION }/` , '' ) . split ( '/' ) ; const fileName = path . pop ( ) ; return `[WARN] Linting ${ fileName } took ${ lintTime }s at ${ path . join ( '/' ) }` ; } ; export const LINT_FAILURE_TEMPLATE = ( repository , rule ? ) : string => `[ERROR] ${ repository } crashed${ rule ? `: ${ rule }` : '' }` ; export const WORKER_FAILURE_TEMPLATE = ( repository , errorCode ? ) : string => `[ERROR] Worker crashed on ${ repository }${ errorCode ? ` (${ errorCode })` : '' }` ; export const PULL_FAILURE_TEMPLATE = ( repository ) : string => `[ERROR] ${ repository } failed to pull` ; export const CLONE_FAILURE_TEMPLATE = ( repository ) : string => `[ERROR] ${ repository } failed to clone` ; export const READ_FAILURE_TEMPLATE = ( repository ) : string => `[ERROR] ${ repository } failed to read files` ; export const WRITE_FAILURE_TEMPLATE = ( repository , e ) : string => `[ERROR] ${ repository } failed to write results: ${ e . message }` ; export const OVERFLOWING_ROWS_TOP = ( overflowingRowCount ) : string => `[\u25B2 to see ${ overflowingRowCount } lines above]` ; export const OVERFLOWING_ROWS_BOTTOM = ( overflowingRowCount ) : string => `[\u25BC to see ${ overflowingRowCount } lines below]` ; export const RESULT_COMPARISON_FINISHED = ( added , removed ) : string => `[DONE] Result comparison: Added ${ added }. Removed ${ removed }.` ; export const SCAN_TIMELIMIT_REACHED = ( timeSeconds ) : string => `[DONE] Reached scan time limit ${ formatSeconds ( timeSeconds ) }` ; export const SCAN_FINISHED = ( scannedRepositories ) : string => `[DONE] Finished scan of ${ scannedRepositories } repositories` ; export const DEBUG_TEMPLATE = ( message ) : string => `[DEBUG ${ new Date ( ) . toTimeString ( ) . split ( ' ' ) [ 0 ] }] ${ message }` ;