build-apple-cdn.js 2.1 KB

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