@@ -17,27 +17,28 @@ import https from 'node:https';
1717import crypto from 'node:crypto' ;
1818
1919async function main ( ) {
20- const version = '1.0.0' ;
21- const expectedSha256BySuffix = {
22- "linux-arm64" : '69be61326f5d305ed5b0d27659bb5a6ecf2fc9fc517a1f7a1ed4a560011591dd' ,
23- "linux-x64" : '6050d404473c3fbba707513d8f99d3f10fc953e6fe6cc8a118b2a22c99ea1729' ,
24- "macos-arm64" : 'b9c227f429adbb7089b6b88ad1676e546bb57faf5c9abe5f22cdbafe90c61e1e' ,
25- "windows-x64" : 'e572cc627d7aee9fd7f3928ba9bd9004da367ce83cb58e54616d2a17872b2c5e' ,
26- } ;
27- const assetSuffix = resolveAssetSuffix ( ) ;
20+ const __filename = fileURLToPath ( import . meta. url ) ;
21+ const __dirname = path . dirname ( __filename ) ;
22+
23+ const checksums = JSON . parse ( fs . readFileSync ( path . resolve ( __dirname , 'previewer-checksums.json' ) , 'utf-8' ) ) ;
24+ const version = checksums . version ;
25+ const expectedSha256BySuffix = checksums . sha256 ;
26+
27+ if ( ! version || ! expectedSha256BySuffix || typeof expectedSha256BySuffix !== 'object' ) {
28+ throw new Error ( 'previewer-checksums.json must contain "version" and "sha256" properties' ) ;
29+ }
30+
31+ const assetSuffix = resolveAssetSuffix ( Object . keys ( expectedSha256BySuffix ) ) ;
2832 const expectedSha256 = expectedSha256BySuffix [ assetSuffix ] ;
2933 const assetName = `curity-ui-kit-previewer-${ version } -${ assetSuffix } .zip` ;
3034
3135 const libFolder = '../../lib/' ;
3236 const zipFile = assetName ;
33- const presenceFile = 'run-ui-kit-server.sh' ;
34- const __filename = fileURLToPath ( import . meta. url ) ;
35- const __dirname = path . dirname ( __filename ) ;
3637 const source = path . resolve ( __dirname , libFolder + zipFile ) ;
3738 const target = path . resolve ( __dirname , libFolder ) ;
38- const presence = path . join ( target , presenceFile ) ;
39+ const versionMarker = path . join ( target , '.previewer-version' ) ;
3940
40- if ( fs . existsSync ( presence ) ) {
41+ if ( fs . existsSync ( versionMarker ) && fs . readFileSync ( versionMarker , 'utf-8' ) . trim ( ) === version ) {
4142 console . log ( 'UI Kit runtime already unzipped. Skipping...' ) ;
4243 return ;
4344 }
@@ -47,21 +48,24 @@ async function main() {
4748 }
4849
4950 if ( ! fs . existsSync ( source ) ) {
50- console . error ( 'ui-kit-runtime. zip file does not exist:' , source ) ;
51+ console . error ( `Previewer zip does not exist: ${ source } ` ) ;
5152 process . exit ( 1 ) ;
5253 }
5354
54- if ( expectedSha256 ) {
55- await verifySha256 ( source , expectedSha256 ) ;
55+ if ( ! expectedSha256 ) {
56+ throw new Error ( `No checksum found for platform suffix ' ${ assetSuffix } ' in previewer-checksums.json` ) ;
5657 }
58+ await verifySha256 ( source , expectedSha256 ) ;
5759
5860 await extract ( source , { dir : target } ) ;
5961 console . log ( `Unzipped ${ source } to ${ target } ` ) ;
6062
6163 await extractNestedZip ( target , `ui-kit-runtime-${ version } .zip` ) ;
64+
65+ fs . writeFileSync ( versionMarker , version + '\n' ) ;
6266}
6367
64- function resolveAssetSuffix ( ) {
68+ function resolveAssetSuffix ( supportedSuffixes ) {
6569 const platformMap = {
6670 linux : 'linux' ,
6771 darwin : 'macos' ,
@@ -74,12 +78,13 @@ function resolveAssetSuffix() {
7478
7579 const platform = platformMap [ process . platform ] ;
7680 const arch = archMap [ process . arch ] ;
81+ const suffix = `${ platform } -${ arch } ` ;
7782
78- if ( ! platform || ! arch ) {
83+ if ( ! platform || ! arch || ! supportedSuffixes . includes ( suffix ) ) {
7984 throw new Error ( `Unsupported platform/arch: ${ process . platform } /${ process . arch } ` ) ;
8085 }
8186
82- return ` ${ platform } - ${ arch } ` ;
87+ return suffix ;
8388}
8489
8590function downloadPreviewerZip ( version , assetSuffix , assetName , destinationPath ) {
0 commit comments