fixed issues with cocod init

This commit is contained in:
redshift
2026-04-23 17:12:58 +05:30
parent 3a81b97371
commit 293f1098a5
+22 -49
View File
@@ -73,28 +73,28 @@ async function printLightningInvoice(invoice: string): Promise<void> {
console.log(`${qr}\nInvoice:\n${invoice}`);
}
async function installCocodOrExit(): Promise<void> {
logger.log("cocod not found. Installing globally with bun...");
const installProc = Bun.spawn(["bun", "install", "--global", "cocod"], {
stdout: "inherit",
stderr: "inherit",
});
const installCode = await installProc.exited;
if (installCode !== 0 || !(await isCocodInstalled())) {
logger.error(
"Failed to install cocod. Please run 'bun install --global cocod' manually.",
);
throw new Error("cocod installation failed");
}
logger.log("cocod installed successfully.");
}
async function initDaemon(): Promise<void> {
logger.log("Initializing routstrd...");
if (!(await checkCocodInstalled())) {
logger.log("cocod not found. Installing globally with bun...");
const installProc = Bun.spawn(["bun", "install", "--global", "cocod"], {
stdout: "inherit",
stderr: "inherit",
});
const installCode = await installProc.exited;
if (installCode !== 0 || !(await checkCocodInstalled())) {
logger.error(
"Failed to install cocod. Please run 'bun install --global cocod' manually.",
);
return;
}
logger.log("cocod installed successfully.");
}
// Create config directory
if (!existsSync(CONFIG_DIR)) {
mkdirSync(CONFIG_DIR, { recursive: true });
@@ -112,7 +112,6 @@ async function initDaemon(): Promise<void> {
}
const config = await loadConfig();
const cocodExecutable = resolveCocodExecutable(config.cocodPath);
if (!(await isCocodInstalled(config.cocodPath))) {
if (config.cocodPath) {
@@ -122,24 +121,11 @@ async function initDaemon(): Promise<void> {
return;
}
logger.log("cocod not found. Installing globally with bun...");
const installProc = Bun.spawn(["bun", "install", "--global", "cocod"], {
stdout: "inherit",
stderr: "inherit",
});
const installCode = await installProc.exited;
if (installCode !== 0 || !(await isCocodInstalled(config.cocodPath))) {
logger.error(
"Failed to install cocod. Please run 'bun install --global cocod' manually.",
);
return;
}
logger.log("cocod installed successfully.");
await installCocodOrExit();
}
const cocodExecutable = resolveCocodExecutable(config.cocodPath);
console.log(`Database will be stored at: ${DB_PATH}`);
console.log("\nInitializing cocod...");
@@ -216,19 +202,6 @@ async function initDaemon(): Promise<void> {
);
}
async function checkCocodInstalled(): Promise<boolean> {
try {
const proc = Bun.spawn({
cmd: ["which", "cocod"],
stdout: "pipe",
});
const code = await proc.exited;
return code === 0;
} catch {
return false;
}
}
program
.name("routstrd")
.description("Routstr daemon - Manage routstr processes")