Skip to content

Commit bd22752

Browse files
authored
ci: revert to @match metadata block (#36)
1 parent a5a47b0 commit bd22752

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

builder.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as ESBuild from 'esbuild'
66
import * as Zod from 'zod'
77
import PackageJson from '@npmcli/package-json'
88
import * as Semver from 'semver'
9-
import * as TsMorph from 'ts-morph'
109
import * as Fs from 'node:fs'
1110
import * as NodeHttps from 'node:https'
1211
import * as Process from 'node:process'
@@ -79,35 +78,28 @@ for (const SellerEntry of IABSellersJsonData.sellers) {
7978
}
8079
console.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-
9481
const HeaderLocation = './sources/banner.txt'
9582
let ConvertedHeader: string = ''
9683
for (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')
10698
let AttachHeaderPath = `/tmp/${crypto.randomUUID()}`
10799
Fs.writeFileSync(AttachHeaderPath, ConvertedHeader, { encoding: 'utf-8', mode: 0o700 })
108100
console.log('Written temporary header file to:', AttachHeaderPath)
109101
await 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
})
123115
console.log('Build completed')
124116
Fs.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')

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"esbuild": "^0.27.0",
3939
"eslint": "^9.38.0",
4040
"semver": "^7.7.3",
41-
"ts-morph": "^27.0.2",
4241
"tsx": "^4.21.0",
4342
"typescript": "^5.9.3",
4443
"typescript-eslint": "^8.46.2",

sources/banner.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
// @version %%VERSION_VALUE%%
1212
// @author PiQuark6046 and contributors
1313
//
14-
// @match https://*/*
15-
// @match http://*/*
14+
%%DOMAIN_INJECTION%%
1615
//
1716
// @description tinyShield allows AdGuard, uBlock Origin, Brave and ABP to resist against Ad-Shield quickly.
1817
// @description:ko tinyShield는 AdGuard, uBlock Origin, Brave 와 ABP가 애드쉴드에 빠르게 저항할 수 있도록 합니다.

0 commit comments

Comments
 (0)