phion
Version:
Phion Development Agent and Vite Plugin for seamless code sync and auto-deploy
92 lines (90 loc) • 2.56 kB
JavaScript
import {
PhionAgent,
checkForUpdates,
getCurrentVersion
} from "./chunk-FNONEKCO.mjs";
// src/cli.ts
import fs from "fs";
import path from "path";
function loadConfig() {
const configPath = path.join(process.cwd(), "phion.config.json");
if (fs.existsSync(configPath)) {
try {
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
return {
projectId: config.projectId,
wsUrl: config.wsUrl || process.env.PHION_WS_URL || "ws://localhost:8080",
debug: config.debug || false,
toolbar: config.toolbar || {
enabled: true,
position: "top",
autoOpen: true
}
};
} catch (error) {
console.error("\u274C Error reading phion.config.json:", error.message);
}
}
const projectId = process.env.PHION_PROJECT_ID || process.argv[2];
const wsUrl = process.env.PHION_WS_URL || "ws://localhost:8080";
if (!projectId || projectId === "__PROJECT_ID__") {
console.error("\u274C Missing project ID!");
console.log("Add project ID to phion.config.json or pass as argument");
process.exit(1);
}
return {
projectId,
wsUrl,
debug: false,
toolbar: {
enabled: true,
position: "top",
autoOpen: true
}
};
}
async function checkForUpdates2(wsUrl, debug = false) {
try {
const currentVersion = getCurrentVersion();
console.log(`\u{1F4E6} Phion v${currentVersion}`);
if (debug) {
try {
const versionInfo = await checkForUpdates(wsUrl);
if (versionInfo.hasUpdate && versionInfo.latest) {
console.log(`\u{1F195} New version ${versionInfo.latest} available!`);
console.log("\u{1F4E5} Run 'pnpm update phion' to update");
console.log("");
}
} catch (updateCheckError) {
console.debug("Update check failed:", updateCheckError);
}
}
} catch (error) {
}
}
async function main() {
try {
const config = loadConfig();
await checkForUpdates2(config.wsUrl, config.debug);
const agent = new PhionAgent(config);
const shutdown = () => {
agent.stop();
process.exit(0);
};
process.on("SIGINT", shutdown);
process.on("SIGTERM", shutdown);
await agent.start();
process.stdin.setRawMode?.(true);
process.stdin.resume();
process.stdin.on("data", (key) => {
if (key[0] === 3) {
shutdown();
}
});
} catch (error) {
console.error("\u274C Failed to start Phion Agent:", error.message);
process.exit(1);
}
}
main();