1- import * as yaml from "js-yaml" ;
2- import fs from "fs" ;
3- import path from "path" ;
41import Head from "next/head" ;
52
6- import { loadTestCaseFixture } from "@cursorless/test-case-component" ;
7- import { TestCaseComponentPage } from "@cursorless/test-case-component" ;
3+ import {
4+ ShikiComponentList ,
5+ testCasesByLanguage ,
6+ } from "@cursorless/test-case-component" ;
87import type { TestCaseFixture } from "@cursorless/common" ;
9- import { testSelectedFiles } from "./allowList" ;
10-
118import { cheatsheetBodyClasses } from "@cursorless/cheatsheet" ;
129
13- const fixturesDir = path . join ( "../" , "../" , "data" , "example-files" ) ;
14-
15- async function loadYamlFiles ( dir : string , allowList ?: string [ ] ) {
16- const directoryPath = path . join ( process . cwd ( ) , dir ) ;
17- const files = fs . readdirSync ( directoryPath ) ;
18- const data : any [ ] = [ ] ;
19-
20- files . forEach ( ( file ) => {
21- if (
22- path . extname ( file ) === ".yml" &&
23- ( ! allowList || allowList . includes ( file ) )
24- ) {
25- try {
26- const filePath = path . join ( directoryPath , file ) ;
27- const fileContents = fs . readFileSync ( filePath , "utf8" ) ;
28- const yamlData : any = yaml . load ( fileContents ) ;
29- yamlData . filename = file ;
30- data . push ( yamlData ) ;
31- } catch {
32- console . error ( "File load failure" , file ) ;
33- }
34- }
35- } ) ;
36-
37- return data ;
38- }
39-
40- // Change argument to a single object for loadAndProcessFixtures
41- interface LoadAndProcessFixturesOptions {
42- fixturesDir : string ;
43- allowList ?: string [ ] ;
44- }
45-
46- /**
47- * Loads YAML test case files from a directory, processes them into fixtures, and returns an array of processed test case data.
48- * Optionally filters which files to load using an allow list.
49- *
50- * @param {Object } options - Options for loading and processing fixtures.
51- * @param {string } options.fixturesDir - Directory containing YAML fixture files.
52- * @param {string[]= } options.allowList - Optional list of filenames to include.
53- * @returns {Promise<any[]> } Array of processed test case data, each with a `raw` property containing the original YAML object.
54- */
55- async function loadAndProcessFixtures ( {
56- fixturesDir,
57- allowList,
58- } : LoadAndProcessFixturesOptions ) {
59- const dataActions = await loadYamlFiles ( fixturesDir , allowList ) ;
60- const data_errors : any [ ] = [ ] ;
61-
62- const data = (
63- await Promise . all (
64- dataActions . map ( async ( val ) => {
65- try {
66- const fixture = await loadTestCaseFixture ( val ) ;
67- return { ...fixture , raw : val } ;
68- } catch ( err ) {
69- console . error ( err ) ;
70- data_errors . push ( val ) ;
71- return null ;
72- }
73- } ) ,
74- )
75- ) . filter ( ( test ) => test != null ) ;
76-
77- if ( data_errors . length > 0 ) {
78- console . error ( "data errors:" , data_errors ) ;
79- }
80-
81- return data ;
82- }
83-
8410// See https://github.com/vercel/next.js/discussions/12325#discussioncomment-1116108
8511export async function getStaticProps ( ) {
86- const data = await loadAndProcessFixtures ( {
87- fixturesDir,
88- allowList : testSelectedFiles ,
89- } ) ;
90- return { props : { data, bodyClasses : cheatsheetBodyClasses } } ;
12+ return { props : { bodyClasses : cheatsheetBodyClasses } } ;
9113}
9214
9315export type TestCaseComponentProps = TestCaseFixture & {
@@ -100,7 +22,6 @@ export type TestCaseComponentProps = TestCaseFixture & {
10022} ;
10123
10224export function App ( {
103- data,
10425 debug,
10526} : {
10627 data : TestCaseComponentProps [ ] ;
@@ -111,7 +32,9 @@ export function App({
11132 < Head >
11233 < title > Cursorless Test Case Component Page</ title >
11334 </ Head >
114- < TestCaseComponentPage data = { data } debug = { debug } />
35+ { Object . keys ( testCasesByLanguage ) . map ( ( language ) => (
36+ < ShikiComponentList key = { language } language = { language } debug = { debug } />
37+ ) ) }
11538 </ >
11639 ) ;
11740}
0 commit comments