1- import { GlobSync } from "glob" ;
21import { filesystem } from "@discloudapp/gluegun" ;
2+ import { GlobSync } from "glob" ;
33import { existsSync , readFileSync } from "node:fs" ;
44import { blocked_files } from "./constants" ;
55
66export class GS {
7- found : string [ ] ;
8- ignore : string [ ] ;
7+ found : string [ ] = [ ] ;
8+ ignore : string [ ] = [ ] ;
9+ ignoreFiles : string [ ] = [ ] ;
910
10- constructor ( public path = "**" ) {
11+ constructor ( public path = "**" , ignoreFileName ?: string ) {
1112 this . path = path = this . normalizePath ( path ) ;
1213
14+ if ( ignoreFileName )
15+ this . ignoreFiles = this . findIgnoreFiles ( ignoreFileName ) ;
16+
1317 this . ignore = this . getDiscloudIgnore ( path ) ;
1418
1519 this . found = new GlobSync ( path , {
1620 dot : true ,
1721 ignore : this . ignore ,
22+ windowsPathsNoEscape : true ,
1823 } ) . found ;
1924 }
2025
2126 getDiscloudIgnore ( path : string ) {
2227 return [
2328 ...new Set ( Object . values ( blocked_files ) . flat ( ) ) ,
24- ...this . resolveIgnoreFile ( ".discloudignore" ) ,
29+ ...this . resolveIgnoreFile ( this . ignoreFiles ) ,
2530 ]
2631 . map ( a => [ a , `${ a } /**` , `**/${ a } ` , `**/${ a } /**` , `${ path } /${ a } ` , `${ path } /${ a } /**` ] ) . flat ( ) ;
2732 }
@@ -32,6 +37,17 @@ export class GS {
3237 return path ;
3338 }
3439
40+ findIgnoreFiles ( fileName : string , path = "**" ) {
41+ const regex = RegExp ( `${ fileName } $` ) ;
42+
43+ const files = new GlobSync ( path , {
44+ dot : true ,
45+ windowsPathsNoEscape : true ,
46+ } ) ;
47+
48+ return files . found . filter ( f => regex . test ( f ) ) ;
49+ }
50+
3551 resolveIgnoreFile ( ignoreFile : string | string [ ] ) {
3652 if ( Array . isArray ( ignoreFile ) ) {
3753 const ignored = < string [ ] > [ ] ;
@@ -42,11 +58,12 @@ export class GS {
4258 return ignored ;
4359 }
4460
45- if ( existsSync ( ignoreFile ) )
46- return readFileSync ( ignoreFile , "utf8" )
47- . replace ( / # [ ^ \r ? \n ] + / g, "" )
48- . split ( / \r ? \n / )
49- . filter ( a => a ) ;
61+ if ( ignoreFile )
62+ if ( existsSync ( ignoreFile ) )
63+ return readFileSync ( ignoreFile , "utf8" )
64+ . replace ( / # [ ^ \r ? \n ] + / g, "" )
65+ . split ( / \r ? \n / )
66+ . filter ( a => a ) ;
5067
5168 return [ ] ;
5269 }
0 commit comments