Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 857cb55159 | |||
| 0c66722989 |
@@ -3,9 +3,19 @@
|
||||
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const { spawnSync } = require("node:child_process");
|
||||
const { pathToFileURL } = require("node:url");
|
||||
|
||||
const bundle = path.join(__dirname, "..", "dist", "app.mjs");
|
||||
const packageRoot = path.join(__dirname, "..");
|
||||
const bundle = path.join(packageRoot, "dist", "app.mjs");
|
||||
|
||||
// `server-config update` self-updates the checkout: pull, reinstall deps, rebuild.
|
||||
// It runs outside the TUI because it must not depend on (or fight with) the bundle
|
||||
// it is about to replace.
|
||||
if (process.argv[2] === "update") {
|
||||
runUpdate();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fs.existsSync(bundle)) {
|
||||
process.stderr.write(
|
||||
@@ -18,3 +28,34 @@ import(pathToFileURL(bundle).href).catch((error) => {
|
||||
process.stderr.write(`server-config: ${error?.stack || error}\n`);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
function runUpdate() {
|
||||
if (!fs.existsSync(path.join(packageRoot, ".git"))) {
|
||||
process.stderr.write(
|
||||
"server-config: cannot update — package root is not a git checkout.\n",
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
|
||||
const steps = [
|
||||
["git", ["pull", "--ff-only"]],
|
||||
[npm, ["install"]],
|
||||
[npm, ["run", "build"]],
|
||||
];
|
||||
|
||||
for (const [cmd, args] of steps) {
|
||||
process.stdout.write(`\n$ ${cmd} ${args.join(" ")}\n`);
|
||||
const result = spawnSync(cmd, args, { cwd: packageRoot, stdio: "inherit" });
|
||||
if (result.error) {
|
||||
process.stderr.write(`server-config: failed to run ${cmd}: ${result.error.message}\n`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (result.status !== 0) {
|
||||
process.stderr.write(`server-config: \`${cmd} ${args.join(" ")}\` exited with code ${result.status}\n`);
|
||||
process.exit(result.status || 1);
|
||||
}
|
||||
}
|
||||
|
||||
process.stdout.write("\nserver-config: update complete.\n");
|
||||
}
|
||||
|
||||
@@ -1,10 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
const os = require("node:os");
|
||||
const path = require("node:path");
|
||||
const { randomBytes } = require("node:crypto");
|
||||
|
||||
const DEFAULT_FRP_VERSION = "0.58.1";
|
||||
const DEFAULT_FRP_ARCH = "amd64";
|
||||
|
||||
// Map Node's os.arch() to the arch token frp uses in its release asset names
|
||||
// (e.g. frp_0.58.1_linux_arm64.tar.gz). Falls back to amd64 for the common case.
|
||||
function detectFrpArch() {
|
||||
switch (os.arch()) {
|
||||
case "x64": return "amd64";
|
||||
case "arm64": return "arm64";
|
||||
case "arm": return "arm";
|
||||
case "ia32": return "386";
|
||||
case "mips": return "mips";
|
||||
case "mipsel": return "mipsle";
|
||||
default: return "amd64";
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_FRP_ARCH = detectFrpArch();
|
||||
const DEFAULT_FRP_SERVER_ADDR = "81.70.134.9";
|
||||
const DEFAULT_FRP_SERVER_PORT = 15443;
|
||||
const DEFAULT_SERVICE_NAME = "frpc";
|
||||
@@ -212,6 +228,7 @@ function buildGlobals({ serverAddr, serverPort, token, tlsEnable, tcpMux, logFil
|
||||
module.exports = {
|
||||
DEFAULT_FRP_VERSION,
|
||||
DEFAULT_FRP_ARCH,
|
||||
detectFrpArch,
|
||||
DEFAULT_FRP_SERVER_ADDR,
|
||||
DEFAULT_FRP_SERVER_PORT,
|
||||
DEFAULT_SERVICE_NAME,
|
||||
|
||||
@@ -79,8 +79,11 @@ function gitPluginStep(name, repo, destination) {
|
||||
|
||||
function condaInstallPlan(options = {}) {
|
||||
const installDir = options.installDir || path.join(os.homedir(), "miniconda3");
|
||||
const installer = "/tmp/Miniconda3-latest-Linux-x86_64.sh";
|
||||
const url = "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh";
|
||||
// Miniconda asset naming uses uname-style arch tokens (x86_64 / aarch64).
|
||||
const condaArch = os.arch() === "arm64" ? "aarch64" : "x86_64";
|
||||
const installerName = `Miniconda3-latest-Linux-${condaArch}.sh`;
|
||||
const installer = `/tmp/${installerName}`;
|
||||
const url = `https://repo.anaconda.com/miniconda/${installerName}`;
|
||||
const condaBin = path.join(installDir, "bin", "conda");
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user