Files
vercel/api/_lib/examples/summary.ts
Nathan Rajlich f1009a80cd [api] Fix GET /api/examples/list output (#6574)
A regression from #6554 caused the return value to contain a nested
object with a `name` property for the `name` key of the response in the
list.
2021-08-09 22:24:17 -07:00

21 lines
559 B
TypeScript

/**
* Get example list from extracted folder
*/
import { lstatSync, existsSync, readdirSync } from 'fs';
const exists = (path: string) => existsSync(path);
const isDotFile = (name: string) => name.startsWith('.');
const isDirectory = (path: string) => lstatSync(path).isDirectory();
export function summary(source: string): string[] {
if (!exists(source) || !isDirectory(source)) {
return [];
}
return readdirSync(source, { withFileTypes: true })
.filter(d => !isDotFile(d.name))
.filter(d => d.isDirectory())
.map(d => d.name);
}