@@ -40,30 +40,46 @@ function updateTransformREADME(transformName) {
40
40
return ;
41
41
}
42
42
43
- fs . readdirSync ( fixtureDir )
44
- . filter ( filename => / \. i n p u t $ / . test ( path . basename ( filename , path . extname ( filename ) ) ) )
45
- . forEach ( filename => {
46
- let extension = path . extname ( filename ) ;
47
- let testName = filename . replace ( `.input${ extension } ` , '' ) ;
48
- let inputPath = path . join ( fixtureDir , `${ testName } .input${ extension } ` ) ;
49
- let outputPath = path . join ( fixtureDir , `${ testName } .output${ extension } ` ) ;
50
-
51
- toc . push ( `* [${ testName } ](#${ testName } )` ) ;
52
- details . push (
53
- '---' ,
54
- `<a id="${ testName } ">**${ testName } **</a>` ,
55
- '' ,
56
- `**Input** (<small>[${ testName } .input${ extension } ](${ inputPath } )</small>):` ,
57
- '```' + extension . slice ( 1 ) ,
58
- fs . readFileSync ( inputPath ) ,
59
- '```' ,
60
- '' ,
61
- `**Output** (<small>[${ testName } .output${ extension } ](${ outputPath } )</small>):` ,
62
- '```' + extension . slice ( 1 ) ,
63
- fs . readFileSync ( outputPath ) ,
64
- '```'
65
- ) ;
66
- } ) ;
43
+ const testMap = fs . readdirSync ( fixtureDir ) . reduce ( ( _hash , filename ) => {
44
+ const extension = path . extname ( filename ) ;
45
+ const validFilename = path . basename ( filename ) . match ( / i n p u t | o u t p u t + (? = \. ) / ) ;
46
+ if ( ! validFilename ) {
47
+ return _hash ;
48
+ }
49
+ const testName = filename . slice ( 0 , validFilename . index - 1 ) ;
50
+ const testType = validFilename [ 0 ] ;
51
+
52
+ if ( ! _hash [ testName ] ) {
53
+ _hash [ testName ] = { } ;
54
+ }
55
+
56
+ _hash [ testName ] [ testType ] = `${ testName } .${ testType } ${ extension } ` ;
57
+
58
+ return _hash ;
59
+ } , { } ) ;
60
+
61
+ Object . entries ( testMap ) . forEach ( ( [ testName , testPaths ] ) => {
62
+ let inputExtension = path . extname ( testPaths . input ) ;
63
+ let outputExtension = path . extname ( testPaths . output ) ;
64
+ let inputPath = path . join ( fixtureDir , testPaths . input ) ;
65
+ let outputPath = path . join ( fixtureDir , testPaths . output ) ;
66
+
67
+ toc . push ( `* [${ testName } ](#${ testName } )` ) ;
68
+ details . push (
69
+ '---' ,
70
+ `<a id="${ testName } ">**${ testName } **</a>` ,
71
+ '' ,
72
+ `**Input** (<small>[${ testPaths . input } ](${ inputPath } )</small>):` ,
73
+ '```' + inputExtension . slice ( 1 ) ,
74
+ fs . readFileSync ( inputPath ) ,
75
+ '```' ,
76
+ '' ,
77
+ `**Output** (<small>[${ testPaths . output } ](${ outputPath } )</small>):` ,
78
+ '```' + outputExtension . slice ( 1 ) ,
79
+ fs . readFileSync ( outputPath ) ,
80
+ '```'
81
+ ) ;
82
+ } ) ;
67
83
68
84
let transformREADMEPath = `transforms/${ transformName } /README.md` ;
69
85
0 commit comments