-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.ts
50 lines (47 loc) · 1.24 KB
/
gatsby-node.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import * as fs from "node:fs";
import * as path from "node:path";
import type { GatsbyNode } from "gatsby";
import * as yaml from "js-yaml";
import type { ActionType } from "./src/types";
export const createPages: GatsbyNode["createPages"] = async ({
actions: { createPage },
}) => {
const actionDirs = await fs.promises.readdir("./data/actions");
for (const dir of actionDirs) {
let actionYml: string;
let versionYml: string;
try {
actionYml = await fs.promises.readFile(
`./data/actions/${dir}/action.yml`,
"utf-8",
);
versionYml = await fs.promises.readFile(
`./data/actions/${dir}/version.yml`,
"utf-8",
);
} catch (error) {
console.warn(`Failed to read action.yaml in ${dir}`, String(error));
continue;
}
const { name, description, inputs, outputs } = yaml.load(
actionYml,
) as ActionType;
const { major } = yaml.load(versionYml);
createPage({
path: `/${dir}/`,
component: path.resolve("./src/templates/action.tsx"),
context: {
name: dir,
action: {
name,
description,
inputs,
outputs,
},
version: {
major,
},
},
});
}
};