mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Build domestic conf
This commit is contained in:
58
Build/build-domestic-ruleset.js
Normal file
58
Build/build-domestic-ruleset.js
Normal file
@@ -0,0 +1,58 @@
|
||||
// @ts-check
|
||||
const path = require('path');
|
||||
const { DOMESTICS } = require('../Source/non_ip/domestic');
|
||||
const { readFileByLine } = require('./lib/fetch-remote-text-by-line');
|
||||
const { processLine } = require('./lib/process-line');
|
||||
const { withBannerArray } = require('./lib/with-banner');
|
||||
const { compareAndWriteFile } = require('./lib/string-array-compare');
|
||||
|
||||
(async () => {
|
||||
const rl = readFileByLine(path.resolve(__dirname, '../Source/non_ip/domestic.conf'));
|
||||
const results = [];
|
||||
for await (const l of rl) {
|
||||
const line = processLine(l);
|
||||
if (line) {
|
||||
results.push(line);
|
||||
}
|
||||
}
|
||||
|
||||
results.push(
|
||||
...Object.entries(DOMESTICS)
|
||||
.filter(([key]) => key !== 'SYSTEM')
|
||||
.flatMap(([, { domains }]) => domains)
|
||||
.sort()
|
||||
.map((domain) => `DOMAIN-SUFFIX,${domain}`)
|
||||
);
|
||||
|
||||
await Promise.all([
|
||||
compareAndWriteFile(
|
||||
withBannerArray(
|
||||
'Sukka\'s Surge Rules - Domestic Domain',
|
||||
[
|
||||
'License: AGPL 3.0',
|
||||
'Homepage: https://ruleset.skk.moe',
|
||||
'GitHub: https://github.com/SukkaW/Surge',
|
||||
'',
|
||||
'This file contains known addresses that are avaliable in the Mainland China.'
|
||||
],
|
||||
new Date(),
|
||||
results
|
||||
),
|
||||
path.resolve(__dirname, '../List/non_ip/domestic.conf')
|
||||
),
|
||||
compareAndWriteFile(
|
||||
[
|
||||
'#!name=[Sukka] Local DNS Mapping',
|
||||
`#!desc=Last Updated: ${new Date().toISOString()}`,
|
||||
'',
|
||||
'[Host]',
|
||||
...Object.entries(DOMESTICS)
|
||||
.flatMap(
|
||||
([, { domains, dns }]) => domains.map((domain) => `${domain} = server:${dns}`)
|
||||
),
|
||||
''
|
||||
],
|
||||
path.resolve(__dirname, '../Modules/sukka_local_dns_mapping.sgmodule')
|
||||
)
|
||||
]);
|
||||
})();
|
||||
Reference in New Issue
Block a user