11import * as Piscina from 'piscina'
22import * as Path from 'node:path'
33import * as Process from 'node:process'
4+ import * as Crypto from 'node:crypto'
5+ import * as Fs from 'node:fs'
46import PackageJson from '@npmcli/package-json'
57import { Build , type BuildOptions } from './build-core.js'
68
@@ -26,6 +28,37 @@ export class GroupedBuild extends Build {
2628 }
2729 return Result
2830 }
31+
32+ async MakeGroupMetadata ( ) {
33+ const MetadataObj : {
34+ DomainMapping : Record < string , string > ,
35+ FileMapping : Record < string , { SHA386 : string , FileName : string } >
36+ } = {
37+ DomainMapping : { } ,
38+ FileMapping : { }
39+ }
40+
41+ const FileNameList : Set < Set < string > > = this . TransformDomainSetToFileName ( new Set < Set < string > > ( this . FetchedDomains . get ( 'EachDomain' ) ) )
42+ const MatchingDomains : Set < Set < string > > = new Set < Set < string > > ( this . FetchedDomains . get ( 'EachDomainFull' ) )
43+
44+ for ( let I = 0 ; I < FileNameList . size ; I ++ ) {
45+ const FileName = [ ...[ ...FileNameList ] [ I ] ] [ 0 ]
46+ const Domains = [ ...MatchingDomains ] [ I ]
47+ const FilePath = `${ this . ProjectRoot } /dist/grouped/${ FileName [ 0 ] } /tinyShield-${ FileName } .user.js`
48+ const FileContent = await Fs . promises . readFile ( FilePath )
49+ const SHA386Hash = Crypto . createHash ( 'sha384' ) . update ( FileContent ) . digest ( 'hex' ) . toUpperCase ( )
50+
51+ for ( const Domain of Domains ) {
52+ MetadataObj . DomainMapping [ Domain ] = FileName
53+ MetadataObj . FileMapping [ FileName ] = {
54+ SHA386 : SHA386Hash ,
55+ FileName : `tinyShield-${ FileName } .user.js`
56+ }
57+ }
58+ }
59+
60+ await Fs . promises . writeFile ( `${ this . ProjectRoot } /dist/grouped/metadata.json` , JSON . stringify ( MetadataObj , null , 2 ) , 'utf-8' )
61+ }
2962
3063 async Build ( ) {
3164 if ( ! this . Options ) {
0 commit comments