@@ -30,18 +30,40 @@ if (!values.input || !values.output) {
3030 process . exit ( 1 ) ;
3131}
3232
33- const src = readFileSync ( values . input , 'utf8' ) ;
33+ const src = await open ( values . input , 'r' ) ;
34+
35+ const MARKER_RE = / ^ < ! - - \s * a d d o n - v e r i f y - f i l e \s + ( \S + ?) \/ ( \S + ) \s * - - > $ / ;
3436
35- // Collect files grouped by section directory name.
36- const MARKER_RE = / ^ < ! - - \s * a d d o n - v e r i f y - f i l e \s + ( \S + ?) \/ ( \S + ) \s * - - > $ / gm;
37- const FENCE_RE = / ` ` ` \w * \n ( [ \s \S ] * ?) \n ` ` ` / ;
3837const entries = [ ] ;
39- for ( const match of src . matchAll ( MARKER_RE ) ) {
40- const [ , dir , name ] = match ;
41- const after = src . slice ( match . index + match [ 0 ] . length ) ;
42- const content = after . match ( FENCE_RE ) ?. [ 1 ] ;
43- if ( content != null ) entries . push ( { dir, name, content } ) ;
38+ let nextBlockIsAddonVerifyFile = false ;
39+ let expectedClosingFenceMarker ;
40+ for await ( const line of src . readLines ( ) ) {
41+ if ( expectedClosingFenceMarker ) {
42+ // We're inside a Addon snippet
43+ if ( line === expectedClosingFenceMarker ) {
44+ // End of the snippet
45+ expectedClosingFenceMarker = null ;
46+ continue ;
47+ }
48+
49+ entries . at ( - 1 ) . content += `${ line } \n` ;
50+ }
51+ if ( nextBlockIsAddonVerifyFile ) {
52+ if ( line ) {
53+ expectedClosingFenceMarker = line . replace ( / \w / g, '' ) ;
54+ nextBlockIsAddonVerifyFile = false ;
55+ }
56+ continue ;
57+ }
58+ const match = MARKER_RE . exec ( line ) ;
59+ if ( match ) {
60+ nextBlockIsAddonVerifyFile = true ;
61+ const [ , dir , name ] = match ;
62+ entries . push ( { dir, name, content : '' } ) ;
63+ }
4464}
65+
66+ // Collect files grouped by section directory name.
4567const sections = Map . groupBy ( entries , ( e ) => e . dir ) ;
4668
4769let idx = 0 ;
0 commit comments