build-deprecate-files.ts 1.5 KB

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