@@ -100,22 +100,33 @@ export async function readFileToUint8Array(filePath: string): Promise<Uint8Array
100100 } ) ;
101101}
102102
103+ export function getBinaryFilesFromPath ( fileOrFolderPath : string ) : string [ ] {
104+ if ( ! fs . existsSync ( fileOrFolderPath ) ) {
105+ throw new Error ( `File or Folder not exits ${ fileOrFolderPath } ` ) ;
106+ }
107+ // Check if the provided path is a directory
108+ if ( fs . lstatSync ( fileOrFolderPath ) . isDirectory ( ) ) {
109+ return listBinaryFilesInFolder ( fileOrFolderPath ) ;
110+ }
111+
112+ if ( fs . lstatSync ( fileOrFolderPath ) . isFile ( ) && isBinaryFile ( fileOrFolderPath ) ) {
113+ return [ fileOrFolderPath ] ;
114+ }
115+
116+ throw new Error ( `${ fileOrFolderPath } is not a valid path to deploy scripts.` ) ;
117+ }
118+
103119export function listBinaryFilesInFolder ( folderPath : string ) : string [ ] {
104120 // Check if the provided path is a directory
105121 if ( ! fs . existsSync ( folderPath ) || ! fs . lstatSync ( folderPath ) . isDirectory ( ) ) {
106122 throw new Error ( `${ folderPath } is not a valid directory.` ) ;
107123 }
108124
109125 // Read the contents of the directory
110- const files = fs . readdirSync ( folderPath ) ;
126+ const files = fs . readdirSync ( folderPath ) . map ( ( f ) => path . join ( folderPath , f ) ) ;
111127
112128 // Filter out only the binary files (assuming they have extensions like .exe, .bin, .dll, etc.)
113- const binaryFiles = files . filter ( ( file ) => {
114- const filePath = path . join ( folderPath , file ) ;
115- // Check if the file is a regular file and not a directory
116- return fs . statSync ( filePath ) . isFile ( ) && isBinaryFile ( filePath ) ;
117- } ) ;
118-
129+ const binaryFiles = files . filter ( ( file ) => fs . statSync ( file ) . isFile ( ) && isBinaryFile ( file ) ) ;
119130 return binaryFiles ;
120131}
121132
0 commit comments