build-chn-cidr.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { fetchRemoteTextAndReadByLine } from './lib/fetch-text-by-line';
  2. import { resolve as pathResolve } from 'path';
  3. import { compareAndWriteFile, withBannerArray } from './lib/create-file';
  4. import { processLineFromReadline } from './lib/process-line';
  5. import { task } from './lib/trace-runner';
  6. import { exclude } from 'fast-cidr-tools';
  7. // https://github.com/misakaio/chnroutes2/issues/25
  8. const EXCLUDE_CIDRS = [
  9. '223.118.0.0/15',
  10. '223.120.0.0/15'
  11. ];
  12. const INCLUDE_CIDRS = [
  13. '211.99.96.0/19' // wy.com.cn
  14. ];
  15. export const buildChnCidr = task(import.meta.path, async () => {
  16. const cidr = await processLineFromReadline(await fetchRemoteTextAndReadByLine('https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt'));
  17. const filteredCidr = exclude([...cidr, ...INCLUDE_CIDRS], EXCLUDE_CIDRS, true);
  18. // Can not use SHARED_DESCRIPTION here as different license
  19. const description = [
  20. 'License: CC BY-SA 2.0',
  21. 'Homepage: https://ruleset.skk.moe',
  22. 'GitHub: https://github.com/SukkaW/Surge',
  23. '',
  24. 'Data from https://misaka.io (misakaio @ GitHub)'
  25. ];
  26. return Promise.all([
  27. compareAndWriteFile(
  28. withBannerArray(
  29. 'Sukka\'s Ruleset - Mainland China IPv4 CIDR',
  30. description,
  31. new Date(),
  32. filteredCidr.map(i => `IP-CIDR,${i}`)
  33. ),
  34. pathResolve(import.meta.dir, '../List/ip/china_ip.conf')
  35. ),
  36. compareAndWriteFile(
  37. withBannerArray(
  38. 'Sukka\'s Ruleset - Mainland China IPv4 CIDR',
  39. description,
  40. new Date(),
  41. filteredCidr
  42. ),
  43. pathResolve(import.meta.dir, '../Clash/ip/china_ip.txt')
  44. )
  45. ]);
  46. });
  47. if (import.meta.main) {
  48. buildChnCidr();
  49. }