index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import fs, { readFileSync } from "fs"
  2. import path from "path"
  3. const outbounds = []
  4. fs.readdirSync("proxies").forEach(file => {
  5. if (
  6. fs.statSync(path.resolve("proxies", file)).isDirectory() ||
  7. file.startsWith(".") ||
  8. !file.toLowerCase().endsWith(".txt")
  9. )
  10. return
  11. fs.readFileSync(path.resolve("proxies", file))
  12. .toString()
  13. .split("\n")
  14. .filter(line => !!line)
  15. .forEach((line, i) => {
  16. const [host, port, username, password] = line.split(":")
  17. outbounds.push({
  18. tag: `${file.replace(".txt", "")}-${i + 1}`,
  19. protocol: "http",
  20. settings: {
  21. servers: [
  22. {
  23. address: host,
  24. port: parseInt(port),
  25. users: [
  26. {
  27. user: username,
  28. pass: password
  29. }
  30. ]
  31. }
  32. ]
  33. }
  34. })
  35. })
  36. })
  37. fs.writeFileSync(
  38. path.resolve("dist", "outbounds.json"),
  39. JSON.stringify(outbounds, null, 2)
  40. )
  41. const routingRules = outbounds.map((p, i) => {
  42. return {
  43. type: "field",
  44. user: [p.tag],
  45. outboundTag: p.tag
  46. }
  47. })
  48. fs.writeFileSync(
  49. path.resolve("dist", "routingRules.json"),
  50. JSON.stringify(routingRules, null, 2)
  51. )
  52. const xray = JSON.parse(
  53. fs.readFileSync(path.resolve("config", "xray.json")).toString()
  54. )
  55. xray.outbounds = xray.outbounds.concat(outbounds)
  56. xray.routing.rules = xray.routing.rules.concat(routingRules)
  57. fs.writeFileSync(
  58. path.resolve("dist", "xray_edited.json"),
  59. JSON.stringify(xray, null, 2)
  60. )