@@ -8,24 +8,54 @@ export interface UploadSoFilesOptions {
88 token : string ;
99 name : string ;
1010 api_key : string ;
11+
12+ /**
13+ * Disables logging to the console and prevents process exit on error.
14+ *
15+ * @default false
16+ * */
17+ silent ?: boolean ;
1118}
1219
13- export const uploadSoFiles = async ( opts : UploadSoFilesOptions ) => {
20+ /**
21+ * Uploads NDK `.so` files to Instabug.
22+ *
23+ * @param opts Options for the `.so` files upload process.
24+ * @returns A promise that resolves to a boolean indicating whether the upload was successful.
25+ */
26+ export const uploadSoFiles = async ( opts : UploadSoFilesOptions ) : Promise < boolean > => {
1427 const fileName = opts . file ;
15- if ( fileName == null ) {
16- console . error ( 'Failed to upload So Files: invalid file path' ) ;
17- process . exit ( 1 ) ;
28+
29+ const validFilePath = assert (
30+ fileName != null ,
31+ 'Failed to upload So Files: invalid file path' ,
32+ opts . silent ,
33+ ) ;
34+
35+ if ( ! validFilePath ) {
36+ return false ;
1837 }
1938
20- if ( fs . existsSync ( fileName ) === false ) {
21- console . error ( 'Failed to upload So Files: File not found' ) ;
22- process . exit ( 1 ) ;
39+ const fileExists = assert (
40+ fs . existsSync ( fileName ) ,
41+ 'Failed to upload So Files: File not found' ,
42+ opts . silent ,
43+ ) ;
44+
45+ if ( ! fileExists ) {
46+ return false ;
2347 }
24- var fileExt = fileName . split ( '.' ) . pop ( ) ;
2548
26- if ( fileExt !== 'zip' ) {
27- console . error ( 'Failed to upload So Files: You can only upload ZIP files' ) ;
28- process . exit ( 1 ) ;
49+ const fileExt = fileName . split ( '.' ) . pop ( ) ;
50+
51+ const isZipFile = assert (
52+ fileExt === 'zip' ,
53+ 'Failed to upload So Files: You can only upload ZIP files' ,
54+ opts . silent ,
55+ ) ;
56+
57+ if ( ! isZipFile ) {
58+ return false ;
2959 }
3060
3161 const fileBlob = fs . readFileSync ( opts . file ) ;
@@ -37,16 +67,46 @@ export const uploadSoFiles = async (opts: UploadSoFilesOptions) => {
3767 form . append ( 'api_key' , opts . api_key ) ;
3868 form . append ( 'arch' , opts . arch ) ;
3969
40- console . log ( 'Uploading So files...' ) ;
70+ if ( ! opts . silent ) {
71+ console . log ( 'Uploading So files...' ) ;
72+ }
73+
4174 const uploadEndpoint = 'https://api.instabug.com/api/web/public/so_files' ;
4275 try {
4376 await axios . post ( uploadEndpoint , form , {
4477 headers : form . getHeaders ( ) ,
4578 } ) ;
4679
47- console . log ( `Successfully uploaded So Files for version: ${ opts . name } with arch ${ opts . arch } ` ) ;
80+ if ( ! opts . silent ) {
81+ console . log (
82+ `Successfully uploaded So Files for version: ${ opts . name } with arch ${ opts . arch } ` ,
83+ ) ;
84+ }
85+
86+ return true ;
4887 } catch ( err ) {
49- console . error ( 'Failed to upload So Files:' , axios . isAxiosError ( err ) ? err . response ?. data : err ) ;
88+ if ( ! opts . silent ) {
89+ console . error (
90+ 'Failed to upload So Files:' ,
91+ axios . isAxiosError ( err ) ? err . response ?. data : err ,
92+ ) ;
93+
94+ process . exit ( 1 ) ;
95+ }
96+
97+ return false ;
98+ }
99+ } ;
100+
101+ export const assert = ( condition : unknown , message : string , silent ?: boolean ) : boolean => {
102+ if ( silent ) {
103+ return Boolean ( condition ) ;
104+ }
105+
106+ if ( ! condition ) {
107+ console . error ( message ) ;
50108 process . exit ( 1 ) ;
51109 }
110+
111+ return true ;
52112} ;
0 commit comments