11import * as ESBuild from 'esbuild'
2- import * as Zod from 'zod'
3- import * as Process from 'node:process'
4- import * as TLDTS from 'tldts'
52import PackageJson from '@npmcli/package-json'
6- import { FetchAdShieldDomains } from './references/index.js'
7- import { CustomDefinedMatches } from './references/custom-defined.js'
8- import { ConvertWildcardSuffixToRegexPattern } from './utils/wildcard-suffix-converter.js'
93import { CreateBanner } from './banner/index.js'
10- import { SafeInitCwd } from './utils/safe-init-cwd .js'
4+ import { Build , type BuildOptions } from './build-core .js'
115
12- export type BuildOptions = {
13- Minify : boolean
14- BuildType : 'production' | 'development' ,
15- SubscriptionUrl : string ,
16- Version ?: string
17- }
18-
19- export async function Build ( OptionsParam ?: BuildOptions ) : Promise < void > {
20- const Options = await Zod . strictObject ( {
21- Minify : Zod . boolean ( ) ,
22- BuildType : Zod . enum ( [ 'production' , 'development' ] ) ,
23- SubscriptionUrl : Zod . string ( ) . transform ( Value => new URL ( Value ) ) . default ( new URL ( 'https://cdn.jsdelivr.net/npm/@filteringdev/tinyshield@latest/dist/tinyShield.user.js' ) ) ,
24- Version : Zod . string ( ) . optional ( )
25- } ) . parseAsync ( OptionsParam )
26-
27- const FetchedDomains = await FetchAdShieldDomains ( )
28- let MatchingDomains : Set < string > = new Set < string > ( FetchedDomains . get ( 'Normal' ) )
29- CustomDefinedMatches . forEach ( Domain => MatchingDomains . add ( Domain ) )
30-
31- MatchingDomains = new Set < string > ( [ ...MatchingDomains ] . map ( Domain => TLDTS . parse ( Domain ) . domain ?? Domain ) . filter ( ( D ) : D is string => D !== null ) )
32- for ( const Domain of MatchingDomains ) {
33- if ( Domain . endsWith ( '.*' ) ) {
34- MatchingDomains . delete ( Domain )
35- ConvertWildcardSuffixToRegexPattern ( Domain ) . forEach ( GeneratedPattern => MatchingDomains . add ( GeneratedPattern ) )
6+ export class StandardBuild extends Build {
7+ constructor ( FromOrOption : Build | BuildOptions , Option ?: BuildOptions ) {
8+ if ( FromOrOption instanceof Build ) {
9+ super ( Option ! )
10+ this . CopyStateFrom ( FromOrOption )
11+ return
3612 }
13+
14+ super ( FromOrOption )
3715 }
3816
39- let ProjectRoot = SafeInitCwd ( { Cwd : Process . cwd ( ) , InitCwd : Process . env . INIT_CWD } )
40-
41- const Banner = CreateBanner ( {
42- Version : Options . Version ?? ( await PackageJson . load ( ProjectRoot ) ) . content . version ?? '0.0.0' ,
43- BuildType : Options . BuildType ?? 'production' ,
44- Domains : MatchingDomains ,
45- Name : 'tinyShield' ,
46- Namespace : 'https://github.com/FilteringDev/tinyShield' ,
47- DownloadURL : Options . SubscriptionUrl ,
48- UpdateURL : Options . SubscriptionUrl ,
49- HomepageURL : new URL ( 'https://github.com/FilteringDev/tinyShield' ) ,
50- SupportURL : new URL ( 'https://github.com/FilteringDev/tinyShield/issues' ) ,
51- License : 'MPL-2.0' ,
52- Author : 'PiQuark6046 and contributors' ,
53- Description : {
54- en : 'tinyShield allows AdGuard, uBlock Origin, Brave and ABP to resist against Ad-Shield quickly.' ,
55- ko : 'tinyShield는 AdGuard, uBlock Origin, Brave 와 ABP가 애드쉴드에 빠르게 저항할 수 있도록 합니다.' ,
56- ja : 'tinyShieldを使うと、AdGuard, uBlock Origin, Brave, およびABPがAd-Shieldに素早く対抗できます。'
57- }
58- } )
17+ async Build ( ) {
18+ let MatchingDomains : Set < string > = new Set < string > ( this . FetchedDomains . get ( 'Full' ) )
19+ const Banner = CreateBanner ( {
20+ Version : this . Options ? .Version ?? ( await PackageJson . load ( this . ProjectRoot ) ) . content . version ?? '0.0.0' ,
21+ BuildType : this . Options ! . BuildType ?? 'production' ,
22+ Domains : MatchingDomains ,
23+ Name : 'tinyShield' ,
24+ Namespace : 'https://github.com/FilteringDev/tinyShield' ,
25+ DownloadURL : this . Options ! . SubscriptionUrl ,
26+ UpdateURL : this . Options ! . SubscriptionUrl ,
27+ HomepageURL : new URL ( 'https://github.com/FilteringDev/tinyShield' ) ,
28+ SupportURL : new URL ( 'https://github.com/FilteringDev/tinyShield/issues' ) ,
29+ License : 'MPL-2.0' ,
30+ Author : 'PiQuark6046 and contributors' ,
31+ Description : {
32+ en : 'tinyShield allows AdGuard, uBlock Origin, Brave and ABP to resist against Ad-Shield quickly.' ,
33+ ko : 'tinyShield는 AdGuard, uBlock Origin, Brave 와 ABP가 애드쉴드에 빠르게 저항할 수 있도록 합니다.' ,
34+ ja : 'tinyShieldを使うと、AdGuard, uBlock Origin, Brave, およびABPがAd-Shieldに素早く対抗できます。'
35+ }
36+ } )
5937
60- await ESBuild . build ( {
61- entryPoints : [ ProjectRoot + '/userscript/source/index.ts' ] ,
62- bundle : true ,
63- minify : Options . Minify ,
64- outfile : `${ ProjectRoot } /dist/tinyShield${ Options . BuildType === 'development' ? '.dev' : '' } .user.js` ,
65- banner : {
66- js : Banner
67- } ,
68- target : [ 'es2024' , 'chrome119' , 'firefox142' , 'safari26' ]
69- } )
38+ await ESBuild . build ( {
39+ entryPoints : [ this . ProjectRoot + '/userscript/source/index.ts' ] ,
40+ bundle : true ,
41+ minify : this . Options ! . Minify ,
42+ outfile : `${ this . ProjectRoot } /dist/tinyShield${ this . Options ! . BuildType === 'development' ? '.dev' : '' } .user.js` ,
43+ banner : {
44+ js : Banner
45+ } ,
46+ target : [ 'es2024' , 'chrome119' , 'firefox142' , 'safari26' ]
47+ } )
48+ }
7049}
0 commit comments