1
- import * as yaml from "js-yaml" ;
2
- import fs from "fs" ;
3
- import path from "path" ;
4
1
import Head from "next/head" ;
5
2
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" ;
8
7
import type { TestCaseFixture } from "@cursorless/common" ;
9
- import { testSelectedFiles } from "./allowList" ;
10
-
11
8
import { cheatsheetBodyClasses } from "@cursorless/cheatsheet" ;
12
9
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
-
84
10
// See https://github.com/vercel/next.js/discussions/12325#discussioncomment-1116108
85
11
export 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 } } ;
91
13
}
92
14
93
15
export type TestCaseComponentProps = TestCaseFixture & {
@@ -100,7 +22,6 @@ export type TestCaseComponentProps = TestCaseFixture & {
100
22
} ;
101
23
102
24
export function App ( {
103
- data,
104
25
debug,
105
26
} : {
106
27
data : TestCaseComponentProps [ ] ;
@@ -111,7 +32,9 @@ export function App({
111
32
< Head >
112
33
< title > Cursorless Test Case Component Page</ title >
113
34
</ Head >
114
- < TestCaseComponentPage data = { data } debug = { debug } />
35
+ { Object . keys ( testCasesByLanguage ) . map ( ( language ) => (
36
+ < ShikiComponentList key = { language } language = { language } debug = { debug } />
37
+ ) ) }
115
38
</ >
116
39
) ;
117
40
}
0 commit comments