Files
3x-ui/docs/lib/xray/install.ts
T
MHSanaei 9b91f0f42e docs: vendor the documentation site into the monorepo
Fold the standalone 3x-ui-docs project (Next.js 16 + Fumadocs, deployed to
docs.sanaei.dev) into docs/ so the panel and its documentation share a single
source of truth, the way sing-box keeps its docs in-tree. The old repo becomes
redundant and can be retired.

- Import the full site under docs/ (app, components, content, lib, public,
  scripts, config). The self-contained pnpm project sits alongside the existing
  engineering notes with no filename collisions.
- Re-point "Edit on GitHub" links from MHSanaei/3x-ui-docs to this repo's
  docs/content/docs path (docs/lib/shared.ts, docs/app/.../page.tsx).
- Add docs-ci.yml and docs-deploy.yml under .github/workflows/, scoped to
  docs/** and run with working-directory: docs, since GitHub only runs
  workflows from the repo-root .github/. deploy-static.yml's GitHub Pages
  publish (CNAME docs.sanaei.dev) carries over unchanged.

Follow-up (outside this commit): attach the docs.sanaei.dev custom domain to
this repository's Pages (or set the Vercel project's root directory to docs),
confirm the site is live from the monorepo, then delete MHSanaei/3x-ui-docs.
2026-07-07 23:07:14 +02:00

75 lines
2.6 KiB
TypeScript

// Pure builders for 3x-ui install commands (script + Docker). No React/DOM.
export type InstallMethod = 'script' | 'docker';
export interface InstallOptions {
method: InstallMethod;
/** A release tag like `v3.4.1`, or empty/`latest` for the latest release. */
version: string;
enableFail2ban: boolean;
panelPort: string;
webBasePath: string;
}
const REPO_RAW = 'https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh';
const IMAGE = 'ghcr.io/mhsanaei/3x-ui:latest';
function isLatest(version: string): boolean {
const v = version.trim().toLowerCase();
return v === '' || v === 'latest';
}
/**
* The one-line script install command. The master install script reads the
* version as its first argument: empty = latest stable release, a tag like
* `v3.4.0` = that release, and `dev-latest` = the rolling per-commit dev build.
*/
export function buildScriptCommand(options: InstallOptions): string {
if (isLatest(options.version)) {
return `bash <(curl -Ls ${REPO_RAW})`;
}
return `bash <(curl -Ls ${REPO_RAW}) ${options.version.trim()}`;
}
/** A `docker run` command reflecting the chosen options. */
export function buildDockerRun(options: InstallOptions): string {
const lines = ['docker run -itd'];
lines.push(` -e XRAY_VMESS_AEAD_FORCED=false`);
lines.push(` -e XUI_ENABLE_FAIL2BAN=${options.enableFail2ban ? 'true' : 'false'}`);
if (options.panelPort.trim()) lines.push(` -e XUI_PORT=${options.panelPort.trim()}`);
if (options.webBasePath.trim())
lines.push(` -e XUI_INIT_WEB_BASE_PATH=${options.webBasePath.trim()}`);
lines.push(` -v $PWD/db/:/etc/x-ui/`);
lines.push(` -v $PWD/cert/:/root/cert/`);
lines.push(` --network=host`);
lines.push(` --restart=unless-stopped`);
lines.push(` --name 3x-ui`);
lines.push(` ${IMAGE}`);
return lines.join(' \\\n');
}
/** A `docker-compose.yml` reflecting the chosen options. */
export function buildDockerCompose(options: InstallOptions): string {
const env: string[] = [
` XRAY_VMESS_AEAD_FORCED: 'false'`,
` XUI_ENABLE_FAIL2BAN: '${options.enableFail2ban ? 'true' : 'false'}'`,
];
if (options.panelPort.trim()) env.push(` XUI_PORT: '${options.panelPort.trim()}'`);
if (options.webBasePath.trim())
env.push(` XUI_INIT_WEB_BASE_PATH: '${options.webBasePath.trim()}'`);
return [
`services:`,
` 3x-ui:`,
` image: ${IMAGE}`,
` container_name: 3x-ui`,
` volumes:`,
` - ./db/:/etc/x-ui/`,
` - ./cert/:/root/cert/`,
` environment:`,
...env,
` network_mode: host`,
` restart: unless-stopped`,
].join('\n');
}