@@ -21,14 +21,19 @@ interface CommandOptions extends Options {
2121export const command = new Command ( "crashlytics:sourcemap:upload <mappingFiles>" )
2222 . description ( "upload javascript source maps to de-minify stack traces" )
2323 . option ( "--app <appID>" , "the app id of your Firebase app" )
24- . option ( "--bucket-location <bucketLocation>" , "the location of the Google Cloud Storage bucket (default: \"US-CENTRAL1\"" )
25- . option ( "--app-version <appVersion>" , "the version of your Firebase app (defaults to Git commit hash, if available)" )
24+ . option (
25+ "--bucket-location <bucketLocation>" ,
26+ 'the location of the Google Cloud Storage bucket (default: "US-CENTRAL1"' ,
27+ )
28+ . option (
29+ "--app-version <appVersion>" ,
30+ "the version of your Firebase app (defaults to Git commit hash, if available)" ,
31+ )
2632 . action ( async ( mappingFiles : string , options : CommandOptions ) => {
27- const app = getGoogleAppID ( options ) ;
28- const debug = ! ! options . debug ;
33+ checkGoogleAppID ( options ) ;
2934
3035 // App version
31- const appVersion = getAppVersion ( options ) ;
36+ const appVersion = getAppVersion ( ) ;
3237
3338 // Get project identifiers
3439 const projectId = needProjectId ( options ) ;
@@ -42,7 +47,7 @@ export const command = new Command("crashlytics:sourcemap:upload <mappingFiles>"
4247 const filePath = path . relative ( rootDir , mappingFiles ) ;
4348 let fstat : fs . Stats ;
4449 try {
45- fstat = statSync ( filePath )
50+ fstat = statSync ( filePath ) ;
4651 } catch ( e ) {
4752 throw new FirebaseError (
4853 "provide a valid file path or directory to mapping file(s), e.g. app/build/outputs/app.js.map or app/build/outputs" ,
@@ -52,10 +57,11 @@ export const command = new Command("crashlytics:sourcemap:upload <mappingFiles>"
5257 await uploadMap ( mappingFiles , bucketName , appVersion , options ) ;
5358 } else if ( fstat . isDirectory ( ) ) {
5459 logLabeledBullet ( "crashlytics" , "Looking for mapping files in your directory..." ) ;
55- const files = ( await readdirRecursive ( { path : filePath , ignore : [ "node_modules" , ".git" ] } ) )
56- . filter ( f => f . name . endsWith ( '.js.map' ) ) ;
60+ const files = (
61+ await readdirRecursive ( { path : filePath , ignore : [ "node_modules" , ".git" ] } )
62+ ) . filter ( ( f ) => f . name . endsWith ( ".js.map" ) ) ;
5763 for ( const file of files ) {
58- await uploadMap ( file . name , bucketName , appVersion , options ) ;
64+ await uploadMap ( file . name , bucketName , appVersion , options ) ;
5965 }
6066 } else {
6167 throw new FirebaseError (
@@ -66,26 +72,32 @@ export const command = new Command("crashlytics:sourcemap:upload <mappingFiles>"
6672 // TODO: notify Firebase Telemetry service of the new mapping file
6773 } ) ;
6874
69- function getGoogleAppID ( options : CommandOptions ) : string {
75+ function checkGoogleAppID ( options : CommandOptions ) : void {
7076 if ( ! options . app ) {
7177 throw new FirebaseError (
7278 "set --app <appId> to a valid Firebase application id, e.g. 1:00000000:android:0000000" ,
7379 ) ;
7480 }
75- return options . app ;
7681}
7782
78- function getAppVersion ( options : CommandOptions ) : string {
83+ function getAppVersion ( ) : string {
7984 // TODO: implement app version lookup
8085 return "default" ;
8186}
8287
83- async function upsertBucket ( projectId : string , projectNumber : string , options : CommandOptions ) : Promise < string > {
84- let loc : string = 'US-CENTRAL1' ;
88+ async function upsertBucket (
89+ projectId : string ,
90+ projectNumber : string ,
91+ options : CommandOptions ,
92+ ) : Promise < string > {
93+ let loc : string = "US-CENTRAL1" ;
8594 if ( options . bucketLocation ) {
8695 loc = ( options . bucketLocation as string ) . toUpperCase ( ) ;
8796 } else {
88- logLabeledBullet ( "crashlytics" , "No Google Cloud Storage bucket location specified. Defaulting to US-CENTRAL1." ) ;
97+ logLabeledBullet (
98+ "crashlytics" ,
99+ "No Google Cloud Storage bucket location specified. Defaulting to US-CENTRAL1." ,
100+ ) ;
89101 }
90102
91103 const baseName = `firebasecrashlytics-sourcemaps-${ projectNumber } -${ loc . toLowerCase ( ) } ` ;
@@ -113,11 +125,16 @@ async function upsertBucket(projectId: string, projectNumber: string, options: C
113125 } ) ;
114126}
115127
116- async function uploadMap ( mappingFile : string , bucketName : string , appVersion : string , options : CommandOptions ) {
128+ async function uploadMap (
129+ mappingFile : string ,
130+ bucketName : string ,
131+ appVersion : string ,
132+ options : CommandOptions ,
133+ ) {
117134 logLabeledBullet ( "crashlytics" , `Found mapping file ${ mappingFile } ...` ) ;
118135 try {
119136 const tmpArchive = await createArchive ( mappingFile , options ) ;
120- const gcsFile = `${ options . app } -${ appVersion } -${ normalizeFileName ( mappingFile ) } .zip`
137+ const gcsFile = `${ options . app } -${ appVersion } -${ normalizeFileName ( mappingFile ) } .zip` ;
121138
122139 const { bucket, object } = await gcs . uploadObject (
123140 {
@@ -142,7 +159,7 @@ async function createArchive(mappingFile: string, options: CommandOptions): Prom
142159 const archive = archiver ( "zip" ) ;
143160 const rootDir = options . projectRoot ?? process . cwd ( ) ;
144161 const name = path . relative ( rootDir , mappingFile ) ;
145- archive . file ( name , { name : ' mapping.js.map' } ) ;
162+ archive . file ( name , { name : " mapping.js.map" } ) ;
146163 await pipeAsync ( archive , fileStream ) ;
147164 return tmpFile ;
148165}
@@ -157,5 +174,5 @@ async function pipeAsync(from: archiver.Archiver, to: fs.WriteStream): Promise<v
157174}
158175
159176function normalizeFileName ( fileName : string ) : string {
160- return fileName . replaceAll ( / \/ / g, '-' ) ;
161- }
177+ return fileName . replaceAll ( / \/ / g, "-" ) ;
178+ }
0 commit comments