11import { parse , SEPARATOR_PATTERN } from '@std/path'
22import * as posix from '@std/path/posix'
33import { type BIDSFile , FileTree } from '../types/filetree.ts'
4+ import { FileIgnoreRules } from './ignore.ts'
45
56const nullFile = {
67 size : 0 ,
7- ignored : false ,
88 stream : new ReadableStream ( ) ,
99 text : ( ) => Promise . resolve ( '' ) ,
1010 readBytes : async ( size : number , offset ?: number ) => new Uint8Array ( ) ,
1111 parent : new FileTree ( '' , '/' ) ,
1212 viewed : false ,
1313}
1414
15- export function pathToFile ( path : string ) : BIDSFile {
15+ export function pathToFile ( path : string , ignored : boolean = false ) : BIDSFile {
1616 const name = path . split ( '/' ) . pop ( ) as string
17- return { name, path, ...nullFile }
17+ return { name, path, ignored , ...nullFile }
1818}
1919
20- export function pathsToTree ( paths : string [ ] ) : FileTree {
21- return filesToTree ( paths . map ( pathToFile ) )
20+ export function pathsToTree ( paths : string [ ] , ignore ?: string [ ] ) : FileTree {
21+ const ignoreRules = new FileIgnoreRules ( ignore ?? [ ] )
22+ return filesToTree ( paths . map ( ( path ) => pathToFile ( path , ignoreRules . test ( path ) ) ) )
2223}
2324
24- export function filesToTree ( fileList : BIDSFile [ ] ) : FileTree {
25+ export function filesToTree ( fileList : BIDSFile [ ] , ignore ?: FileIgnoreRules ) : FileTree {
26+ ignore = ignore ?? new FileIgnoreRules ( [ ] )
2527 const tree : FileTree = new FileTree ( '/' , '/' )
2628 for ( const file of fileList ) {
2729 const parts = parse ( file . path )
@@ -37,7 +39,7 @@ export function filesToTree(fileList: BIDSFile[]): FileTree {
3739 current = exists
3840 continue
3941 }
40- const newTree = new FileTree ( posix . join ( current . path , level ) , level , current )
42+ const newTree = new FileTree ( posix . join ( current . path , level ) , level , current , ignore )
4143 current . directories . push ( newTree )
4244 current = newTree
4345 }
0 commit comments