Подготовить HY2XS к production-сборке
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
import { install } from "./commands/install";
|
||||
import type { InstallOptions } from "./types/context";
|
||||
|
||||
function usage(): never {
|
||||
console.error("Usage: hy2xs-orchestrator install --package-dir <path> [--domain <name>] [--port <udp>] [--ssh-port <tcp>] [--skip-firewall] [--skip-start] [--ui-port <tcp>] [--ui-bind-host <host>] [--non-interactive]");
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
function takeValue(args: string[], index: number, flag: string): string {
|
||||
const value = args[index + 1];
|
||||
if (!value || value.startsWith("--")) {
|
||||
console.error(`Missing value for ${flag}`);
|
||||
usage();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function parseInstallOptions(args: string[]): InstallOptions {
|
||||
const options: InstallOptions = {
|
||||
packageDir: "",
|
||||
nonInteractive: false,
|
||||
domain: "",
|
||||
port: 443,
|
||||
sshPort: 22,
|
||||
skipFirewall: false,
|
||||
skipStart: false,
|
||||
uiPort: 8080,
|
||||
uiBindHost: "127.0.0.1"
|
||||
};
|
||||
|
||||
for (let i = 0; i < args.length; i += 1) {
|
||||
const arg = args[i];
|
||||
switch (arg) {
|
||||
case "--package-dir":
|
||||
options.packageDir = takeValue(args, i, arg);
|
||||
i += 1;
|
||||
break;
|
||||
case "--non-interactive":
|
||||
options.nonInteractive = true;
|
||||
break;
|
||||
case "--domain":
|
||||
options.domain = takeValue(args, i, arg);
|
||||
i += 1;
|
||||
break;
|
||||
case "--port":
|
||||
options.port = Number(takeValue(args, i, arg));
|
||||
i += 1;
|
||||
break;
|
||||
case "--ssh-port":
|
||||
options.sshPort = Number(takeValue(args, i, arg));
|
||||
i += 1;
|
||||
break;
|
||||
case "--skip-firewall":
|
||||
options.skipFirewall = true;
|
||||
break;
|
||||
case "--skip-start":
|
||||
options.skipStart = true;
|
||||
break;
|
||||
case "--ui-port":
|
||||
options.uiPort = Number(takeValue(args, i, arg));
|
||||
i += 1;
|
||||
break;
|
||||
case "--ui-bind-host":
|
||||
options.uiBindHost = takeValue(args, i, arg);
|
||||
i += 1;
|
||||
break;
|
||||
default:
|
||||
console.error(`Unknown argument: ${arg}`);
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (!options.packageDir) {
|
||||
console.error("Missing --package-dir");
|
||||
usage();
|
||||
}
|
||||
|
||||
for (const [name, value] of Object.entries({ port: options.port, sshPort: options.sshPort, uiPort: options.uiPort })) {
|
||||
if (!Number.isInteger(value) || value < 1 || value > 65535) {
|
||||
console.error(`Invalid ${name}: ${value}`);
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const [command, ...args] = Bun.argv.slice(2);
|
||||
if (command !== "install") {
|
||||
usage();
|
||||
}
|
||||
|
||||
await install(parseInstallOptions(args));
|
||||
}
|
||||
|
||||
main().catch((error: unknown) => {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
console.error(`[hy2xs] ERROR: ${message}`);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user