Skip to content

Commit 5e39efb

Browse files
committed
wip: Get yml to pass as props for selected files
1 parent 71c2acd commit 5e39efb

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

packages/cursorless-org/src/pages/component-sheet.tsx

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,68 @@
11
import {
22
TestCaseComponentPage
33
} from "@cursorless/test-case-component";
4+
45
import {
56
cheatsheetBodyClasses,
67
} from "@cursorless/cheatsheet";
78

9+
import * as yaml from "js-yaml";
10+
import fs from 'fs';
11+
import path from 'path';
12+
813
import Head from "next/head";
914

15+
const fixturesDir = path.join(
16+
"../",
17+
"../",
18+
"data",
19+
"fixtures",
20+
"recorded",
21+
);
22+
23+
async function loadYamlFiles(dir: string, selectedFiles?: string[]) {
24+
25+
const directoryPath = path.join(process.cwd(), dir);
26+
const files = fs.readdirSync(directoryPath);
27+
const data: any[] = [];
28+
29+
files.forEach(file => {
30+
if(path.extname(file) === '.yml' && (!selectedFiles || selectedFiles.includes(file))) {
31+
const filePath = path.join(directoryPath, file);
32+
const fileContents = fs.readFileSync(filePath, 'utf8');
33+
const yamlData: any = yaml.load(fileContents);
34+
data.push(yamlData);
35+
}
36+
});
37+
38+
console.log(dir, "files:", files)
39+
console.log("data:", data);
40+
41+
return data;
42+
}
43+
1044
// See https://github.com/vercel/next.js/discussions/12325#discussioncomment-1116108
1145
export async function getStaticProps() {
12-
return { props: { bodyClasses: cheatsheetBodyClasses } };
46+
const itemsDir = (path.join(fixturesDir, 'actions'))
47+
const testSelectedFiles = [
48+
"bringArgMadeAfterLook.yml",
49+
"chuckBlockAirUntilBatt.yml",
50+
"cutFine.yml",
51+
"chuckLineFine.yml",
52+
"bringAirAndBatAndCapToAfterItemEach.yml"
53+
]
54+
const data = await loadYamlFiles(itemsDir, testSelectedFiles);
55+
56+
return { props: { data: data, bodyClasses: cheatsheetBodyClasses } };
1357
}
1458

15-
export function App() {
59+
export function App({data} : { data:any }) {
1660
return (
1761
<>
1862
<Head>
1963
<title>Cursorless cheatsheet</title>
2064
</Head>
21-
<TestCaseComponentPage />
65+
<TestCaseComponentPage data={data} />
2266
</>
2367
);
2468
}

0 commit comments

Comments
 (0)