file import { existsSync } from 'fs' ; import { mkdir , readFile , unlink , writeFile } from 'fs/promises' ; interface DocFn { kind : string ; isFPFn : boolean ; title : string ; generatedFrom : string ; args : { length : number ; } ; } ; ( async ( ) => { const jsDocs = JSON . parse ( ( await readFile ( './tmp/docs.json' ) ) . toString ( ) ) ; const fpFns = Object . keys ( jsDocs ) . map ( ( category ) => jsDocs [ category ] ) . reduce ( ( previousValue , newValue ) => [ ... previousValue , ... newValue ] , [ ] ) . filter ( ( doc ) => doc . kind === 'function' && doc . isFPFn ) ; fpFns . forEach ( buildFPFn ) ; } ) ( ) ; function getFPFn ( initialFnName , arity ) { return `// This file is generated automatically by \`scripts/build/fp.ts\`. Please, don't change it.

import fn from '../../${ initialFnName }/index'
import convertToFP from '../_lib/convertToFP/index'

export default convertToFP(fn, ${ arity })
` ; } async function buildFPFn ( { title , generatedFrom , args : { length } , } ) { const source = getFPFn ( generatedFrom , length ) ; const dir = `./src/fp/${ title }` ; if ( ! existsSync ( dir ) ) await mkdir ( dir ) ; writeFile ( `${ dir }/index.ts` , source ) ; const jsPath = `${ dir }/index.js` ; if ( existsSync ( jsPath ) ) unlink ( jsPath ) ; }