forked from learn-anything/learn-anything
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.ts
34 lines (32 loc) · 921 Bytes
/
lib.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
import { grafbaseTypeDefs } from "@la/shared/lib"
import fs from "fs"
import path from "path"
import Mobius from "graphql-mobius"
export function mobius() {
return new Mobius<typeof grafbaseTypeDefs>({
fetch: (query) =>
fetch(process.env.GRAFBASE_API_URL!, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer`
},
body: JSON.stringify({
query,
variables: {}
})
}).then((res) => res.json())
})
}
export function getMarkdownFiles(dirPath: string) {
let mdFiles = <string[]>[]
fs.readdirSync(dirPath).forEach((file) => {
const fullPath = path.join(dirPath, file)
if (fs.statSync(fullPath).isDirectory()) {
mdFiles = mdFiles.concat(getMarkdownFiles(fullPath))
} else if (path.extname(fullPath) === ".md") {
mdFiles.push(fullPath)
}
})
return mdFiles
}