build-deprecate-files.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. ];
  18. export const buildDeprecateFiles = task(require.main === module, __filename)((span) => span.traceChildAsync('create deprecated files', async (childSpan) => {
  19. const promises: Array<Promise<unknown>> = REMOVED_FILES
  20. .map(f => fsp.rm(
  21. path.join(PUBLIC_DIR, f),
  22. { force: true, recursive: true }
  23. ));
  24. for (const [filePath, description] of DEPRECATED_FILES) {
  25. const surgeFile = path.resolve(OUTPUT_SURGE_DIR, `${filePath}.conf`);
  26. const clashFile = path.resolve(OUTPUT_CLASH_DIR, `${filePath}.txt`);
  27. const content = [
  28. '#########################################',
  29. '# Sukka\'s Ruleset - Deprecated',
  30. `# ${description}`,
  31. '################## EOF ##################'
  32. ];
  33. promises.push(
  34. compareAndWriteFile(childSpan, content, surgeFile),
  35. compareAndWriteFile(childSpan, content, clashFile)
  36. );
  37. }
  38. return Promise.all(promises);
  39. }));