import { join } from 'path' ; import { mkdirpSync } from 'fs-extra' ; import { WorkRoot as IWorkRoot , SubRoot , SpecialSubRoot , WorkRootKind } from './types' ; const EnvPaths = { objects : process . env . FLOOD_OBJECTS_PATH , results : process . env . FLOOD_RESULTS_PATH , traces : process . env . FLOOD_TRACES_PATH , files : process . env . FLOOD_FILES_PATH , screenshots : null , network : null , } ; export default class WorkRoot implements IWorkRoot { subRoots : SubRoot [ ] = [ 'objects' , 'screenshots' , 'files' , 'results' , 'network' , 'traces' ] ; constructor ( public root , public specialSubRoots ) { this . ensureExistsSync ( ) ; } getRoot ( ) { return this . root ; } getSubRoot ( key ) { return this . specialSubRoots [ key ] ; } ensureExistsSync ( ) { this . subRoots . forEach ( ( r ) => mkdirpSync ( join ( this . root , r ) ) ) ; } rootFor ( root ) { if ( this . specialSubRoots [ root ] != null ) { return this . specialSubRoots [ root as SpecialSubRoot ] ; } else { if ( EnvPaths [ root ] != null ) { return EnvPaths [ root ] ; } return join ( this . root , root ) ; } } join ( root , ... segments ) { return join ( this . rootFor ( root ) , ... segments ) ; } testData ( filename ) { return join ( this . rootFor ( 'test-data' ) , filename ) ; } }