2022-08-24 10:44:35 +03:00
|
|
|
import { promises as fs } from "fs";
|
|
|
|
import path from "path";
|
2022-09-07 16:53:24 +03:00
|
|
|
|
2022-08-24 10:44:35 +03:00
|
|
|
import yaml from "js-yaml";
|
2022-09-07 16:53:24 +03:00
|
|
|
|
2022-08-24 10:44:35 +03:00
|
|
|
import checkAndCopyConfig from "utils/config";
|
|
|
|
|
|
|
|
export default async function handler(req, res) {
|
|
|
|
checkAndCopyConfig("widgets.yaml");
|
|
|
|
|
|
|
|
const widgetsYaml = path.join(process.cwd(), "config", "widgets.yaml");
|
|
|
|
const fileContents = await fs.readFile(widgetsYaml, "utf8");
|
|
|
|
const widgets = yaml.load(fileContents);
|
|
|
|
|
|
|
|
// map easy to write YAML objects into easy to consume JS arrays
|
2022-09-07 16:53:24 +03:00
|
|
|
const widgetsArray = widgets.map((group) => ({
|
|
|
|
type: Object.keys(group)[0],
|
|
|
|
options: { ...group[Object.keys(group)[0]] },
|
|
|
|
}));
|
2022-08-24 10:44:35 +03:00
|
|
|
|
|
|
|
res.send(widgetsArray);
|
|
|
|
}
|