UNPKG

@botport/core

Version:

Unified framework for Discord bot products, published by BotPort. Combines docky and framework functionality.

96 lines (81 loc) â€ĸ 3.71 kB
import chalk from "chalk"; import { readFileSync } from "fs"; import { join } from "path"; import latestVersion from "latest-version"; import { getFrameworkDir } from "../utils/pathResolver.js"; const getPackageInfo = () => { try { // Read from the FRAMEWORK's package.json using the path resolver const packagePath = join(getFrameworkDir(), "package.json"); const pkg = JSON.parse(readFileSync(packagePath, "utf8")); return { version: pkg.version || "unknown", name: pkg.name || "unknown", }; } catch (error) { console.error(chalk.red("Error reading package.json:"), error.message); return { version: "unknown", name: "unknown" }; } }; const getLatestVersion = async (packageName) => { try { if (packageName === "unknown") return null; return await latestVersion(packageName); } catch (error) { // Silently fail if we can't check for updates (might be offline or package not published) return null; } }; const compareVersions = (current, latest) => { if (!latest || current === "unknown") return null; const curParts = current.split('.').map(Number); const latParts = latest.split('.').map(Number); const len = Math.max(curParts.length, latParts.length); for (let i = 0; i < len; i++) { const cur = curParts[i] || 0; const lat = latParts[i] || 0; if (cur < lat) return -1; if (cur > lat) return 1; } return 0; }; const logBanner = async () => { const { version: currentVersion, name: packageName } = getPackageInfo(); const asciiArt = ` ${chalk.cyan(" ____ ____ ______ ____ ____ ____ ______")} ${chalk.cyan(" / __ )/ __ \\/_ __/ / __ \\/ __ \\/ __ \\/_ __/")} ${chalk.cyan(" / __ / / / / / / / /_/ / / / / /_/ / / / ")} ${chalk.cyan(" / /_/ / /_/ / / / / ____/ /_/ / _, _/ / / ")} ${chalk.cyan("/_____/\\____/ /_/ /_/ \\____/_/ |_| /_/ ")} ${chalk.white("🤖 BotPort Framework")} ${chalk.gray(`v${currentVersion}`)} ${chalk.white("─────────────────────────────────────────────")} ${chalk.green("✅ Framework successfully initialized")}`; console.log(asciiArt); if (packageName !== "unknown" && currentVersion !== "unknown") { try { const latest = await getLatestVersion(packageName); if (!latest) { // Could not fetch latest version (offline or not published) console.log(chalk.gray("â„šī¸ Could not check for updates")); } else { const cmp = compareVersions(currentVersion, latest); if (cmp === -1) { console.log(chalk.yellow(`đŸ“Ļ Update available: v${currentVersion} → v${latest}`)); console.log(chalk.yellow(` Run: npm update ${packageName}`)); } else if (cmp === 0) { console.log(chalk.green("✅ You're running the latest version!")); } else if (cmp === 1) { console.log(chalk.blue(`🚀 Running v${currentVersion} (latest published: v${latest})`)); } } } catch { console.log(chalk.gray("â„šī¸ Could not check for updates")); } } else { console.log(chalk.gray("â„šī¸ Package version could not be determined")); } console.log(chalk.white("─────────────────────────────────────────────")); console.log(chalk.cyan("🔗 Check us out on GitHub: https://github.com/BotPortOfficial")); console.log(chalk.white("─────────────────────────────────────────────")); }; export default logBanner;