mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
33 lines
1.1 KiB
TypeScript
33 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';
|
|
import { MARKER_DOMAIN } from './constants/description';
|
|
|
|
(async () => {
|
|
const trie = new HostnameSmolTrie();
|
|
const extraWhiteTLDs = new Set<string>();
|
|
|
|
await runAgainstSourceFile(path.join(OUTPUT_SURGE_DIR, 'non_ip', 'domestic.conf'), (domain) => {
|
|
if (domain === MARKER_DOMAIN) {
|
|
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'));
|
|
})();
|