@@ -6,7 +6,6 @@ import * as ESBuild from 'esbuild'
66import * as Zod from 'zod'
77import PackageJson from '@npmcli/package-json'
88import * as Semver from 'semver'
9- import * as TsMorph from 'ts-morph'
109import * as Fs from 'node:fs'
1110import * as NodeHttps from 'node:https'
1211import * as Process from 'node:process'
@@ -79,35 +78,28 @@ for (const SellerEntry of IABSellersJsonData.sellers) {
7978}
8079console . log ( 'Collected' , DomainsList . size , 'unique domains from IAB Sellers.json' )
8180
82- const IndexFilePath = `./sources/src/#generated-${ crypto . randomUUID ( ) } .ts`
83- Fs . copyFileSync ( './sources/src/index.ts' , IndexFilePath )
84- Fs . chmodSync ( IndexFilePath , 0o700 )
85- const Project = new TsMorph . Project ( { tsConfigFilePath : './tsconfig.json' } )
86- const IndexFile = Project . getSourceFileOrThrow ( IndexFilePath )
87- const TargetedDomainsArray = IndexFile . getVariableDeclaration ( 'TargetedDomains' ) . getInitializerIfKindOrThrow ( TsMorph . SyntaxKind . ArrayLiteralExpression )
88- for ( const Domain of DomainsList ) {
89- TargetedDomainsArray . addElement ( `'${ Domain } '` )
90- }
91- await Project . save ( )
92- console . log ( 'Updated targeted domains in' , IndexFilePath , '; total domains:' , DomainsList . size )
93-
9481const HeaderLocation = './sources/banner.txt'
9582let ConvertedHeader : string = ''
9683for ( const Line of Fs . readFileSync ( HeaderLocation , 'utf-8' ) . split ( '\n' ) ) {
9784 if ( Line . includes ( '%%VERSION_VALUE%%' ) ) {
9885 ConvertedHeader += Line . replaceAll ( '%%VERSION_VALUE%%' , Version ) + '\n'
9986 } else if ( Line . includes ( '%%NAME%%' ) ) {
10087 ConvertedHeader += Line . replaceAll ( '%%NAME%%' , BuildType === 'production' ? 'tinyShield' : 'tinyShield (Development)' ) + '\n'
88+ } else if ( Line === '%%DOMAIN_INJECTION%%' ) {
89+ for ( const DomainEntry of DomainsList ) {
90+ ConvertedHeader += `// @match *://${ DomainEntry } /*\n`
91+ ConvertedHeader += `// @match *://*.${ DomainEntry } /*\n`
92+ }
10193 } else {
10294 ConvertedHeader += Line + '\n'
10395 }
10496}
105- console . log ( 'Generated header with userscript name and version ' )
97+ console . log ( 'Generated header with domain injections and processing ' )
10698let AttachHeaderPath = `/tmp/${ crypto . randomUUID ( ) } `
10799Fs . writeFileSync ( AttachHeaderPath , ConvertedHeader , { encoding : 'utf-8' , mode : 0o700 } )
108100console . log ( 'Written temporary header file to:' , AttachHeaderPath )
109101await ESBuild . build ( {
110- entryPoints : [ IndexFilePath ] ,
102+ entryPoints : [ './sources/src/index.ts' ] ,
111103 bundle : true ,
112104 minify : BuildType === 'production' ,
113105 define : {
@@ -122,6 +114,4 @@ await ESBuild.build({
122114} )
123115console . log ( 'Build completed' )
124116Fs . rmSync ( AttachHeaderPath )
125- console . log ( 'Temporary header file removed' )
126- Fs . rmSync ( IndexFilePath )
127- console . log ( 'Temporary source file removed' )
117+ console . log ( 'Temporary header file removed' )
0 commit comments