@@ -4,6 +4,7 @@ import { afterAll, assert, beforeAll, describe, expect, it } from 'vitest';
44import { cli } from '../src/cli' ;
55import type { Manifest } from '../src/types' ;
66import {
7+ createShouldIncludeFile ,
78 shouldIncludeBlock ,
89 shouldIncludeCategory ,
910 shouldListBlock ,
@@ -65,6 +66,7 @@ describe('build', () => {
6566 dirs : [ './src' , './' ] ,
6667 includeBlocks : [ ] ,
6768 includeCategories : [ ] ,
69+ includeFiles : [ 'src/utils/block-with-asset/asset.txt' ] ,
6870 excludeBlocks : [ ] ,
6971 excludeCategories : [ 'src' ] ,
7072 doNotListBlocks : [ 'noop' ] ,
@@ -206,6 +208,19 @@ export const highlighter = createHighlighterCore({
206208</script>`
207209 ) ;
208210
211+ fs . mkdirSync ( './src/utils/block-with-asset' , { recursive : true } ) ;
212+
213+ fs . writeFileSync (
214+ './src/utils/block-with-asset/index.ts' ,
215+ `import { fs } from 'node:fs';
216+
217+ const result = fs.readFileSync(new URL('./asset.txt', import.meta.url), 'utf-8');
218+ console.log(result);
219+ `
220+ ) ;
221+
222+ fs . writeFileSync ( './src/utils/block-with-asset/asset.txt' , 'This is an asset file.' ) ;
223+
209224 // build
210225
211226 await cli . parseAsync ( [
@@ -321,6 +336,20 @@ export const highlighter = createHighlighterCore({
321336 './log' : '{{utils/log}}' ,
322337 } ,
323338 } ,
339+ {
340+ _imports_ : { } ,
341+ category : 'utils' ,
342+ dependencies : [ ] ,
343+ devDependencies : [ ] ,
344+ directory : 'src/utils/block-with-asset' ,
345+ docs : false ,
346+ files : [ 'asset.txt' , 'index.ts' ] ,
347+ list : true ,
348+ localDependencies : [ ] ,
349+ name : 'block-with-asset' ,
350+ subdirectory : true ,
351+ tests : false ,
352+ } ,
324353 {
325354 name : 'form1' ,
326355 category : 'utils' ,
@@ -395,6 +424,7 @@ const defaultConfig = {
395424 excludeDeps : [ ] ,
396425 includeBlocks : [ ] ,
397426 includeCategories : [ ] ,
427+ includeFiles : [ ] ,
398428 excludeBlocks : [ ] ,
399429 excludeCategories : [ ] ,
400430} ;
@@ -518,3 +548,81 @@ describe('shouldIncludeCategory', () => {
518548 ) . toBe ( false ) ;
519549 } ) ;
520550} ) ;
551+
552+ describe ( 'shouldIncludeFile' , ( ) => {
553+ it ( 'does not list if unspecified' , ( ) => {
554+ expect (
555+ createShouldIncludeFile ( { ...defaultConfig , includeDocs : false } ) (
556+ 'utils/math/asset.txt'
557+ )
558+ ) . toBe ( false ) ;
559+ } ) ;
560+
561+ it ( 'can include a file when referenced directly' , ( ) => {
562+ expect (
563+ createShouldIncludeFile ( {
564+ ...defaultConfig ,
565+ includeFiles : [ '/utils/math/asset.txt' ] ,
566+ includeDocs : false ,
567+ } ) ( 'utils/math/asset.txt' )
568+ ) . toBe ( true ) ;
569+ } ) ;
570+
571+ it ( 'is lenient to leading slashes' , ( ) => {
572+ expect (
573+ createShouldIncludeFile ( {
574+ ...defaultConfig ,
575+ includeFiles : [ '/utils/math/asset.txt' ] ,
576+ includeDocs : false ,
577+ } ) ( 'utils/math/asset.txt' )
578+ ) . toBe ( true ) ;
579+ expect (
580+ createShouldIncludeFile ( {
581+ ...defaultConfig ,
582+ includeFiles : [ './utils/math/asset.txt' ] ,
583+ includeDocs : false ,
584+ } ) ( 'utils/math/asset.txt' )
585+ ) . toBe ( true ) ;
586+ } ) ;
587+
588+ it ( 'it can include all files of a certain extension' , ( ) => {
589+ expect (
590+ createShouldIncludeFile ( {
591+ ...defaultConfig ,
592+ includeFiles : [ '**/*.txt' ] ,
593+ includeDocs : false ,
594+ } ) ( 'utils/math/asset.txt' )
595+ ) . toBe ( true ) ;
596+ expect (
597+ createShouldIncludeFile ( {
598+ ...defaultConfig ,
599+ includeFiles : [ '**/*.png' ] ,
600+ includeDocs : false ,
601+ } ) ( 'utils/math/asset.png' )
602+ ) . toBe ( true ) ;
603+ expect (
604+ createShouldIncludeFile ( {
605+ ...defaultConfig ,
606+ includeFiles : [ '**/*.png' ] ,
607+ includeDocs : false ,
608+ } ) ( 'utils/math/asset.jpg' )
609+ ) . toBe ( false ) ;
610+ } ) ;
611+
612+ it ( 'it can include all files in a certain directory' , ( ) => {
613+ expect (
614+ createShouldIncludeFile ( {
615+ ...defaultConfig ,
616+ includeFiles : [ 'utils/math/files-to-include/**' ] ,
617+ includeDocs : false ,
618+ } ) ( 'utils/math/files-to-include/asset.txt' )
619+ ) . toBe ( true ) ;
620+ expect (
621+ createShouldIncludeFile ( {
622+ ...defaultConfig ,
623+ includeFiles : [ 'utils/math/files-to-include/**' ] ,
624+ includeDocs : false ,
625+ } ) ( 'utils/math/files-to-include/image.png' )
626+ ) . toBe ( true ) ;
627+ } ) ;
628+ } ) ;
0 commit comments