mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
headless-sync-server-plugin
This commit is contained in:
52
server/plugins/headless-sync/ob-cli.js
Normal file
52
server/plugins/headless-sync/ob-cli.js
Normal file
@@ -0,0 +1,52 @@
|
||||
const { spawn, execSync } = require("child_process");
|
||||
const os = require("os");
|
||||
|
||||
function checkInstalled() {
|
||||
try {
|
||||
const output = execSync("ob --version", { stdio: "pipe" }).toString().trim();
|
||||
return { installed: true, version: output || "unknown" };
|
||||
} catch {
|
||||
return { installed: false, version: null };
|
||||
}
|
||||
}
|
||||
|
||||
function runCommand(args, opts = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const spawnOpts = {
|
||||
env: { ...process.env, HOME: os.homedir() },
|
||||
};
|
||||
|
||||
if (opts.cwd) {
|
||||
spawnOpts.cwd = opts.cwd;
|
||||
}
|
||||
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
|
||||
const proc = spawn("ob", args, spawnOpts);
|
||||
|
||||
proc.stdout.on("data", (data) => {
|
||||
stdout += data.toString();
|
||||
});
|
||||
|
||||
proc.stderr.on("data", (data) => {
|
||||
stderr += data.toString();
|
||||
});
|
||||
|
||||
proc.on("close", (code) => {
|
||||
if (code === 0) {
|
||||
resolve({ stdout, stderr });
|
||||
} else {
|
||||
reject(
|
||||
new Error(`ob ${args[0]} failed (code ${code}): ${stderr || stdout}`),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
proc.on("error", (err) => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { checkInstalled, runCommand };
|
||||
Reference in New Issue
Block a user