|
1 | 1 | import {
|
2 | 2 | TestCaseComponentPage
|
3 | 3 | } from "@cursorless/test-case-component";
|
| 4 | + |
4 | 5 | import {
|
5 | 6 | cheatsheetBodyClasses,
|
6 | 7 | } from "@cursorless/cheatsheet";
|
7 | 8 |
|
| 9 | +import * as yaml from "js-yaml"; |
| 10 | +import fs from 'fs'; |
| 11 | +import path from 'path'; |
| 12 | + |
8 | 13 | import Head from "next/head";
|
9 | 14 |
|
| 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 | + |
10 | 44 | // See https://github.com/vercel/next.js/discussions/12325#discussioncomment-1116108
|
11 | 45 | 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 } }; |
13 | 57 | }
|
14 | 58 |
|
15 |
| -export function App() { |
| 59 | +export function App({data} : { data:any }) { |
16 | 60 | return (
|
17 | 61 | <>
|
18 | 62 | <Head>
|
19 | 63 | <title>Cursorless cheatsheet</title>
|
20 | 64 | </Head>
|
21 |
| - <TestCaseComponentPage /> |
| 65 | + <TestCaseComponentPage data={data} /> |
22 | 66 | </>
|
23 | 67 | );
|
24 | 68 | }
|
|
0 commit comments