@@ -2,15 +2,17 @@ import { existsSync, readFileSync } from "fs";
22import { glob } from "glob" ;
33import yaml from "js-yaml" ;
44import path from "path" ;
5+ import { fileURLToPath } from "url" ;
56
67interface FrameworkManifest {
78 framework : string ;
89 scenarios : Record < string , unknown > ;
910}
1011
11- const ROOT = path . resolve ( import . meta. dirname , ".." ) ;
12+ const ROOT = path . resolve ( path . dirname ( fileURLToPath ( import . meta. url ) ) , ".." ) ;
1213const SAMPLES = path . join ( ROOT , "samples" ) ;
13- const TAG_PATTERN = / @ s n i p p e t : s t e p \d + : s t a r t / ;
14+ const TAG_START = / @ s n i p p e t : s t e p ( \d + ) : s t a r t / g;
15+ const TAG_END = / @ s n i p p e t : s t e p ( \d + ) : e n d / g;
1416
1517let errors = 0 ;
1618
@@ -51,9 +53,20 @@ async function main() {
5153 let hasSnippetTag = false ;
5254 for ( const file of sourceFiles ) {
5355 const fileContent = readFileSync ( path . join ( scenarioDir , file ) , "utf-8" ) ;
54- if ( TAG_PATTERN . test ( fileContent ) ) {
55- hasSnippetTag = true ;
56- break ;
56+ const starts = [ ...fileContent . matchAll ( TAG_START ) ] . map ( ( m ) => parseInt ( m [ 1 ] , 10 ) ) ;
57+ const ends = [ ...fileContent . matchAll ( TAG_END ) ] . map ( ( m ) => parseInt ( m [ 1 ] , 10 ) ) ;
58+
59+ if ( starts . length > 0 ) hasSnippetTag = true ;
60+
61+ for ( const step of starts ) {
62+ if ( ! ends . includes ( step ) ) {
63+ error ( `Missing @snippet:step${ step } :end in samples/${ manifest . framework } /${ dirName } /${ file } ` ) ;
64+ }
65+ }
66+ for ( const step of ends ) {
67+ if ( ! starts . includes ( step ) ) {
68+ error ( `Missing @snippet:step${ step } :start in samples/${ manifest . framework } /${ dirName } /${ file } ` ) ;
69+ }
5770 }
5871 }
5972
0 commit comments