Add new Bds Maneger Core CLI #194
@ -4,7 +4,6 @@ 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 serverline = require("serverline");
|
const serverline = require("serverline");
|
||||||
|
|
||||||
// Bin Args
|
// Bin Args
|
||||||
@ -46,9 +45,11 @@ async function Runner() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(ProcessArgs.start || ProcessArgs.s)) return;
|
||||||
|
|
||||||
// Start
|
// Start
|
||||||
const BdsCoreStart = BdsCore.start();
|
const BdsCoreStart = BdsCore.start();
|
||||||
BdsCoreStart.log(data => process.stdout.write(cli_color.blueBright(data)));
|
BdsCoreStart.log(data => console.log(cli_color.blueBright(data.replace(/\n$/gi, ""))));
|
||||||
BdsCoreStart.exit(code => {
|
BdsCoreStart.exit(code => {
|
||||||
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);
|
||||||
@ -56,8 +57,10 @@ async function Runner() {
|
|||||||
serverline.init();
|
serverline.init();
|
||||||
serverline.setCompletion(["tp"]);
|
serverline.setCompletion(["tp"]);
|
||||||
serverline.setPrompt("Command > ");
|
serverline.setPrompt("Command > ");
|
||||||
serverline.on('line', function(line) {
|
serverline.on("line", function(line) {
|
||||||
BdsCoreStart.command(line);
|
if (/^@/.test(line)) {
|
||||||
|
console.log("🤪It's not working yet!");
|
||||||
|
} else BdsCoreStart.command(line);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Runner();
|
Runner();
|
||||||
|
2
index.js
2
index.js
@ -5,7 +5,7 @@ const fs = require("fs");
|
|||||||
const randomUUID = require("uuid").v4;
|
const randomUUID = require("uuid").v4;
|
||||||
const { bds_dir } = require("./lib/BdsSettings");
|
const { bds_dir } = require("./lib/BdsSettings");
|
||||||
|
|
||||||
if (typeof fetch === "undefined") global.fetch = require("node-fetch");
|
require("./lib/Requests")
|
||||||
|
|
||||||
const bds_core_package = resolve(__dirname, "package.json")
|
const bds_core_package = resolve(__dirname, "package.json")
|
||||||
module.exports.package_path = bds_core_package
|
module.exports.package_path = bds_core_package
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
const { join, resolve, basename } = require("path");
|
const { join, resolve, basename } = require("path");
|
||||||
const { existsSync, writeFileSync, mkdirSync, readFileSync } = require("fs");
|
const { existsSync, writeFileSync, mkdirSync, readFileSync } = require("fs");
|
||||||
const { homedir } = require("os");
|
const { homedir } = require("os");
|
||||||
const BdsInfo = require("./BdsSystemInfo");
|
|
||||||
const yaml = require("js-yaml");
|
const yaml = require("js-yaml");
|
||||||
|
|
||||||
// PATHs
|
// PATHs
|
||||||
@ -9,19 +8,6 @@ const home = homedir();
|
|||||||
const bds_dir = join(home, "bds_core");
|
const bds_dir = join(home, "bds_core");
|
||||||
if (!(existsSync(bds_dir))) mkdirSync(bds_dir, {recursive: true})
|
if (!(existsSync(bds_dir))) mkdirSync(bds_dir, {recursive: true})
|
||||||
|
|
||||||
BdsInfo().then(validation => {
|
|
||||||
const { valid_platform } = validation;
|
|
||||||
// Set default platform for bds maneger
|
|
||||||
var default_platformConfig;
|
|
||||||
if (valid_platform["bedrock"]) default_platformConfig = "bedrock";
|
|
||||||
else if (valid_platform["java"]) default_platformConfig = "java";
|
|
||||||
else if (valid_platform["pocketmine"]) default_platformConfig = "pocketmine";
|
|
||||||
else throw new Error("We cannot run any platforms on this system/device");
|
|
||||||
UpdatePlatform(default_platformConfig);
|
|
||||||
}).catch(err => {
|
|
||||||
console.log(err);
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Config Base to Bds Maneger Core and others Projects
|
// Config Base to Bds Maneger Core and others Projects
|
||||||
var Config = {
|
var Config = {
|
||||||
@ -115,12 +101,12 @@ var Config = {
|
|||||||
|
|
||||||
// Config
|
// Config
|
||||||
const ConfigPath = join(resolve(homedir(), "bds_core"), "BdsConfig.yaml")
|
const ConfigPath = join(resolve(homedir(), "bds_core"), "BdsConfig.yaml")
|
||||||
function SaveConfig(){writeFileSync(ConfigPath, yaml.dump(Config));}
|
|
||||||
if (existsSync(ConfigPath)) Config = {
|
const SaveConfig = () => writeFileSync(ConfigPath, yaml.dump(Config));
|
||||||
...Config,
|
process.on("exit", () => SaveConfig());
|
||||||
...yaml.load(readFileSync(ConfigPath, "utf8"))
|
|
||||||
}; else writeFileSync(ConfigPath, yaml.dump(Config))
|
if (existsSync(ConfigPath)) Config = yaml.load(readFileSync(ConfigPath, "utf8"));
|
||||||
process.on("exit", () => SaveConfig())
|
else writeFileSync(ConfigPath, yaml.dump(Config))
|
||||||
|
|
||||||
// Paths
|
// Paths
|
||||||
if (!(existsSync(Config.paths["backups"]))) mkdirSync(Config.paths["backups"], {recursive: true})
|
if (!(existsSync(Config.paths["backups"]))) mkdirSync(Config.paths["backups"], {recursive: true})
|
||||||
@ -168,21 +154,20 @@ function UpdateServerVersion(version = null, platform = Config.server.platform){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the entire Bds Manager Core platform
|
// Update the entire Bds Manager Core platform
|
||||||
function UpdatePlatform(platform = Config.server.platform){
|
function UpdatePlatform(platform = "null"){
|
||||||
platform = platform.toLocaleLowerCase();
|
platform = platform.toLocaleLowerCase();
|
||||||
if (/bedrock/.test(platform)) {
|
if (/bedrock/.test(platform)) {
|
||||||
Config.server.platform = "bedrock";
|
Config.server.platform = "bedrock";
|
||||||
SaveConfig()
|
|
||||||
} else if (/java/.test(platform)) {
|
} else if (/java/.test(platform)) {
|
||||||
Config.server.platform = "java";
|
Config.server.platform = "java";
|
||||||
SaveConfig()
|
|
||||||
} else if (/pocketmine/.test(platform)) {
|
} else if (/pocketmine/.test(platform)) {
|
||||||
Config.server.platform = "pocketmine";
|
Config.server.platform = "pocketmine";
|
||||||
SaveConfig()
|
|
||||||
} else if (/spigot/.test(platform)) {
|
} else if (/spigot/.test(platform)) {
|
||||||
Config.server.platform = "spigot";
|
Config.server.platform = "spigot";
|
||||||
SaveConfig()
|
} else if (/dragonfly/.test(platform)) {
|
||||||
} else throw new Error("platform no Exists")
|
Config.server.platform = "dragonfly";
|
||||||
|
} else throw new Error("platform no exists");
|
||||||
|
SaveConfig();
|
||||||
return platform
|
return platform
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ async function CheckSystemAsync() {
|
|||||||
|
|
||||||
if (valid_platform["bedrock"] === false) {
|
if (valid_platform["bedrock"] === false) {
|
||||||
if (commadExist("qemu-x86_64-static")) {
|
if (commadExist("qemu-x86_64-static")) {
|
||||||
console.warn("The Minecraft Bedrock Server is only being validated because you can use 'qemu-x86_64-static'");
|
// console.warn("The Minecraft Bedrock Server is only being validated because you can use 'qemu-x86_64-static'");
|
||||||
valid_platform["bedrock"] = true
|
valid_platform["bedrock"] = true
|
||||||
require_qemu = true
|
require_qemu = true
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,7 @@ function start() {
|
|||||||
else if (GetPlatform() === "pocketmine") {
|
else if (GetPlatform() === "pocketmine") {
|
||||||
// Start PocketMine-MP
|
// Start PocketMine-MP
|
||||||
SetupCommands.command = path.join(path.resolve(GetServerPaths("pocketmine"), "bin", "php7", "bin"), "php");
|
SetupCommands.command = path.join(path.resolve(GetServerPaths("pocketmine"), "bin", "php7", "bin"), "php");
|
||||||
|
if (process.platform === "win32") SetupCommands.command = path.join(path.resolve(GetServerPaths("pocketmine"), "bin/php"), "php.exe");
|
||||||
SetupCommands.args.push("./PocketMine-MP.phar");
|
SetupCommands.args.push("./PocketMine-MP.phar");
|
||||||
SetupCommands.cwd = GetServerPaths("pocketmine");
|
SetupCommands.cwd = GetServerPaths("pocketmine");
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ const fs = require("fs");
|
|||||||
const os = require("os");
|
const os = require("os");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const { writeFileSync, existsSync, readFileSync, readdirSync, rmSync } = fs;
|
const { writeFileSync, existsSync, readFileSync, readdirSync, rmSync } = fs;
|
||||||
const { join, resolve, basename } = path;
|
const { join, resolve } = path;
|
||||||
var AdmZip = require("adm-zip");
|
var AdmZip = require("adm-zip");
|
||||||
const BdsInfo = require("../lib/BdsSystemInfo");
|
const BdsInfo = require("../lib/BdsSystemInfo");
|
||||||
const { GetServerPaths, GetServerVersion, UpdateServerVersion, GetPlatform } = require("../lib/BdsSettings");
|
const { GetServerPaths, GetServerVersion, UpdateServerVersion, GetPlatform } = require("../lib/BdsSettings");
|
||||||
@ -214,7 +214,7 @@ module.exports = function (version = true, force_install = false, callback = (er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New Download Method
|
// New Download Method
|
||||||
module.exports.v2 = async (version = true, force = true) => {
|
module.exports.v2 = async (version = true) => {
|
||||||
const CurrentPlatform = GetPlatform();
|
const CurrentPlatform = GetPlatform();
|
||||||
const valid_platform = (await BdsInfo()).valid_platform;
|
const valid_platform = (await BdsInfo()).valid_platform;
|
||||||
const LocalServersVersions = bds.BdsSettigs.GetServerVersion();
|
const LocalServersVersions = bds.BdsSettigs.GetServerVersion();
|
||||||
@ -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.bedrock !== version) {
|
if (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,7 +279,7 @@ 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.java !== version) {
|
if (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;
|
||||||
@ -304,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.spigot !== version) {
|
if (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;
|
||||||
@ -326,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.dragonfly !== version) {
|
if (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 = "";
|
||||||
@ -355,7 +355,29 @@ module.exports.v2 = async (version = true, force = true) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pocketmine-MP
|
// Pocketmine-MP
|
||||||
else if (CurrentPlatform === "pocketmine") {throw new Error("We are still creating for Pocketmine-MP");}
|
else if (CurrentPlatform === "pocketmine") {
|
||||||
|
if (valid_platform.pocketmine) {
|
||||||
|
if (LocalServersVersions.pocketmine !== version) {
|
||||||
|
// Add info to ReturnObject
|
||||||
|
ReturnObject.url = ServerDownloadJSON.pocketmine[version].url;
|
||||||
|
ReturnObject.data = ServerDownloadJSON.pocketmine[version].data;
|
||||||
|
|
||||||
|
// Download PHP Bin
|
||||||
|
await php_download();
|
||||||
|
|
||||||
|
// Download php file and save
|
||||||
|
const PocketmineBufferPhp = await Request.buffer(ReturnObject.url);
|
||||||
|
fs.writeFileSync(path.join(ServersPaths.pocketmine, "PocketMine-MP.phar"), PocketmineBufferPhp, "binary");
|
||||||
|
|
||||||
|
// Update Server Version
|
||||||
|
bds.BdsSettigs.UpdateServerVersion(version, CurrentPlatform);
|
||||||
|
} else {
|
||||||
|
ReturnObject.skip = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw Error("Pocketmine-MP not suported");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if the platform does not exist
|
// if the platform does not exist
|
||||||
else throw Error("No Valid Platform");
|
else throw Error("No Valid Platform");
|
||||||
@ -379,17 +401,13 @@ async function php_download() {
|
|||||||
|
|
||||||
// Remove Old php Binary if it exists
|
// Remove Old php Binary if it exists
|
||||||
if (existsSync(phpFolder)) {
|
if (existsSync(phpFolder)) {
|
||||||
console.log("Removing old PHP files.");
|
|
||||||
rmSync(phpFolder, { recursive: true });
|
rmSync(phpFolder, { recursive: true });
|
||||||
}
|
}
|
||||||
console.log(`Downloading ${urlPHPBin}`);
|
|
||||||
const ZipBuffer = Buffer.from((await (await fetch(urlPHPBin)).arrayBuffer()));
|
const ZipBuffer = Buffer.from((await (await fetch(urlPHPBin)).arrayBuffer()));
|
||||||
console.log(`${basename(urlPHPBin)} downloaded`);
|
|
||||||
|
|
||||||
console.log(`Extracting ${basename(urlPHPBin)}`);
|
|
||||||
const zipExtractBin = new AdmZip(ZipBuffer);
|
const zipExtractBin = new AdmZip(ZipBuffer);
|
||||||
zipExtractBin.extractAllTo(bds_dir_pocketmine, false)
|
zipExtractBin.extractAllTo(bds_dir_pocketmine, false)
|
||||||
console.log("Successfully extracting the binaries")
|
|
||||||
|
if (process.platform === "win32") return resolve();
|
||||||
|
|
||||||
let phpConfigInit = readFileSync(join(phpFolder, "php7", "bin", "php.ini"), "utf8");
|
let phpConfigInit = readFileSync(join(phpFolder, "php7", "bin", "php.ini"), "utf8");
|
||||||
if (!(existsSync(phpExtensiosnsDir))) return true;
|
if (!(existsSync(phpExtensiosnsDir))) return true;
|
||||||
|
Reference in New Issue
Block a user