import { renderApplication } from '@ui' ; import config , { validateConfig } from '@config' ; import engine from '@engine' ; import { LintMessage } from '@engine/types' ; import * as fileClient from '@file-client' ; import logger from '@progress-logger' ; /**
 * Entrypoint of the application.
 * Runs ESLint to given repositories and filters out only the rules being under testing.
 * Results are written to ./eslint-remote-tester-results directory.
 */ async function main ( ) { const pool = config . repositories . map ( repo => ( ) => scanRepo ( repo ) ) ; async function execute ( ) { const task = pool . shift ( ) ; if ( task && ! logger . isTimeout ( ) ) { await task ( ) ; return execute ( ) ; } } await validateConfig ( config ) ; fileClient . prepareResultsDirectory ( ) ; renderApplication ( ) ; logger . onCacheStatus ( fileClient . getCacheStatus ( ) ) ; await Promise . all ( Array ( config . concurrentTasks ) . fill ( execute ) . map ( task => task ( ) ) ) ; logger . onAllRepositoriesScanned ( ) ; logger . onCacheStatus ( fileClient . getCacheStatus ( ) ) ; } /**
 * Run repository scanning on separate thread in order to keep main one
 * free for logger updates
 */ async function scanRepo ( repository ) { const results = [ ] ; await engine . scanRepository ( repository , function onMessage ( message ) { switch ( message . type ) { case 'START' : return logger . onTaskStart ( repository ) ; case 'READ' : return logger . onRepositoryRead ( repository ) ; case 'CLONE' : return logger . onRepositoryClone ( repository ) ; case 'PULL' : return logger . onRepositoryPull ( repository ) ; case 'ON_RESULT' : return results . push ( ... message . payload . messages ) ; case 'LINT_START' : return logger . onLintStart ( repository , message . payload ) ; case 'FILE_LINT_END' : return logger . onFileLintEnd ( repository , message . payload . fileIndex ) ; case 'FILE_LINT_SLOW' : return logger . onFileLintSlow ( repository , message . payload . lintTime , message . payload . path ) ; case 'LINTER_CRASH' : return logger . onLinterCrash ( repository , message . payload ) ; case 'WORKER_ERROR' : return logger . onWorkerCrash ( repository , message . payload ) ; case 'CLONE_FAILURE' : return logger . onCloneFailure ( repository ) ; case 'PULL_FAILURE' : return logger . onPullFailure ( repository ) ; case 'READ_FAILURE' : return logger . onReadFailure ( repository ) ; case 'DEBUG' : return logger . onDebug ( message . payload ) ; } } , function workerCallback ( worker ) { function onTimeout ( ) { worker . terminate ( ) ; } logger . on ( 'timeout' , onTimeout ) ; return function cleanup ( ) { logger . off ( 'timeout' , onTimeout ) ; } ; } ) ; try { await fileClient . writeResults ( results , repository ) ; } catch ( e ) { logger . onWriteFailure ( repository , e ) ; } logger . onLintEnd ( repository , results . length ) ; } export const __handleForTests = main ( ) ;