import fs from "fs" ; import os from "os" ; import path from "path" ; import uuid from "uuid/v4" ; param parent return export const createTempDir = ( parent ? ) : string => { parent = parent || os . tmpdir ( ) ; const randomTmpDir = path . join ( parent , uuid ( ) ) ; fs . mkdirSync ( randomTmpDir ) ; return randomTmpDir ; } ; param dir export const removeDir = ( dir ) : void => { const folder = path . resolve ( dir ) ; if ( fs . existsSync ( folder ) ) { fs . readdirSync ( folder ) . forEach ( ( item ) => { const curPath = path . join ( folder , item ) ; if ( fs . statSync ( curPath ) . isDirectory ( ) ) { removeDir ( curPath ) ; } else { fs . unlinkSync ( curPath ) ; } } ) ; fs . rmdirSync ( folder ) ; } } ; param dir return export const isDirEmpty = ( dir ) : boolean => { return fs . readdirSync ( dir ) . length === 0 ; } ; param dir param fileNames return export const getMissingFilenames = ( dir , fileNames ) : string [ ] => { return fileNames . map ( ( f ) => path . join ( dir , f ) ) . filter ( ( f ) => ! fs . existsSync ( f ) ) . map ( ( f ) => path . basename ( f ) ) ; } ; param dir param files returns export const getAllFilesInDirectory = ( dir , files = [ ] ) : string [ ] => { const filesInDir = fs . readdirSync ( dir ) ; filesInDir . forEach ( function ( file ) { if ( fs . statSync ( path . join ( dir , file ) ) . isDirectory ( ) ) { files = getAllFilesInDirectory ( path . join ( dir , file ) , files ) ; } else { files . push ( path . join ( dir , file ) ) ; } } ) ; return files ; } ;