1
1
import { parse , SEPARATOR_PATTERN } from '@std/path'
2
2
import * as posix from '@std/path/posix'
3
3
import { type BIDSFile , FileTree } from '../types/filetree.ts'
4
+ import { FileIgnoreRules } from './ignore.ts'
4
5
5
6
const nullFile = {
6
7
size : 0 ,
7
- ignored : false ,
8
8
stream : new ReadableStream ( ) ,
9
9
text : ( ) => Promise . resolve ( '' ) ,
10
10
readBytes : async ( size : number , offset ?: number ) => new Uint8Array ( ) ,
11
11
parent : new FileTree ( '' , '/' ) ,
12
12
viewed : false ,
13
13
}
14
14
15
- export function pathToFile ( path : string ) : BIDSFile {
15
+ export function pathToFile ( path : string , ignored : boolean = false ) : BIDSFile {
16
16
const name = path . split ( '/' ) . pop ( ) as string
17
- return { name, path, ...nullFile }
17
+ return { name, path, ignored , ...nullFile }
18
18
}
19
19
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 ) ) ) )
22
23
}
23
24
24
- export function filesToTree ( fileList : BIDSFile [ ] ) : FileTree {
25
+ export function filesToTree ( fileList : BIDSFile [ ] , ignore ?: FileIgnoreRules ) : FileTree {
26
+ ignore = ignore ?? new FileIgnoreRules ( [ ] )
25
27
const tree : FileTree = new FileTree ( '/' , '/' )
26
28
for ( const file of fileList ) {
27
29
const parts = parse ( file . path )
@@ -37,7 +39,7 @@ export function filesToTree(fileList: BIDSFile[]): FileTree {
37
39
current = exists
38
40
continue
39
41
}
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 )
41
43
current . directories . push ( newTree )
42
44
current = newTree
43
45
}
0 commit comments