@@ -257,10 +257,12 @@ ${fs.readFileSync(path('..', 'build', 'package.json')).toString()}
257257  ) ; 
258258
259259  //-----------------------------------------------------------------------------------------------------+ 
260-   // Copy to another folder. Azure does not support wildcard for `[email protected] ` |  260+   // Recalculate artifacts hash and copy to another folder (because they can change after signing them). 
261+   // Azure does not support wildcard for `[email protected] ` |  261262  //-----------------------------------------------------------------------------------------------------+ 
262263  if  ( isCI )  { 
263264    try  { 
265+       await  recalculateArtifactsHash ( ) ; 
264266      await  copyFilesToBuildArtifacts ( ) ; 
265267    }  catch  ( e )  { 
266268      echo ( JSON . stringify ( e ) ) ; 
@@ -400,6 +402,67 @@ ${fs.readFileSync(path('..', 'build', 'package.json')).toString()}
400402    } 
401403  } 
402404
405+   async  function  recalculateArtifactsHash ( )  { 
406+     echo ( `🚢  Detected CI, recalculating artifacts hash...` ) ; 
407+     const  {  platform }  =  process ; 
408+     const  cwd  =  path ( '..' ,  'build' ,  'dist' ) ; 
409+     const  channelFilePath  =  join ( cwd ,  getChannelFile ( platform ) ) ; 
410+     const  yaml  =  require ( 'yaml' ) ; 
411+ 
412+     try  { 
413+       let  fileContents  =  fs . readFileSync ( channelFilePath ,  'utf8' ) ; 
414+       const  newChannelFile  =  yaml . parse ( fileContents ) ; 
415+       const  {  files,  path }  =  newChannelFile ; 
416+       const  newSha512  =  await  hashFile ( join ( cwd ,  path ) ) ; 
417+       newChannelFile . sha512  =  newSha512 ; 
418+       if  ( ! ! files )  { 
419+         const  newFiles  =  [ ] ; 
420+         for  ( let  file  of  files )  { 
421+           const  {  url }  =  file ; 
422+           const  {  size }  =  fs . statSync ( join ( cwd ,  url ) ) ; 
423+           const  newSha512  =  await  hashFile ( join ( cwd ,  url ) ) ; 
424+           newFiles . push ( {  ...file ,  sha512 : newSha512 ,  size } ) ; 
425+         } 
426+         newChannelFile . files  =  newFiles ; 
427+       } 
428+ 
429+       const  newChannelFileRaw  =  yaml . stringify ( newChannelFile ) ; 
430+       fs . writeFileSync ( channelFilePath ,  newChannelFileRaw ) ; 
431+       echo ( `👌  >>> Channel file updated successfully. New channel file:` ) ; 
432+       echo ( newChannelFileRaw ) ; 
433+     }  catch  ( e )  { 
434+       console . log ( e ) ; 
435+     } 
436+   } 
437+ 
438+   async  function  hashFile ( 
439+     file , 
440+     algorithm  =  'sha512' , 
441+     encoding  =  'base64' , 
442+     options 
443+   )  { 
444+     const  crypto  =  require ( 'crypto' ) ; 
445+     return  await  new  Promise ( ( resolve ,  reject )  =>  { 
446+       const  hash  =  crypto . createHash ( algorithm ) ; 
447+       hash . on ( 'error' ,  reject ) . setEncoding ( encoding ) ; 
448+       fs . createReadStream ( 
449+         file , 
450+         Object . assign ( { } ,  options ,  { 
451+           highWaterMark : 1024  *  1024 , 
452+           /* better to use more memory but hash faster */ 
453+         } ) 
454+       ) 
455+         . on ( 'error' ,  reject ) 
456+         . on ( 'end' ,  ( )  =>  { 
457+           hash . end ( ) ; 
458+           resolve ( hash . read ( ) ) ; 
459+         } ) 
460+         . pipe ( hash ,  { 
461+           end : false , 
462+         } ) ; 
463+     } ) ; 
464+   } 
465+ 
403466  /** 
404467   * Joins tha path from `__dirname`. 
405468   */ 
0 commit comments