build-apple-cdn.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. const path = require('path');
  2. const { compareAndWriteFile } = require('./lib/string-array-compare');
  3. const { withBannerArray } = require('./lib/with-banner');
  4. const { parseFelixDnsmasq } = require('./lib/parse-dnsmasq');
  5. const { surgeRulesetToClashClassicalTextRuleset, surgeDomainsetToClashDomainset } = require('./lib/clash');
  6. (async () => {
  7. console.time('Total Time - build-apple-cdn-conf');
  8. const res = await parseFelixDnsmasq('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf');
  9. const description = [
  10. 'License: AGPL 3.0',
  11. 'Homepage: https://ruleset.skk.moe',
  12. 'GitHub: https://github.com/SukkaW/Surge',
  13. '',
  14. 'This file contains Apple\'s domains using their China mainland CDN servers.',
  15. '',
  16. 'Data from:',
  17. ' - https://github.com/felixonmars/dnsmasq-china-list'
  18. ];
  19. const ruleset = res.map(domain => `DOMAIN-SUFFIX,${domain}`);
  20. const domainset = res.map(i => `.${i}`);
  21. await Promise.all([
  22. compareAndWriteFile(
  23. withBannerArray(
  24. 'Sukka\'s Ruleset - Apple CDN',
  25. description,
  26. new Date(),
  27. ruleset
  28. ),
  29. path.resolve(__dirname, '../List/non_ip/apple_cdn.conf')
  30. ),
  31. compareAndWriteFile(
  32. withBannerArray(
  33. 'Sukka\'s Ruleset - Apple CDN',
  34. description,
  35. new Date(),
  36. surgeRulesetToClashClassicalTextRuleset(ruleset)
  37. ),
  38. path.resolve(__dirname, '../Clash/non_ip/apple_cdn.txt')
  39. ),
  40. compareAndWriteFile(
  41. withBannerArray(
  42. 'Sukka\'s Ruleset - Apple CDN',
  43. description,
  44. new Date(),
  45. domainset
  46. ),
  47. path.resolve(__dirname, '../List/domainset/apple_cdn.conf')
  48. ),
  49. compareAndWriteFile(
  50. withBannerArray(
  51. 'Sukka\'s Ruleset - Apple CDN',
  52. description,
  53. new Date(),
  54. surgeDomainsetToClashDomainset(domainset)
  55. ),
  56. path.resolve(__dirname, '../Clash/domainset/apple_cdn.txt')
  57. )
  58. ]);
  59. console.timeEnd('Total Time - build-apple-cdn-conf');
  60. })();