Surge_by_SukkaW/Build/validate-global-tld.ts
SukkaW 2d706f4775
Some checks failed
Build / Build (push) Has been cancelled
Build / Diff output (push) Has been cancelled
Build / Deploy to Cloudflare Pages (3.114.6) (push) Has been cancelled
Build / Deploy to GitHub and GitLab (push) Has been cancelled
Chore: new util run against source file
2025-04-27 23:51:18 +08:00

32 lines
1.1 KiB
TypeScript

import path from 'node:path';
import { HostnameSmolTrie } from './lib/trie';
import { OUTPUT_SURGE_DIR } from './constants/dir';
import { ICP_TLD } from './constants/domains';
import tldts from 'tldts-experimental';
import { looseTldtsOpt } from './constants/loose-tldts-opt';
import runAgainstSourceFile from './lib/run-against-source-file';
(async () => {
const trie = new HostnameSmolTrie();
const extraWhiteTLDs = new Set<string>();
await runAgainstSourceFile(path.join(OUTPUT_SURGE_DIR, 'non_ip', 'domestic.conf'), (domain) => {
if (domain === 'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe') {
return;
}
const tld = tldts.getPublicSuffix(domain, looseTldtsOpt);
if (tld) {
extraWhiteTLDs.add(tld);
}
}, 'ruleset');
await runAgainstSourceFile(path.join(OUTPUT_SURGE_DIR, 'non_ip', 'global.conf'), (domain, includeAllSubDomain) => {
trie.add(domain, includeAllSubDomain);
}, 'ruleset');
ICP_TLD.forEach(tld => trie.whitelist(tld, true));
extraWhiteTLDs.forEach(tld => trie.whitelist(tld, true));
console.log(trie.dump().join('\n'));
})();