build-deprecate-files.ts 2.0 KB

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