27 lines
929 B
TypeScript
27 lines
929 B
TypeScript
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||
|
|
import { readdirSync, statSync } from "node:fs";
|
||
|
|
import { join } from "node:path";
|
||
|
|
|
||
|
|
// Returns a list of subfolders in the dev root that contain a .sf directory
|
||
|
|
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||
|
|
const devRoot = req.query.devRoot as string;
|
||
|
|
if (!devRoot) return res.status(400).json({ error: "Missing devRoot" });
|
||
|
|
let projects: string[] = [];
|
||
|
|
try {
|
||
|
|
const entries = readdirSync(devRoot, { withFileTypes: true });
|
||
|
|
projects = entries
|
||
|
|
.filter((entry) => entry.isDirectory())
|
||
|
|
.filter((entry) => {
|
||
|
|
try {
|
||
|
|
return statSync(join(devRoot, entry.name, ".sf")).isDirectory();
|
||
|
|
} catch {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
})
|
||
|
|
.map((entry) => entry.name);
|
||
|
|
res.status(200).json({ projects });
|
||
|
|
} catch (e) {
|
||
|
|
res.status(500).json({ error: (e as Error).message });
|
||
|
|
}
|
||
|
|
}
|