| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import fs, { readFileSync } from "fs"
- import path from "path"
- const outbounds = []
- fs.readdirSync("proxies").forEach(file => {
- if (
- fs.statSync(path.resolve("proxies", file)).isDirectory() ||
- file.startsWith(".") ||
- !file.toLowerCase().endsWith(".txt")
- )
- return
- fs.readFileSync(path.resolve("proxies", file))
- .toString()
- .split("\n")
- .filter(line => !!line)
- .forEach((line, i) => {
- const [host, port, username, password] = line.split(":")
- outbounds.push({
- tag: `${file.replace(".txt", "")}-${i + 1}`,
- protocol: "http",
- settings: {
- servers: [
- {
- address: host,
- port: parseInt(port),
- users: [
- {
- user: username,
- pass: password
- }
- ]
- }
- ]
- }
- })
- })
- })
- fs.writeFileSync(
- path.resolve("dist", "outbounds.json"),
- JSON.stringify(outbounds, null, 2)
- )
- const routingRules = outbounds.map((p, i) => {
- return {
- type: "field",
- user: [p.tag],
- outboundTag: p.tag
- }
- })
- fs.writeFileSync(
- path.resolve("dist", "routingRules.json"),
- JSON.stringify(routingRules, null, 2)
- )
- const xray = JSON.parse(
- fs.readFileSync(path.resolve("config", "xray.json")).toString()
- )
- xray.outbounds = xray.outbounds.concat(outbounds)
- xray.routing.rules = xray.routing.rules.concat(routingRules)
- fs.writeFileSync(
- path.resolve("dist", "xray_edited.json"),
- JSON.stringify(xray, null, 2)
- )
|