Add new Bds Maneger Core CLI #194

Merged
Sirherobrine23 merged 12 commits from CLI into main 2021-09-25 06:20:18 +00:00
5 changed files with 50 additions and 61 deletions
Showing only changes of commit 0530612a94 - Show all commits

View File

@ -5,6 +5,7 @@ process.env.IS_BDS_CLI = process.env.IS_BIN_BDS = true;
// External Modules // External Modules
const cli_color = require("cli-color"); const cli_color = require("cli-color");
const inquirer = require("inquirer"); const inquirer = require("inquirer");
const serverline = require("serverline");
// Bin Args // Bin Args
const ProcessArgs = require("minimist")(process.argv.slice(2)); const ProcessArgs = require("minimist")(process.argv.slice(2));
@ -52,26 +53,11 @@ async function Runner() {
console.log(cli_color.redBright(`Bds Core Exit with code ${code}, Uptimed: ${BdsCoreStart.uptime}`)); console.log(cli_color.redBright(`Bds Core Exit with code ${code}, Uptimed: ${BdsCoreStart.uptime}`));
process.exit(code); process.exit(code);
}); });
const BdsCliMenus = require("./bds_maneger/menus"); serverline.init();
const InfinitCommands = async () => { serverline.setCompletion(["tp"]);
const CommandtoRun = (await inquirer.prompt([ serverline.setPrompt("Command > ");
{ serverline.on('line', function(line) {
type: "list", BdsCoreStart.command(line);
name: "commands", });
message: "Select a command",
choices: [
"tp"
]
}
])).commands;
if (CommandtoRun === "tp") {
BdsCliMenus.tp();
return await InfinitCommands();
} else {
BdsCliMenus.Command();
return await InfinitCommands();
}
}
InfinitCommands();
} }
Runner(); Runner();

14
package-lock.json generated
View File

@ -30,6 +30,7 @@
"ora": "^6.0.1", "ora": "^6.0.1",
"properties-to-json": "^0.2.1", "properties-to-json": "^0.2.1",
"request-ip": "^2.1.3", "request-ip": "^2.1.3",
"serverline": "^1.5.0",
"telegraf": "^4.0.0", "telegraf": "^4.0.0",
"uuid": "^8.3.2" "uuid": "^8.3.2"
}, },
@ -4995,6 +4996,14 @@
"node": ">= 0.8.0" "node": ">= 0.8.0"
} }
}, },
"node_modules/serverline": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/serverline/-/serverline-1.5.0.tgz",
"integrity": "sha512-QzNBH8omGchv+L5n/irZEeU2IGK3r8EMRh3EKRIlbfTklf9PtNRiRbWcYr8kqdNeWdc5M5jS13VtspDKgFXFFg==",
"engines": {
"node": ">=10.0.0"
}
},
"node_modules/setprototypeof": { "node_modules/setprototypeof": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
@ -9773,6 +9782,11 @@
"send": "0.17.1" "send": "0.17.1"
} }
}, },
"serverline": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/serverline/-/serverline-1.5.0.tgz",
"integrity": "sha512-QzNBH8omGchv+L5n/irZEeU2IGK3r8EMRh3EKRIlbfTklf9PtNRiRbWcYr8kqdNeWdc5M5jS13VtspDKgFXFFg=="
},
"setprototypeof": { "setprototypeof": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",

View File

@ -69,6 +69,7 @@
"ora": "^6.0.1", "ora": "^6.0.1",
"properties-to-json": "^0.2.1", "properties-to-json": "^0.2.1",
"request-ip": "^2.1.3", "request-ip": "^2.1.3",
"serverline": "^1.5.0",
"telegraf": "^4.0.0", "telegraf": "^4.0.0",
"uuid": "^8.3.2" "uuid": "^8.3.2"
}, },

View File

@ -85,22 +85,6 @@ function start() {
env: SetupCommands.env env: SetupCommands.env
}); });
// Post Start
if (GetPlatform() === "java") {
const eula_file_path = path.join(GetServerPaths("java"), "eula.txt");
if (fs.existsSync(eula_file_path)) {
const eula_file = fs.readFileSync(eula_file_path, "utf8");
console.log(eula_file);
if (eula_file.includes("eula=false")) {
fs.writeFileSync(eula_file_path, eula_file.replace(/eula=false/gi, "eula=true"));
throw new Error("Restart application/CLI")
}
} else {
console.log("EULA file not found");
throw new Error("EULA file not found")
}
}
// Log file // Log file
const LogFile = path.join(GetPaths("log"), `${GetPlatform()}_${new Date().toString().replace(/:|\(|\)/g, "_")}_Bds_log.log`); const LogFile = path.join(GetPaths("log"), `${GetPlatform()}_${new Date().toString().replace(/:|\(|\)/g, "_")}_Bds_log.log`);
const LatestLog_Path = path.join(GetPaths("log"), "latest.log"); const LatestLog_Path = path.join(GetPaths("log"), "latest.log");

View File

@ -238,7 +238,7 @@ module.exports.v2 = async (version = true, force = true) => {
// Bedrock // Bedrock
if (CurrentPlatform === "bedrock") { if (CurrentPlatform === "bedrock") {
if (valid_platform.bedrock) { if (valid_platform.bedrock) {
if (!(force === true && typeof force === "boolean") && LocalServersVersions !== version) { if (!(force === true && typeof force === "boolean") && LocalServersVersions.bedrock !== version) {
// Add info to ReturnObject // Add info to ReturnObject
ReturnObject.url = ServerDownloadJSON.bedrock[version][bds.arch][process.platform]; ReturnObject.url = ServerDownloadJSON.bedrock[version][bds.arch][process.platform];
ReturnObject.data = ServerDownloadJSON.bedrock[version].data; ReturnObject.data = ServerDownloadJSON.bedrock[version].data;
@ -279,13 +279,14 @@ module.exports.v2 = async (version = true, force = true) => {
// Java // Java
else if (CurrentPlatform === "java") { else if (CurrentPlatform === "java") {
if (valid_platform.java) { if (valid_platform.java) {
if (!(force === true && typeof force === "boolean") && LocalServersVersions !== version) { if (!(force === true && typeof force === "boolean") && LocalServersVersions.java !== version) {
// Add info to ReturnObject // Add info to ReturnObject
ReturnObject.url = ServerDownloadJSON.java[version].url; ReturnObject.url = ServerDownloadJSON.java[version].url;
ReturnObject.data = ServerDownloadJSON.java[version].data; ReturnObject.data = ServerDownloadJSON.java[version].data;
// Download and write java file // Download and write java file
fs.writeFileSync(path.join(ServersPaths.java, "MinecraftServerJava.jar"), await Request.buffer(ReturnObject.url), "binary"); const JavaBufferJar = await Request.buffer(ReturnObject.url);
fs.writeFileSync(path.join(ServersPaths.java, "MinecraftServerJava.jar"), JavaBufferJar, "binary");
// Write EULA // Write EULA
fs.writeFileSync(path.join(ServersPaths.java, "eula.txt"), "eula=true"); fs.writeFileSync(path.join(ServersPaths.java, "eula.txt"), "eula=true");
@ -303,7 +304,7 @@ module.exports.v2 = async (version = true, force = true) => {
// Spigot // Spigot
else if (CurrentPlatform === "spigot") { else if (CurrentPlatform === "spigot") {
if (valid_platform.spigot) { if (valid_platform.spigot) {
if (!(force === true && typeof force === "boolean") && LocalServersVersions !== version) { if (!(force === true && typeof force === "boolean") && LocalServersVersions.spigot !== version) {
// Add info to ReturnObject // Add info to ReturnObject
const FindedSpigot = ServerDownloadJSON.spigot.findOne(spigot => spigot.version === version); const FindedSpigot = ServerDownloadJSON.spigot.findOne(spigot => spigot.version === version);
ReturnObject.url = FindedSpigot.url; ReturnObject.url = FindedSpigot.url;
@ -325,7 +326,7 @@ module.exports.v2 = async (version = true, force = true) => {
// Dragonfly // Dragonfly
else if (CurrentPlatform === "dragonfly") { else if (CurrentPlatform === "dragonfly") {
if (valid_platform.dragonfly) { if (valid_platform.dragonfly) {
if (!(force === true && typeof force === "boolean") && LocalServersVersions !== version) { if (!(force === true && typeof force === "boolean") && LocalServersVersions.dragonfly !== version) {
// Add info to ReturnObject // Add info to ReturnObject
ReturnObject.url = "https://github.com/df-mc/dragonfly/tree/master"; ReturnObject.url = "https://github.com/df-mc/dragonfly/tree/master";
ReturnObject.data = ""; ReturnObject.data = "";
@ -353,6 +354,9 @@ module.exports.v2 = async (version = true, force = true) => {
} }
} }
// Pocketmine-MP
else if (CurrentPlatform === "pocketmine") {throw new Error("We are still creating for Pocketmine-MP");}
// if the platform does not exist // if the platform does not exist
else throw Error("No Valid Platform"); else throw Error("No Valid Platform");