UNPKG

dango-cli

Version:

A configurable minecraft BE to Discord Bot cli tool

110 lines (100 loc) 3.37 kB
#!/usr/bin/env node const fs = require("fs"); const path = require("path"); const { execSync } = require("child_process"); const packageDir = __dirname; // The folder where your CLI is installed const configPath = path.join(process.cwd(), "config.json"); // 1️⃣ Make config.json if not found if (!fs.existsSync(configPath)) { console.log("📂 Making template config.json (none found)..."); const templateConfig = { botToken: "discord bot token here", clientId: "discord client ID here", username: "Discord Bot Name", webhookUrl: "discord webhook URL here", realms: [ { realmName: "Name of Realm", realmCode: "Realm Code", logChannels: { chat: "channel ID for chat", kicks: "channel ID for kicks", joinsAndLeaves: "channel ID for joins and leaves" }, modules: { deviceFilter: false, whitelist: false } } ], admins: ["admins user ID here"], whitelist: ["any username can go here"], bannedDevices: [ "Windows", "Android", "iOS", "WindowsPhone", "Win32", "Dedicated", "PlayStation" ], altSystem: { maxGamerScore: 0, maxFriends: 0, maxFollowers: 0 } }; fs.writeFileSync(configPath, JSON.stringify(templateConfig, null, 4), "utf8"); console.log("✅ Created template config.json"); } // 2️⃣ Auto-install dependencies if missing function installDeps() { const pkgJson = path.join(packageDir, "package.json"); if (!fs.existsSync(pkgJson)) { console.error("❌ package.json not found in CLI package folder!"); process.exit(1); } const pkg = require(pkgJson); const dependencies = Object.keys(pkg.dependencies || {}); const missing = dependencies.filter(dep => { try { require.resolve(dep, { paths: [packageDir] }); return false; } catch { return true; } }); if (missing.length > 0) { console.log("📦 Installing missing dependencies:", missing.join(", ")); try { execSync(`npm install ${missing.join(" ")}`, { cwd: packageDir, stdio: "inherit" }); console.log("✅ Dependencies installed!"); } catch (err) { console.error("❌ Failed to install dependencies:", err.message); process.exit(1); } } } installDeps(); // 3️⃣ Load config.json let config; try { config = JSON.parse(fs.readFileSync(configPath, "utf8")); console.log("✅ Loaded config:", config); } catch (err) { console.error("❌ Error reading config.json:", err.message); process.exit(1); } // 4️⃣ Run the package’s index.js try { const main = require(path.join(packageDir, "index.js")); if (typeof main === "function") { main(config); } } catch (err) { console.error("❌ Error running package index.js:", err.message); process.exit(1); }