build-deprecate-files.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. '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 surgeFile = path.resolve(OUTPUT_SURGE_DIR, `${filePath}.conf`);
  28. const clashFile = path.resolve(OUTPUT_CLASH_DIR, `${filePath}.txt`);
  29. const content = [
  30. '#########################################',
  31. '# Sukka\'s Ruleset - Deprecated',
  32. `# ${description}`,
  33. '################## EOF ##################'
  34. ];
  35. promises.push(
  36. compareAndWriteFile(childSpan, content, surgeFile),
  37. compareAndWriteFile(childSpan, content, clashFile)
  38. );
  39. }
  40. return Promise.all(promises);
  41. }));