build-deprecate-files.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. ['domainset/reject_phishing', 'This file has been merged with domainset/reject']
  10. ];
  11. const REMOVED_FILES = [
  12. 'Internal/cdn.txt',
  13. 'List/domainset/steam.conf',
  14. 'List/internal/appprofile.php',
  15. 'Clash/domainset/steam.txt',
  16. 'Clash/non_ip/clash_fake_ip_filter.txt',
  17. 'sing-box/domainset/steam.json',
  18. 'Modules/sukka_unlock_abema.sgmodule',
  19. 'Modules/sukka_exclude_reservered_ip.sgmodule'
  20. ];
  21. export const buildDeprecateFiles = task(require.main === module, __filename)((span) => span.traceChildAsync('create deprecated files', async (childSpan) => {
  22. const promises: Array<Promise<unknown>> = REMOVED_FILES
  23. .map(f => fsp.rm(
  24. path.join(PUBLIC_DIR, f),
  25. { force: true, recursive: true }
  26. ));
  27. for (const [filePath, description] of DEPRECATED_FILES) {
  28. const surgeFile = path.resolve(OUTPUT_SURGE_DIR, `${filePath}.conf`);
  29. const clashFile = path.resolve(OUTPUT_CLASH_DIR, `${filePath}.txt`);
  30. const content = [
  31. '#########################################',
  32. '# Sukka\'s Ruleset - Deprecated',
  33. `# ${description}`,
  34. '################## EOF ##################'
  35. ];
  36. promises.push(
  37. compareAndWriteFile(childSpan, content, surgeFile),
  38. compareAndWriteFile(childSpan, content, clashFile)
  39. );
  40. }
  41. return Promise.all(promises);
  42. }));