import * as path from "path" ; import * as recast from "recast" ; import * as parser from "recast/parsers/babel" ; import glob = require ( "glob" ) ; export const distDir = path . resolve ( __dirname , ".." , "dist" ) ; export function eachFile ( dir , callback ) { const promises = [ ] ; return new Promise < void > ( ( resolve , reject ) => { glob ( `${ dir }/**/*.js` , ( error , files ) => { if ( error ) return reject ( error ) ; files . sort ( ) . forEach ( file => { const relPath = path . relative ( dir , file ) ; if ( relPath . startsWith ( "../" ) ) return ; if ( relPath . endsWith ( ".cjs.js" ) ) return ; if ( relPath . endsWith ( ".cjs" ) ) return ; if ( relPath . endsWith ( ".min.js" ) ) return ; if ( relPath . endsWith ( "invariantErrorCodes.js" ) ) return ; promises . push ( new Promise ( resolve => { resolve ( callback ( file , relPath ) ) ; } ) ) ; } ) ; resolve ( ) ; } ) ; } ) . then ( ( ) => Promise . all ( promises ) ) ; } export function reparse ( source ) { return recast . parse ( source , { parser } ) ; } export function reprint ( ast ) { return recast . print ( ast ) . code ; }