const getProjectDir = ( ( ) => { const project = files . path ( `../` ) ; return ( ) => { return project ; } ; } ) ( ) ; const getThirdPartyDir = ( ( ) => { const dir = files . join ( getProjectDir ( ) , 'thirdParty/' ) ; return ( ) => { return dir ; } ; } ) ( ) ; function getScriptPath ( key ) { return files . join ( getThirdPartyDir ( ) , `${ key }.js` ) ; } function downloadFile ( { url , key , callback = ( ) => { } , options = { method : 'GET' } , } ) { http . request ( url , options , ( res , error ) => { if ( error ) { callback ( error , res ) ; return ; } const body = res . body . string ( ) ; const filePath = getScriptPath ( key ) ; if ( ! files . exists ( filePath ) ) { files . createWithDirs ( filePath ) ; } files . write ( filePath , body , 'utf8' ) ; callback ( null , res , filePath ) ; } ) ; } export { downloadFile , getProjectDir , getThirdPartyDir , getScriptPath } ;