feat(cli): colorize gateway health + daemon output
This commit is contained in:
@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { colorize, isRich, theme } from "../terminal/theme.js";
|
||||
import {
|
||||
GATEWAY_WINDOWS_TASK_NAME,
|
||||
LEGACY_GATEWAY_WINDOWS_TASK_NAMES,
|
||||
@@ -12,6 +13,11 @@ import type { GatewayServiceRuntime } from "./service-runtime.js";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
const formatLine = (label: string, value: string) => {
|
||||
const rich = isRich();
|
||||
return `${colorize(rich, theme.muted, `${label}:`)} ${colorize(rich, theme.command, value)}`;
|
||||
};
|
||||
|
||||
function resolveHomeDir(env: Record<string, string | undefined>): string {
|
||||
const home = env.USERPROFILE?.trim() || env.HOME?.trim();
|
||||
if (!home) throw new Error("Missing HOME");
|
||||
@@ -229,8 +235,10 @@ export async function installScheduledTask({
|
||||
}
|
||||
|
||||
await execSchtasks(["/Run", "/TN", GATEWAY_WINDOWS_TASK_NAME]);
|
||||
stdout.write(`Installed Scheduled Task: ${GATEWAY_WINDOWS_TASK_NAME}\n`);
|
||||
stdout.write(`Task script: ${scriptPath}\n`);
|
||||
stdout.write(
|
||||
`${formatLine("Installed Scheduled Task", GATEWAY_WINDOWS_TASK_NAME)}\n`,
|
||||
);
|
||||
stdout.write(`${formatLine("Task script", scriptPath)}\n`);
|
||||
return { scriptPath };
|
||||
}
|
||||
|
||||
@@ -247,7 +255,7 @@ export async function uninstallScheduledTask({
|
||||
const scriptPath = resolveTaskScriptPath(env);
|
||||
try {
|
||||
await fs.unlink(scriptPath);
|
||||
stdout.write(`Removed task script: ${scriptPath}\n`);
|
||||
stdout.write(`${formatLine("Removed task script", scriptPath)}\n`);
|
||||
} catch {
|
||||
stdout.write(`Task script not found at ${scriptPath}\n`);
|
||||
}
|
||||
@@ -272,7 +280,9 @@ export async function stopScheduledTask({
|
||||
if (res.code !== 0 && !isTaskNotRunning(res)) {
|
||||
throw new Error(`schtasks end failed: ${res.stderr || res.stdout}`.trim());
|
||||
}
|
||||
stdout.write(`Stopped Scheduled Task: ${GATEWAY_WINDOWS_TASK_NAME}\n`);
|
||||
stdout.write(
|
||||
`${formatLine("Stopped Scheduled Task", GATEWAY_WINDOWS_TASK_NAME)}\n`,
|
||||
);
|
||||
}
|
||||
|
||||
export async function restartScheduledTask({
|
||||
@@ -286,7 +296,9 @@ export async function restartScheduledTask({
|
||||
if (res.code !== 0) {
|
||||
throw new Error(`schtasks run failed: ${res.stderr || res.stdout}`.trim());
|
||||
}
|
||||
stdout.write(`Restarted Scheduled Task: ${GATEWAY_WINDOWS_TASK_NAME}\n`);
|
||||
stdout.write(
|
||||
`${formatLine("Restarted Scheduled Task", GATEWAY_WINDOWS_TASK_NAME)}\n`,
|
||||
);
|
||||
}
|
||||
|
||||
export async function isScheduledTaskInstalled(): Promise<boolean> {
|
||||
@@ -400,7 +412,9 @@ export async function uninstallLegacyScheduledTasks({
|
||||
|
||||
try {
|
||||
await fs.unlink(task.scriptPath);
|
||||
stdout.write(`Removed legacy task script: ${task.scriptPath}\n`);
|
||||
stdout.write(
|
||||
`${formatLine("Removed legacy task script", task.scriptPath)}\n`,
|
||||
);
|
||||
} catch {
|
||||
stdout.write(`Legacy task script not found at ${task.scriptPath}\n`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user