build-deprecate-files.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. import { globSync } from 'tinyglobby';
  7. import { appendArrayInPlace } from 'foxts/append-array-in-place';
  8. const DEPRECATED_FILES = [
  9. ['non_ip/global_plus', 'This file has been merged with non_ip/global'],
  10. ['domainset/reject_sukka', 'This file has been merged with domainset/reject']
  11. ];
  12. const REMOVED_FILES = [
  13. 'Internal/chnroutes.txt',
  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. 'Modules/Rules/*.sgmodule',
  21. 'Internal/mihomo_nameserver_policy/*.conf'
  22. ];
  23. const REMOVED_FOLDERS = [
  24. 'List/Internal',
  25. 'Clash/Internal'
  26. ];
  27. export const buildDeprecateFiles = task(require.main === module, __filename)((span) => span.traceChildAsync('create deprecated files', async (childSpan) => {
  28. const promises: Array<Promise<unknown>> = globSync(REMOVED_FILES, { cwd: PUBLIC_DIR, absolute: true })
  29. .map(f => fsp.rm(f, { force: true, recursive: true }));
  30. appendArrayInPlace(promises, REMOVED_FOLDERS.map(folder => fsp.rm(path.join(PUBLIC_DIR, folder), { force: true, recursive: true })));
  31. for (const [filePath, description] of DEPRECATED_FILES) {
  32. const content = [
  33. '#########################################',
  34. '# Sukka\'s Ruleset - Deprecated',
  35. `# ${description}`,
  36. '################## EOF ##################'
  37. ];
  38. promises.push(
  39. compareAndWriteFile(childSpan, content, path.resolve(OUTPUT_SURGE_DIR, `${filePath}.conf`)),
  40. compareAndWriteFile(childSpan, content, path.resolve(OUTPUT_CLASH_DIR, `${filePath}.txt`))
  41. );
  42. }
  43. return Promise.all(promises);
  44. }));