import fs from "fs-extra" ; import path from "path" ; import { ApiMetadata } from "./" ; import { ApiModel } from "./" ; description export param { string } apiPath returns { ApiMetadata } export function loadApiDirectory ( apiPath ) { if ( ! fs . pathExistsSync ( apiPath ) ) { throw new Error ( `${ apiPath } Api path does not exist` ) ; } if ( fs . existsSync ( path . join ( apiPath , "exchange.json" ) ) ) { return new ApiModel ( path . basename ( apiPath ) , apiPath ) ; } const children = fs . readdirSync ( apiPath ) . filter ( ( entry ) => fs . lstatSync ( path . join ( apiPath , entry ) ) . isDirectory ( ) ) . map ( ( dir ) => loadApiDirectory ( path . join ( apiPath , dir ) ) ) ; return new ApiMetadata ( path . basename ( apiPath ) , apiPath , children ) ; }