build-deprecate-files.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { OUTPUT_CLASH_DIR, OUTPUT_SURGE_DIR, PUBLIC_DIR } from './constants/dir';
  2. import { compareAndWriteFile } from './lib/create-file';
  3. import { task } from './trace';
  4. import path from 'node:path';
  5. import fsp from 'node:fs/promises';
  6. const DEPRECATED_FILES = [
  7. ['non_ip/global_plus', 'This file has been merged with non_ip/global'],
  8. ['domainset/reject_sukka', 'This file has been merged with domainset/reject'],
  9. ['Internal/reversed-chn-cidr.txt', 'This file has been replaced by https://chnroutes2.cdn.skk.moe/reversed-chnroutes.txt']
  10. ];
  11. const REMOVED_FILES = [
  12. 'Internal/chnroutes.txt',
  13. 'List/internal/appprofile.php',
  14. 'Clash/domainset/steam.txt',
  15. 'Clash/non_ip/clash_fake_ip_filter.txt',
  16. 'sing-box/domainset/steam.json',
  17. 'Modules/sukka_unlock_abema.sgmodule',
  18. 'Modules/sukka_exclude_reservered_ip.sgmodule'
  19. ];
  20. export const buildDeprecateFiles = task(require.main === module, __filename)((span) => span.traceChildAsync('create deprecated files', async (childSpan) => {
  21. const promises: Array<Promise<unknown>> = REMOVED_FILES
  22. .map(f => fsp.rm(
  23. path.join(PUBLIC_DIR, f),
  24. { force: true, recursive: true }
  25. ));
  26. for (const [filePath, description] of DEPRECATED_FILES) {
  27. const content = [
  28. '#########################################',
  29. '# Sukka\'s Ruleset - Deprecated',
  30. `# ${description}`,
  31. '################## EOF ##################'
  32. ];
  33. promises.push(
  34. compareAndWriteFile(childSpan, content, path.resolve(OUTPUT_SURGE_DIR, `${filePath}.conf`)),
  35. compareAndWriteFile(childSpan, content, path.resolve(OUTPUT_CLASH_DIR, `${filePath}.txt`))
  36. );
  37. }
  38. return Promise.all(promises);
  39. }));