From 868ef2613628fc85b4039fe6d2fb5bf7308725bd Mon Sep 17 00:00:00 2001 From: Matheus Sampaio Queiroga Date: Mon, 16 Aug 2021 22:23:08 -0300 Subject: [PATCH 1/5] Update binaris, Update README, Init remove fetchSync --- .gitignore | 1 + .npmignore | 15 +++++- BdsManegerInfo.json | 31 +++++++++++- DockerConfig.yaml | 5 +- Dockerfile | 22 ++++----- README.md | 70 +++++++++++++++++--------- bin/Docker.js | 100 ++++++++++++++++++++++---------------- bin/bds_maneger.js | 78 ++++++++++++++--------------- bin/telegram_bot.js | 7 +-- lib/BdsSettings.js | 21 +++----- lib/BdsSystemInfo.js | 6 ++- lib/ServerURL.js | 5 -- package-lock.json | 4 +- package.json | 4 +- src/BdsManegerServer.js | 20 +++++--- src/BdsServersDownload.js | 9 +--- 16 files changed, 238 insertions(+), 160 deletions(-) delete mode 100644 lib/ServerURL.js diff --git a/.gitignore b/.gitignore index de9db14..99a5e25 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ node_modules/ Bds_Maneger .dccache docs/ +the-bds-maneger-core-*.tgz # Bds Maneger Core Binaries bds_maneger diff --git a/.npmignore b/.npmignore index 99693aa..0a1aa9b 100644 --- a/.npmignore +++ b/.npmignore @@ -1,6 +1,14 @@ # Log *.log +# Develop files +.devcontainer/ +.vscode/ +.Build/ + +# Linters +.eslint* + # test files *.test *test*.js* @@ -12,5 +20,8 @@ git* .git* # Docker -.dockerignore -Docker* \ No newline at end of file +.docker* +Docker* + +# Npm +the-bds-maneger-core*.tgz \ No newline at end of file diff --git a/BdsManegerInfo.json b/BdsManegerInfo.json index 32e3166..7396513 100644 --- a/BdsManegerInfo.json +++ b/BdsManegerInfo.json @@ -8,10 +8,39 @@ "temp_host": { "url": "http://hosts.bdsmaneger.com:3020" }, - "download": { + "Fetchs": { "php": "https://raw.githubusercontent.com/The-Bds-Maneger/Php_Static_Binary/main/binarys.json", "servers": "https://raw.githubusercontent.com/The-Bds-Maneger/external_files/main/Server.json" }, + "IgnoreLog": { + "bedrock": [ + { + "value": "Running AutoCompaction", + "regex": true + } + ], + "java": [], + "pocketmine": [], + "spigot": [] + }, + "StartedServer": { + "bedrock": { + "value": "Server started", + "regex": true + }, + "java": { + "value": null, + "regex": false + }, + "pocketmine": { + "value": null, + "regex": false + }, + "spigot": { + "value": null, + "regex": false + } + }, "Servers": { "bedrock": { "stop": "stop", diff --git a/DockerConfig.yaml b/DockerConfig.yaml index d0f98f0..bc72ef5 100644 --- a/DockerConfig.yaml +++ b/DockerConfig.yaml @@ -4,7 +4,7 @@ tag: bdsmaneger/core:dev target: bdscore buildx: enable: false - platform: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 + platform: linux/amd64,linux/arm/v7,linux/arm64 # Docker Run envs env: @@ -47,5 +47,6 @@ ports: # More options options: build: [] - run: [] + run: + - "-v $(pwd)/Test:/root/bds_core" runArgv: [] diff --git a/Dockerfile b/Dockerfile index d50cee7..3765834 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,17 +15,6 @@ FROM bdsbase AS bdscore # Create Volume to Storage Server And Config VOLUME [ "/root/bds_core" ] -# Copy Bds Maneger Core -WORKDIR /opt/backend_core_scripts/ - -# Install Core dependencies -COPY package*.json ./ -RUN npm install - -# Copy BdsManger Core -COPY ./ ./ -RUN chmod a+x -v bin/* - # Set default ENVs to Bds Core ENV PLAYERS="5" \ WORLD_NAME="The Ultimate Server" \ @@ -40,5 +29,16 @@ ENV PLAYERS="5" \ # Bds Maneger Core required ports EXPOSE 19132/udp 19133/udp 1932/tcp +# Copy Bds Maneger Core +WORKDIR /opt/backend_core_scripts/ + +# Install Core dependencies +COPY package*.json ./ +RUN npm install + +# Copy BdsManger Core +COPY ./ ./ +RUN chmod a+x -v bin/* + # Set Entrypint ENTRYPOINT [ "node", "./bin/Docker.js" ] diff --git a/README.md b/README.md index 782c746..e88bc89 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,23 @@ # Bds Maneger Core -Create manage a server for Minecraft Bedrock, java and derivatives with an integration in NodeJs in which we deliver a versatile REST API for integration with large projects up to independent projects. +Bds Maneger Core is a javascript core in Nodejs that manages several types of server seftware for Minecraft Bedrock and Java. Bds Maneger Core has integrated with a REST API with full integration with Bds Maneger Core in addition to CLI and One bot versions for the telegram. Any contribution is welcome, but before a look at [CONTRIBUTING.md](CONTRIBUTING.md), [Bds Manager Core code of conduct](CODE_OF_CONDUCT.md) -## More important information for users before 1.10.0+ +## Requirements for Bds Maneger Core -In Version 1.11.0 there was a big change in the way to get the new settings and that left a good part of the program broken, so for those who are going to upgrade to the latest versions of Bds maneger Core will have to change the settings manually. +### All + +* [Nodejs 14+](https://nodejs.org/en/download/) +* [OpenJDK 16+](https://www.oracle.com/java/technologies/javase-jdk16-downloads.html) + +### Windows 10+ + +* [Microsoft Visual Studio C++ (The Bds Maneger Documentation)]() ## Documentation -We have a separate repository for all Bds Maneger Project documentation, link here from the main page, Repository link +We have a separate repository for all Bds Maneger Project documentation, [link here from the main page](), [Repository link](https://github.com/The-Bds-Maneger/Bds-Manager-Project-Documentation) ## Badges @@ -19,50 +26,65 @@ We have a separate repository for all Bds Maneger Project documentation, {console.log(Tokens+":", "Bds API Token:", token.token); Tokens++}); + } else { + console.log("No Tokens Found"); + } +} function StartServer(){ console.log("The entire log can be accessed via the api and/or the docker log"); @@ -13,32 +25,35 @@ function StartServer(){ ServerStarted.log(a => process.stdout.write(a)); ServerStarted.exit(process.exit); BdsCore.api(); - new CronJob("0 */1 * * *", async () => { - try { - const CurrentLocalVersion = BdsCore.getBdsConfig().server.versions[GetPlatform()], - CurrentRemoteVersion = Object.getOwnPropertyNames((await (await fetch(BdsInfo.download.servers)).json())[GetPlatform()])[0]; - if (CurrentLocalVersion !== CurrentRemoteVersion) { - let currenttime = `Hello we are starting the server upgrade from version ${CurrentLocalVersion} to version ${CurrentRemoteVersion}, you have 20 seconds to exit the server` - console.log("Update Server:", currenttime); - ServerStarted.say(currenttime); - let countdown = 20; - while (countdown > 1) { - currenttime = `${countdown} seconds remaining to stop Server!`; + ShowToken(); + if (process.env.UPDATE_SERVER === "true") { + new CronJob("0 */1 * * *", async () => { + try { + const CurrentLocalVersion = BdsCore.getBdsConfig().server.versions[GetPlatform()], + CurrentRemoteVersion = Object.getOwnPropertyNames((await (await fetch(BdsInfo.Fetchs.servers)).json())[GetPlatform()])[0]; + if (CurrentLocalVersion !== CurrentRemoteVersion) { + let currenttime = `Hello we are starting the server upgrade from version ${CurrentLocalVersion} to version ${CurrentRemoteVersion}, you have 20 seconds to exit the server` + console.log("Update Server:", currenttime); + ServerStarted.say(currenttime); + let countdown = 20; + while (countdown > 1) { + currenttime = `${countdown} seconds remaining to stop Server!`; + console.log(currenttime); + ServerStarted.say(currenttime); + countdown--; + await new Promise(resolve => setTimeout(resolve, 1000)); + } + currenttime = "Stopping the server" console.log(currenttime); ServerStarted.say(currenttime); - countdown--; - await new Promise(resolve => setTimeout(resolve, 1000)); + await new Promise(resolve => setTimeout(resolve, 600)); + ServerStarted.stop(); } - currenttime = "Stopping the server" - console.log(currenttime); - ServerStarted.say(currenttime); - await new Promise(resolve => setTimeout(resolve, 600)); - ServerStarted.stop(); + } catch (err) { + console.log(err); } - } catch (err) { - console.log(err); - } - }); + }); + } } // Check Installed Server @@ -53,22 +68,24 @@ if (Object.getOwnPropertyNames(AllVersions).filter(platform => AllVersions[platf StartServer(); }); } else { - // Check for Update - if (AllVersions[GetPlatform()] === Object.getOwnPropertyNames(Servers[GetPlatform()])[0]) { - console.log("The entire log can be accessed via the api and/or the docker log"); - const ServerStarted = BdsCore.start(); - ServerStarted.log(a => process.stdout.write(a)); - ServerStarted.exit(process.exit); - BdsCore.api(); - } else { - BdsCore.download(true, true, (err) => { - if (err) { - console.log(err); - process.exit(1); - } - StartServer(); - }); - } + (async () => { + // Check for Update + if (AllVersions[GetPlatform()] === Object.getOwnPropertyNames((await (await fetch(BdsInfo.Fetchs.servers)).json())[GetPlatform()])[0]) { + console.log("The entire log can be accessed via the api and/or the docker log"); + const ServerStarted = BdsCore.start(); + ServerStarted.log(a => process.stdout.write(a)); + ServerStarted.exit(process.exit); + BdsCore.api(); + } else { + BdsCore.download(true, true, (err) => { + if (err) { + console.log(err); + process.exit(1); + } + StartServer(); + }); + } + })(); } } else { console.log("Server is not installed, starting server implementation"); @@ -94,6 +111,7 @@ if (Object.getOwnPropertyNames(AllVersions).filter(platform => AllVersions[platf port: 19132, portv6: 19133, } + BdsCore.bds_maneger_token_register(["admin"]); BdsCore.set_config(ServerConfig); StartServer(); }); diff --git a/bin/bds_maneger.js b/bin/bds_maneger.js index 9aeb4c6..3e0fee9 100755 --- a/bin/bds_maneger.js +++ b/bin/bds_maneger.js @@ -8,10 +8,11 @@ const argv = require("minimist")(process.argv.slice(2)); if (Object.getOwnPropertyNames(argv).length <= 1) argv.help = true const bds = require("../index"); -const { valid_platform } = require("../lib/BdsSystemInfo"); +const SystemInfo = require("../lib/BdsSystemInfo"); const { bds_dir, GetServerVersion, GetPlatform, UpdatePlatform, GetServerPaths, GetPaths } = require("../lib/BdsSettings"); const commandExits = require("../lib/commandExist"); const download = require("../src/BdsServersDownload"); +const BdsConfigAndInfo = require("../BdsManegerInfo.json"); // Options const @@ -32,8 +33,8 @@ if (kill) bds.kill(); // Set Bds Platform if (server) UpdatePlatform(server); -function StartServer(){ - const { Servers } = require("../lib/ServerURL"); +async function StartServer(){ + const Servers = (await (await fetch(BdsConfigAndInfo.Fetchs.servers)).json()); // Check Server Update if (Versions[GetPlatform()] !== null) { if (Versions[GetPlatform()] !== Servers.latest[GetPlatform()]) { @@ -143,10 +144,10 @@ if (SystemCheck) { "*", "**************************************************************", "* Servers currently available:", - `* - Bedrock: ${valid_platform.bedrock}`, - `* - Java: ${valid_platform.java}`, - `* - Pocketmine-MP: ${valid_platform.pocketmine}`, - `* - JSPrismarine: ${valid_platform.jsprismarine}`, + `* - Bedrock: ${SystemInfo.valid_platform.bedrock}`, + `* - Java: ${SystemInfo.valid_platform.java}`, + `* - Pocketmine-MP: ${SystemInfo.valid_platform.pocketmine}`, + `* - JSPrismarine: ${SystemInfo.valid_platform.jsprismarine}`, "*", "**************************************************************" ]; @@ -156,38 +157,39 @@ if (SystemCheck) { // Download server if (bds_version){ - try { - if (argv.interactive) { - const LoadVersion = require("../lib/ServerURL").Servers[GetPlatform()] - const Version = Object.getOwnPropertyNames(LoadVersion) - - const StartQuestion = (Readline) => { - Readline.question("Select a version to download: ", input => { - if (Version[parseInt(input) - 1]) { - Readline.close(); - download(Version[parseInt(input) - 1], true, function(){ - if (start) return StartServer(); - console.log("Installation was successful, so start the server with the -s option"); - process.exit(0); - }) - } else { - console.log("Invalid Option"); - StartQuestion(Readline); - } - }); + (async () => { + try { + if (argv.interactive) { + const LoadVersion = (await (await fetch(BdsConfigAndInfo.Fetchs.servers)).json())[GetPlatform()] + const Version = Object.getOwnPropertyNames(LoadVersion) + + const StartQuestion = (Readline) => { + Readline.question("Select a version to download: ", input => { + if (Version[parseInt(input) - 1]) { + Readline.close(); + download(Version[parseInt(input) - 1], true, function(){ + if (start) return StartServer(); + console.log("Installation was successful, so start the server with the -s option"); + process.exit(0); + }) + } else { + console.log("Invalid Option"); + StartQuestion(Readline); + } + }); + } + + console.log(`Selected platform: ${GetPlatform()}, Total available versions: ${Version.length}`); + console.log("Option Version"); + + for (let option in Version) console.log(`${parseInt(option) + 1} -------- ${Version[option]}`); + StartQuestion(readline.createInterface({input: process.stdin,output: process.stdout})); } - - console.log(`Selected platform: ${GetPlatform()}, Total available versions: ${Version.length}`); - console.log("Option Version"); - - for (let option in Version) console.log(`${parseInt(option) + 1} -------- ${Version[option]}`); - StartQuestion(readline.createInterface({input: process.stdin,output: process.stdout})); - } - else bds.download(bds_version, true, function(){ - if (start) StartServer(); - }) - } - catch (error) {console.error(error);process.exit(165);} + else bds.download(bds_version, true, function(){ + if (start) StartServer(); + }) + } catch (error) {console.error(error);process.exit(165);} + })(); } // Start server diff --git a/bin/telegram_bot.js b/bin/telegram_bot.js index 37ff279..5073f60 100755 --- a/bin/telegram_bot.js +++ b/bin/telegram_bot.js @@ -1,11 +1,12 @@ +#!/usr/bin/env node const fs = require("fs"); const { Telegraf, Markup } = require("telegraf"); const bds = require("../index"); const { GetPlatform, GetPaths, GetTelegramToken } = require("../lib/BdsSettings"); const { GetKernel, arch, system } = require("../lib/BdsSystemInfo"); const { Detect } = require("../src/CheckKill"); -const { Servers } = require("../lib/ServerURL"); -const { CheckTelegramUser } = require("../src/UsersAndtokenChecks") +const { CheckTelegramUser } = require("../src/UsersAndtokenChecks"); +const BdsInfo = require("../BdsManegerInfo.json"); // Bot Start And Help messages const HelpAndStart = [ @@ -203,7 +204,7 @@ bot.command("download", async ctx => { ctx.reply(`Sucess install ${GetPlatform()} with version ${version}`); } else { await ctx.deleteMessage(); - const KeyboardVersion = Markup.keyboard(Object.getOwnPropertyNames(Servers[GetPlatform()]).map(version => { + const KeyboardVersion = Markup.keyboard(Object.getOwnPropertyNames((await (await fetch(BdsInfo.Fetchs.servers)).json())[GetPlatform()]).map(version => { return { text: `/download ${version}` } diff --git a/lib/BdsSettings.js b/lib/BdsSettings.js index d286ee4..75318a6 100644 --- a/lib/BdsSettings.js +++ b/lib/BdsSettings.js @@ -2,10 +2,7 @@ const { join, resolve, basename } = require("path"); const { existsSync, writeFileSync, mkdirSync, readFileSync } = require("fs"); const { homedir } = require("os"); const { valid_platform } = require("./BdsSystemInfo"); -const yaml = { - parse: require("js-yaml").load, - stringify: require("js-yaml").dump -} +const yaml = require("js-yaml"); // PATHs const home = homedir(); @@ -34,6 +31,7 @@ var Config = { platform: default_platformConfig, BackupCron: [ { + enabled: false, cron: "0 1 * * */3", Azure: false, Oracle: false, @@ -71,7 +69,6 @@ var Config = { ban: [ { username: "Steve", - telegram: true, bedrock: true, java: true, pocketmine: true, @@ -80,7 +77,6 @@ var Config = { }, { username: "Alex", - telegram: true, bedrock: true, java: true, pocketmine: true, @@ -89,7 +85,6 @@ var Config = { }, { username: "steve", - telegram: true, bedrock: true, java: true, pocketmine: true, @@ -98,7 +93,6 @@ var Config = { }, { username: "alex", - telegram: true, bedrock: true, java: true, pocketmine: true, @@ -108,17 +102,18 @@ var Config = { ], telegram: { admins: ["all_users"], + ban: ["Steve_mine_mine"], token: null } } // Config const ConfigPath = join(resolve(homedir(), "bds_core"), "BdsConfig.yaml") -function SaveConfig(){writeFileSync(ConfigPath, yaml.stringify(Config));} +function SaveConfig(){writeFileSync(ConfigPath, yaml.dump(Config));} if (existsSync(ConfigPath)) Config = { ...Config, - ...yaml.parse(readFileSync(ConfigPath, "utf8")) -}; else writeFileSync(ConfigPath, yaml.stringify(Config)) + ...yaml.load(readFileSync(ConfigPath, "utf8")) +}; else writeFileSync(ConfigPath, yaml.dump(Config)) process.on("exit", () => SaveConfig()) // Paths @@ -131,7 +126,6 @@ const ServersPaths = { bedrock: join(Config.paths.servers, "Bedrock"), java: join(Config.paths.servers, "Java"), pocketmine: join(Config.paths.servers, "Pocketmine-MP"), - jsprismarine: join(Config.paths.servers, "JSPrismarine"), dragonfly: join(Config.paths.servers, "Dragonfly_go"), spigot: join(Config.paths.servers, "Spigot") } @@ -181,9 +175,6 @@ function UpdatePlatform(platform = Config.server.platform){ } else if (/spigot/.test(platform)) { Config.server.platform = "spigot"; SaveConfig() - } else if (/jsprismarine/.test(platform)) { - Config.server.platform = "jsprismarine"; - SaveConfig() } else throw new Error("platform no Exists") return platform } diff --git a/lib/BdsSystemInfo.js b/lib/BdsSystemInfo.js index dd571ea..3fd1039 100644 --- a/lib/BdsSystemInfo.js +++ b/lib/BdsSystemInfo.js @@ -2,7 +2,11 @@ const { execSync } = require("child_process"); const { release } = require("os"); const { readdirSync } = require("fs"); const commadExist = require("./commandExist"); -const { PHPBin, Servers } = require("./ServerURL"); +const fetchSync = require("@the-bds-maneger/fetchsync"); + +// Load JSON for Server and PHP Zip files +const PHPBin = fetchSync("https://raw.githubusercontent.com/The-Bds-Maneger/Php_Static_Binary/main/binarys.json").json(), + Servers = fetchSync("https://raw.githubusercontent.com/The-Bds-Maneger/external_files/main/Server.json").json(); // System Architect (x64, aarch64 and others) var arch; diff --git a/lib/ServerURL.js b/lib/ServerURL.js deleted file mode 100644 index 7599107..0000000 --- a/lib/ServerURL.js +++ /dev/null @@ -1,5 +0,0 @@ -const fetchSync = require("@the-bds-maneger/fetchsync"); -module.exports = { - Servers: fetchSync("https://raw.githubusercontent.com/The-Bds-Maneger/external_files/main/Server.json").json(), - PHPBin: fetchSync("https://raw.githubusercontent.com/The-Bds-Maneger/Php_Static_Binary/main/binarys.json").json() -} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index bc0db4f..817e099 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@the-bds-maneger/core", - "version": "1.13.4", + "version": "1.13.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@the-bds-maneger/core", - "version": "1.13.4", + "version": "1.13.5", "license": "AGPL-3.0-or-later", "dependencies": { "@azure/storage-blob": "^12.6.0", diff --git a/package.json b/package.json index 45ab61e..4bd2878 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "Docker": "node .Build/DockerImage.js" }, "bin": { - "bds_maneger": "./bin/bds_maneger.js", - "bds_telegram": "./bin/telegram_bot.js" + "bds_maneger": "bin/bds_maneger.js", + "bds_telegram": "bin/telegram_bot.js" }, "repository": { "type": "git", diff --git a/src/BdsManegerServer.js b/src/BdsManegerServer.js index 4ae0efb..8da91b0 100644 --- a/src/BdsManegerServer.js +++ b/src/BdsManegerServer.js @@ -22,7 +22,9 @@ function start() { command: String, args: [], cwd: String, - env: process.env, + env: { + ...process.env + }, } // Minecraft Bedrock Oficial @@ -85,11 +87,17 @@ function start() { // Post Start if (GetPlatform() === "java") { - const eula_file = path.join(GetServerPaths("java"), "eula.txt"); - console.log(fs.readFileSync(eula_file, "utf8")); - if (fs.readFileSync(eula_file, "utf8").includes("eula=false")) { - fs.writeFileSync(eula_file, fs.readFileSync(eula_file, "utf8").replaceAll("eula=false", "eula=true")); - throw new Error("Restart application/CLI") + 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") } } diff --git a/src/BdsServersDownload.js b/src/BdsServersDownload.js index b569b57..845f44d 100644 --- a/src/BdsServersDownload.js +++ b/src/BdsServersDownload.js @@ -18,14 +18,9 @@ module.exports = async function (version, force_install, callback) { bds_dir_dragonfly = GetServerPaths("dragonfly"); // JSON Configs and others - const Servers = (await (await fetch(Extra.download.servers)).json()); + const Servers = (await (await fetch(Extra.Fetchs.servers)).json()); const ServerVersion = GetServerVersion(); const CurrentPlatform = GetPlatform(); - if (force_install === true) { - ServerVersion.java = "latest"; - ServerVersion.bedrock = "latest" - ServerVersion.pocketmine = "latest" - } if (!(version) || version === true || version === "true" || version === "latest") version = Servers.latest[CurrentPlatform] var url; @@ -152,7 +147,7 @@ module.exports = async function (version, force_install, callback) { async function php_download() { const bds_dir_pocketmine = GetServerPaths("pocketmine"); - const PHPBin = (await (await fetch(Extra.download.php)).json()); + const PHPBin = (await (await fetch(Extra.Fetchs.php)).json()); const phpFolder = resolve(bds_dir_pocketmine, "bin"); const phpExtensiosnsDir = resolve(bds_dir_pocketmine, "bin/php7/lib/php/extensions"); -- 2.49.0 From d999526c62dff91ea43d10259e8f45e7a52aac87 Mon Sep 17 00:00:00 2001 From: Matheus Sampaio Queiroga Date: Mon, 16 Aug 2021 22:32:04 -0300 Subject: [PATCH 2/5] CI Test --- .Build/test/ci.js | 12 ++++++------ src/BdsBackup.js | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.Build/test/ci.js b/.Build/test/ci.js index 8cd01ac..2e7d75b 100644 --- a/.Build/test/ci.js +++ b/.Build/test/ci.js @@ -2,12 +2,12 @@ try { const bds = require("../../index"); await bds.download("latest", true); - console.log("Api:", await bds.api()); - console.log("Backup:", await bds.backup()); - console.log("Detect Server:", await bds.detect()); - console.log("Kill Server:", await bds.kill()); - console.log("Get Config:", await bds.get_config()); - console.log("Start:", await bds.start()); + console.log("Api:", bds.api()); + console.log("Backup:", bds.backup()); + console.log("Detect Server:", bds.detect()); + console.log("Kill Server:", bds.kill()); + console.log("Get Config:", bds.get_config()); + console.log("Start:", bds.start()); setTimeout(() => { console.log("Kill Server:", bds.kill()); }, 1 * 30 * 1000); diff --git a/src/BdsBackup.js b/src/BdsBackup.js index 0689d42..171f627 100644 --- a/src/BdsBackup.js +++ b/src/BdsBackup.js @@ -11,7 +11,7 @@ function Backup() { bedrock: GetServerPaths("bedrock"), java: GetServerPaths("java"), pocketmine: GetServerPaths("pocketmine"), - jsprismarine: GetServerPaths("jsprismarine") + spigot: GetServerPaths("spigot"), } const CurrentDate = new Date(); const name = `Bds_Maneger_Core_Backups_${CurrentDate.getDate()}-${CurrentDate.getMonth()}-${CurrentDate.getFullYear()}.zip` -- 2.49.0 From eda836d0274732f4f1aacb9d34ad2e9bb34b1b7a Mon Sep 17 00:00:00 2001 From: Matheus Sampaio Queiroga Date: Thu, 19 Aug 2021 21:55:42 -0300 Subject: [PATCH 3/5] Actions --- .github/workflows/tag_version.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tag_version.yml b/.github/workflows/tag_version.yml index 214596f..7dea2e7 100644 --- a/.github/workflows/tag_version.yml +++ b/.github/workflows/tag_version.yml @@ -1,9 +1,8 @@ name: Npm Packages Stable and Docker Image on: - push: - tags: - - v** - - V** + release: + types: + - created env: DOCKER_ARCH: linux/amd64,linux/arm64,linux/arm/v7 @@ -11,7 +10,7 @@ env: jobs: npm: runs-on: ubuntu-latest - if: ${{ github.actor }} == ${{ github.repository_owner }} + if: ${{ github.actor }} == ${{ github.repository_owner }} && (contains('tag', ${{ github.ref }}) && contains('v', ${{ github.ref }}) || contains('V', ${{ github.ref }})) steps: - uses: actions/checkout@master - uses: actions/setup-node@v2.4.0 @@ -25,7 +24,12 @@ jobs: - name: Publish run: npm publish env: - NODE_AUTH_TOKEN: "${{ secrets.NPM_ORG_TOKEN }}" + NODE_AUTH_TOKEN: '${{ secrets.NPM_ORG_TOKEN }}' + + - name: Remove Dev Versions + run: npm run remove_dev_versions + env: + NODE_AUTH_TOKEN: '${{ secrets.NPM_ORG_TOKEN }}' docker_core: needs: [npm] -- 2.49.0 From a0cc1b6e60a4415f6c2f4a043507825123b40c68 Mon Sep 17 00:00:00 2001 From: Matheus Sampaio Queiroga Date: Thu, 19 Aug 2021 22:02:51 -0300 Subject: [PATCH 4/5] Remove Dev Package init --- .Build/RemoveVersions.js | 26 ++++ .gitignore | 3 +- package-lock.json | 292 +++++++++++++++++++++++++++++++++++++++ package.json | 4 +- 4 files changed, 323 insertions(+), 2 deletions(-) create mode 100644 .Build/RemoveVersions.js diff --git a/.Build/RemoveVersions.js b/.Build/RemoveVersions.js new file mode 100644 index 0000000..5d4f9e6 --- /dev/null +++ b/.Build/RemoveVersions.js @@ -0,0 +1,26 @@ +const child_process = require("child_process"); +const fs = require("fs"); +const path = require("path"); +const cli_color = require("cli-color"); + +// Fetch +if (typeof fetch === "undefined") global.fetch = require("node-fetch"); + +fetch("https://registry.npmjs.org/@the-bds-maneger/core").then(res => res.json()).then(data => { + data.versions = Object.getOwnPropertyNames(data.versions).filter(version => /[0-9]+\.[0-9][0-9][0-9]/.test(version) && version !== data["dist-tags"].dev && version !== data["dist-tags"].latest) + fs.writeFileSync(path.resolve(__dirname, "Releases.json"), JSON.stringify(data, null, 2)); + const Package = require("../package.json"); + data.versions.map(version => { + const cmd = `npm unpublish ${Package.name}@${version}`; + console.log(cli_color.yellow(cmd)); + try { + child_process.execSync(cmd).toString() + console.log(cli_color.green(`Sucess to remove ${Package.name}@${version}`, "\n")); + return cmd; + } catch (e) { + console.log(cli_color.red(`Failed to remove package: ${Package.name}@${version}`), "\n"); + return version; + } + }); + fs.writeFileSync(path.resolve(__dirname, "Releases.json"), JSON.stringify(data, null, 2)); +}); \ No newline at end of file diff --git a/.gitignore b/.gitignore index 99a5e25..881f58c 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,5 @@ Bds-Maneger-Core # ** .husky -Servers \ No newline at end of file +Servers +.Build/Releases.json \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index eb27053..3c188ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@the-bds-maneger/fetchsync": "github:The-Bds-Maneger/fetchSync", "adm-zip": "^0.5.1", "body-parser": "^1.19.0", + "cli-color": "^2.0.0", "cors": "^2.8.5", "cron": "^1.8.2", "express": "^4.17.1", @@ -1235,6 +1236,27 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/cli-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/cli-color/-/cli-color-2.0.0.tgz", + "integrity": "sha512-a0VZ8LeraW0jTuCkuAGMNufareGHhyZU9z8OGsW0gXd1hZGi1SRuNRXdbGkraBBKnhyUhyebFWnRbp+dIn0f0A==", + "dependencies": { + "ansi-regex": "^2.1.1", + "d": "^1.0.1", + "es5-ext": "^0.10.51", + "es6-iterator": "^2.0.3", + "memoizee": "^0.4.14", + "timers-ext": "^0.1.7" + } + }, + "node_modules/cli-color/node_modules/ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/cli-cursor": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", @@ -1449,6 +1471,15 @@ "node": ">=8" } }, + "node_modules/d": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz", + "integrity": "sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==", + "dependencies": { + "es5-ext": "^0.10.50", + "type": "^1.0.1" + } + }, "node_modules/dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -2100,11 +2131,51 @@ "node": ">=8.6" } }, + "node_modules/es5-ext": { + "version": "0.10.53", + "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.53.tgz", + "integrity": "sha512-Xs2Stw6NiNHWypzRTY1MtaG/uJlwCk8kH81920ma8mvN8Xq1gsfhZvpkImLQArw8AHnv8MT2I45J3c0R8slE+Q==", + "dependencies": { + "es6-iterator": "~2.0.3", + "es6-symbol": "~3.1.3", + "next-tick": "~1.0.0" + } + }, + "node_modules/es6-iterator": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", + "integrity": "sha1-p96IkUGgWpSwhUQDstCg+/qY87c=", + "dependencies": { + "d": "1", + "es5-ext": "^0.10.35", + "es6-symbol": "^3.1.1" + } + }, "node_modules/es6-promise": { "version": "4.2.6", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.6.tgz", "integrity": "sha512-aRVgGdnmW2OiySVPUC9e6m+plolMAJKjZnQlCwNSuK5yQ0JN61DZSO1X1Ufd1foqWRAlig0rhduTCHe7sVtK5Q==" }, + "node_modules/es6-symbol": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.3.tgz", + "integrity": "sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==", + "dependencies": { + "d": "^1.0.1", + "ext": "^1.1.2" + } + }, + "node_modules/es6-weak-map": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/es6-weak-map/-/es6-weak-map-2.0.3.tgz", + "integrity": "sha512-p5um32HOTO1kP+w7PRnB+5lQ43Z6muuMuIMffvDN8ZB4GcnjLBV6zGStpbASIMk4DCAvEaamhe2zhyCb/QXXsA==", + "dependencies": { + "d": "1", + "es5-ext": "^0.10.46", + "es6-iterator": "^2.0.3", + "es6-symbol": "^3.1.1" + } + }, "node_modules/escape-goat": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/escape-goat/-/escape-goat-2.1.1.tgz", @@ -2383,6 +2454,15 @@ "node": ">= 0.6" } }, + "node_modules/event-emitter": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", + "integrity": "sha1-34xp7vFkeSPHFXuc6DhAYQsCzDk=", + "dependencies": { + "d": "1", + "es5-ext": "~0.10.14" + } + }, "node_modules/event-target-shim": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", @@ -2460,6 +2540,14 @@ "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-5.3.0.tgz", "integrity": "sha512-qJhfEgCnmteSeZAeuOKQ2WEIFTX5ajrzE0xS6gCOBCoRQcU+xEzQmgYQQTpzCcqUAAzTEtu4YEih4pnLfvNtew==" }, + "node_modules/ext": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/ext/-/ext-1.4.0.tgz", + "integrity": "sha512-Key5NIsUxdqKg3vIsdw9dSuXpPCQ297y6wBjL30edxwPgt2E44WcWBZey/ZvUc6sERLTxKdyCu4gZFmUbk1Q7A==", + "dependencies": { + "type": "^2.0.0" + } + }, "node_modules/ext-list": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/ext-list/-/ext-list-2.2.2.tgz", @@ -2485,6 +2573,11 @@ "node": ">=4" } }, + "node_modules/ext/node_modules/type": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/type/-/type-2.5.0.tgz", + "integrity": "sha512-180WMDQaIMm3+7hGXWf12GtdniDEy7nYcyFMKJn/eZz/6tSLXrUN9V0wKSbMjej0I1WHWbpREDEKHtqPQa9NNw==" + }, "node_modules/extend": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", @@ -3408,6 +3501,11 @@ "node": ">=0.10.0" } }, + "node_modules/is-promise": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz", + "integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==" + }, "node_modules/is-retry-allowed": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/is-retry-allowed/-/is-retry-allowed-1.2.0.tgz", @@ -3823,6 +3921,14 @@ "node": ">=10" } }, + "node_modules/lru-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/lru-queue/-/lru-queue-0.1.0.tgz", + "integrity": "sha1-Jzi9nw089PhEkMVzbEhpmsYyzaM=", + "dependencies": { + "es5-ext": "~0.10.2" + } + }, "node_modules/make-dir": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz", @@ -3862,6 +3968,26 @@ "node": ">= 0.6" } }, + "node_modules/memoizee": { + "version": "0.4.15", + "resolved": "https://registry.npmjs.org/memoizee/-/memoizee-0.4.15.tgz", + "integrity": "sha512-UBWmJpLZd5STPm7PMUlOw/TSy972M+z8gcyQ5veOnSDRREz/0bmpyTfKt3/51DhEBqCZQn1udM/5flcSPYhkdQ==", + "dependencies": { + "d": "^1.0.1", + "es5-ext": "^0.10.53", + "es6-weak-map": "^2.0.3", + "event-emitter": "^0.3.5", + "is-promise": "^2.2.2", + "lru-queue": "^0.1.0", + "next-tick": "^1.1.0", + "timers-ext": "^0.1.7" + } + }, + "node_modules/memoizee/node_modules/next-tick": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", + "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" + }, "node_modules/merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", @@ -4150,6 +4276,11 @@ "node": ">=4" } }, + "node_modules/next-tick": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", + "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=" + }, "node_modules/node-cron": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/node-cron/-/node-cron-3.0.0.tgz", @@ -6571,6 +6702,15 @@ "node": ">=0.10.0" } }, + "node_modules/timers-ext": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/timers-ext/-/timers-ext-0.1.7.tgz", + "integrity": "sha512-b85NUNzTSdodShTIbky6ZF02e8STtVVfD+fu4aXXShEELpozH+bCpJLYMPZbsABN2wDH7fJpqIoXxJpzbf0NqQ==", + "dependencies": { + "es5-ext": "~0.10.46", + "next-tick": "1" + } + }, "node_modules/to-buffer": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.1.1.tgz", @@ -6682,6 +6822,11 @@ "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" }, + "node_modules/type": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz", + "integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==" + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -7961,6 +8106,26 @@ "integrity": "sha512-y4coMcylgSCdVinjiDBuR8PCC2bLjyGTwEmPb9NHR/QaNU6EUOXcTY/s6VjGMD6ENSEaeQYHCY0GNGS5jfMwPw==", "dev": true }, + "cli-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/cli-color/-/cli-color-2.0.0.tgz", + "integrity": "sha512-a0VZ8LeraW0jTuCkuAGMNufareGHhyZU9z8OGsW0gXd1hZGi1SRuNRXdbGkraBBKnhyUhyebFWnRbp+dIn0f0A==", + "requires": { + "ansi-regex": "^2.1.1", + "d": "^1.0.1", + "es5-ext": "^0.10.51", + "es6-iterator": "^2.0.3", + "memoizee": "^0.4.14", + "timers-ext": "^0.1.7" + }, + "dependencies": { + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + } + } + }, "cli-cursor": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", @@ -8129,6 +8294,15 @@ "integrity": "sha512-v1plID3y9r/lPhviJ1wrXpLeyUIGAZ2SHNYTEapm7/8A9nLPoyvVp3RK/EPFqn5kEznyWgYZNsRtYYIWbuG8KA==", "dev": true }, + "d": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz", + "integrity": "sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==", + "requires": { + "es5-ext": "^0.10.50", + "type": "^1.0.1" + } + }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -8652,11 +8826,51 @@ "ansi-colors": "^4.1.1" } }, + "es5-ext": { + "version": "0.10.53", + "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.53.tgz", + "integrity": "sha512-Xs2Stw6NiNHWypzRTY1MtaG/uJlwCk8kH81920ma8mvN8Xq1gsfhZvpkImLQArw8AHnv8MT2I45J3c0R8slE+Q==", + "requires": { + "es6-iterator": "~2.0.3", + "es6-symbol": "~3.1.3", + "next-tick": "~1.0.0" + } + }, + "es6-iterator": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", + "integrity": "sha1-p96IkUGgWpSwhUQDstCg+/qY87c=", + "requires": { + "d": "1", + "es5-ext": "^0.10.35", + "es6-symbol": "^3.1.1" + } + }, "es6-promise": { "version": "4.2.6", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.6.tgz", "integrity": "sha512-aRVgGdnmW2OiySVPUC9e6m+plolMAJKjZnQlCwNSuK5yQ0JN61DZSO1X1Ufd1foqWRAlig0rhduTCHe7sVtK5Q==" }, + "es6-symbol": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.3.tgz", + "integrity": "sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==", + "requires": { + "d": "^1.0.1", + "ext": "^1.1.2" + } + }, + "es6-weak-map": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/es6-weak-map/-/es6-weak-map-2.0.3.tgz", + "integrity": "sha512-p5um32HOTO1kP+w7PRnB+5lQ43Z6muuMuIMffvDN8ZB4GcnjLBV6zGStpbASIMk4DCAvEaamhe2zhyCb/QXXsA==", + "requires": { + "d": "1", + "es5-ext": "^0.10.46", + "es6-iterator": "^2.0.3", + "es6-symbol": "^3.1.1" + } + }, "escape-goat": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/escape-goat/-/escape-goat-2.1.1.tgz", @@ -8867,6 +9081,15 @@ "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" }, + "event-emitter": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", + "integrity": "sha1-34xp7vFkeSPHFXuc6DhAYQsCzDk=", + "requires": { + "d": "1", + "es5-ext": "~0.10.14" + } + }, "event-target-shim": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", @@ -8932,6 +9155,21 @@ "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-5.3.0.tgz", "integrity": "sha512-qJhfEgCnmteSeZAeuOKQ2WEIFTX5ajrzE0xS6gCOBCoRQcU+xEzQmgYQQTpzCcqUAAzTEtu4YEih4pnLfvNtew==" }, + "ext": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/ext/-/ext-1.4.0.tgz", + "integrity": "sha512-Key5NIsUxdqKg3vIsdw9dSuXpPCQ297y6wBjL30edxwPgt2E44WcWBZey/ZvUc6sERLTxKdyCu4gZFmUbk1Q7A==", + "requires": { + "type": "^2.0.0" + }, + "dependencies": { + "type": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/type/-/type-2.5.0.tgz", + "integrity": "sha512-180WMDQaIMm3+7hGXWf12GtdniDEy7nYcyFMKJn/eZz/6tSLXrUN9V0wKSbMjej0I1WHWbpREDEKHtqPQa9NNw==" + } + } + }, "ext-list": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/ext-list/-/ext-list-2.2.2.tgz", @@ -9646,6 +9884,11 @@ "integrity": "sha1-caUMhCnfync8kqOQpKA7OfzVHT4=", "dev": true }, + "is-promise": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz", + "integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==" + }, "is-retry-allowed": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/is-retry-allowed/-/is-retry-allowed-1.2.0.tgz", @@ -10003,6 +10246,14 @@ "yallist": "^4.0.0" } }, + "lru-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/lru-queue/-/lru-queue-0.1.0.tgz", + "integrity": "sha1-Jzi9nw089PhEkMVzbEhpmsYyzaM=", + "requires": { + "es5-ext": "~0.10.2" + } + }, "make-dir": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz", @@ -10032,6 +10283,28 @@ "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" }, + "memoizee": { + "version": "0.4.15", + "resolved": "https://registry.npmjs.org/memoizee/-/memoizee-0.4.15.tgz", + "integrity": "sha512-UBWmJpLZd5STPm7PMUlOw/TSy972M+z8gcyQ5veOnSDRREz/0bmpyTfKt3/51DhEBqCZQn1udM/5flcSPYhkdQ==", + "requires": { + "d": "^1.0.1", + "es5-ext": "^0.10.53", + "es6-weak-map": "^2.0.3", + "event-emitter": "^0.3.5", + "is-promise": "^2.2.2", + "lru-queue": "^0.1.0", + "next-tick": "^1.1.0", + "timers-ext": "^0.1.7" + }, + "dependencies": { + "next-tick": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", + "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" + } + } + }, "merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", @@ -10239,6 +10512,11 @@ } } }, + "next-tick": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", + "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=" + }, "node-cron": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/node-cron/-/node-cron-3.0.0.tgz", @@ -12259,6 +12537,15 @@ "integrity": "sha1-8y6srFoXW+ol1/q1Zas+2HQe9W8=", "dev": true }, + "timers-ext": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/timers-ext/-/timers-ext-0.1.7.tgz", + "integrity": "sha512-b85NUNzTSdodShTIbky6ZF02e8STtVVfD+fu4aXXShEELpozH+bCpJLYMPZbsABN2wDH7fJpqIoXxJpzbf0NqQ==", + "requires": { + "es5-ext": "~0.10.46", + "next-tick": "1" + } + }, "to-buffer": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.1.1.tgz", @@ -12345,6 +12632,11 @@ "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" }, + "type": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz", + "integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==" + }, "type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", diff --git a/package.json b/package.json index 4bd2878..5079c74 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "eslint": "eslint --debug .", "eslint:fix": "eslint --debug --fix .", "nexe": "node .Build/nexe_build.js", - "Docker": "node .Build/DockerImage.js" + "Docker": "node .Build/DockerImage.js", + "remove_dev_versions": "node .Build/RemoveVersions.js" }, "bin": { "bds_maneger": "bin/bds_maneger.js", @@ -56,6 +57,7 @@ "@the-bds-maneger/fetchsync": "github:The-Bds-Maneger/fetchSync", "adm-zip": "^0.5.1", "body-parser": "^1.19.0", + "cli-color": "^2.0.0", "cors": "^2.8.5", "cron": "^1.8.2", "express": "^4.17.1", -- 2.49.0 From f461866ad8780d312f3bf856facd59da70d0b262 Mon Sep 17 00:00:00 2001 From: Matheus Sampaio Queiroga Date: Thu, 19 Aug 2021 23:23:14 -0300 Subject: [PATCH 5/5] CLI --- bin/bds_maneger.js | 60 +++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/bin/bds_maneger.js b/bin/bds_maneger.js index 3e0fee9..2fc4b5d 100755 --- a/bin/bds_maneger.js +++ b/bin/bds_maneger.js @@ -1,5 +1,7 @@ #!/usr/bin/env node const readline = require("readline"); +const cli_color = require("cli-color"); +const BdsConfigAndInfo = require("../BdsManegerInfo.json"); if (process.platform === "win32") process.title = "Bds Maneger CLI"; else process.title = "Bds-Manger-CLI"; process.env.IS_BDS_CLI = process.env.IS_BIN_BDS = true; @@ -12,7 +14,6 @@ const SystemInfo = require("../lib/BdsSystemInfo"); const { bds_dir, GetServerVersion, GetPlatform, UpdatePlatform, GetServerPaths, GetPaths } = require("../lib/BdsSettings"); const commandExits = require("../lib/commandExist"); const download = require("../src/BdsServersDownload"); -const BdsConfigAndInfo = require("../BdsManegerInfo.json"); // Options const @@ -33,6 +34,7 @@ if (kill) bds.kill(); // Set Bds Platform if (server) UpdatePlatform(server); +// Start Server async function StartServer(){ const Servers = (await (await fetch(BdsConfigAndInfo.Fetchs.servers)).json()); // Check Server Update @@ -43,21 +45,24 @@ async function StartServer(){ "And we strongly recommend keeping the servers up to date, to maintain compatibility between game versions.", `At any time you can update using the options -p ${GetPlatform()} -d "${Servers.latest[GetPlatform()]}"` ] - console.log(message.join("\n")) + console.log(cli_color.yellow(message.join("\n"))); } } else if (Versions[GetPlatform()] === null) { - console.log("Install Server"); + console.log(cli_color.red("Install Server")); process.exit(1) } try { - console.log("Send a \"@stop\" command to stop the server and exit\nUse CTRL + C to force exit\n"); + console.log(cli_color.yellow("Send a \"@stop\" command to stop the server and exit\nUse CTRL + C to force exit"), "\n"); // Start Server const bds_server = bds.start(); - bds_server.log(data => process.stdout.write(data)); + bds_server.log(data => process.stdout.write(cli_color.cyan(data))); bds_server.exit(function (code){ - if (code === 3221225781 && process.platform === "win32") return open("https://docs.the-bds-maneger.org/Bds Maneger core/WindowsFixDll"); - console.log("leaving the server, status code:", code); - process.exit(code) + if (code === 3221225781 && process.platform === "win32") { + console.log(cli_color.red("Open the url: https://docs.the-bds-maneger.org/Bds Maneger core/WindowsFixDll")); + return open("https://docs.the-bds-maneger.org/Bds Maneger core/WindowsFixDll"); + } + console.log(cli_color.red(`"leaving the server, status code: ${code}"`)); + process.exit(code); }); // CLI Commands @@ -72,7 +77,7 @@ async function StartServer(){ else bds_server.command(input); }); rl.on("close", ()=>{ - console.log("CTRL + C closed readline, stopping server"); + console.log(cli_color.redBright("stopping server")); bds_server.stop(); }) bds_server.exit(function(c){ @@ -80,7 +85,7 @@ async function StartServer(){ }) bds.api(); } catch (err) { - console.log(`Bds Maneger Start Server Error: \n******\n${err}`); + console.log(cli_color.redBright(`Bds Maneger Start Server Error: \n******\n${err}`)); process.exit(2) } } @@ -100,7 +105,7 @@ if (help) { " -h --help Print this list and exit.", " -v --version Print the version and exit." ] - console.log(help.join("\n")); + console.log(cli_color.yellow(help.join("\n"))); process.exit(); } @@ -128,30 +133,37 @@ if (SystemCheck) { if (process.platform === "linux" && bds.arch !== "x64"){checkothearch = `qemu-x86_64-static is installed to emulate an x64 system: ${commandExits("qemu-x86_64-static")}\n`} if (process.platform === "android" && bds.arch !== "x64"){checkothearch = `qemu-x86_64 is installed to emulate an x64 system: ${commandExits("qemu-x86_64")}\n`} const help = [ - `Bds Maneger Core version: ${bds.package_json.version}`, - `System: ${process.platform}, architecture: ${bds.arch}`, + `Bds Maneger Core And Bds Maneger CLI version: ${cli_color.magentaBright(bds.package_json.version)}`, + `System: ${cli_color.yellow(process.platform)}, architecture: ${cli_color.blue(bds.arch)}`, checkothearch, "**************************************************************", "* Bds Maneger dirs:", - `* - Config: ${bds_dir}`, - `* - Players File: ${GetPaths("player")}`, + `* - Config: ${cli_color.yellowBright(bds_dir)}`, + `* - Players File: ${cli_color.yellowBright(GetPaths("player"))}`, "*", "* Bds Servers dirs:", - `* - Bedrock Server: ${GetServerPaths("bedrock")}`, - `* - Java Server: ${GetServerPaths("java")}`, - `* - Pocketmine-MP Server: ${GetServerPaths("pocketmine")}`, - `* - JSPrismarine Server: ${GetServerPaths("jsprismarine")}`, + `* - Bedrock Server: ${cli_color.yellowBright(GetServerPaths("bedrock"))}`, + `* - Pocketmine-MP Server: ${cli_color.yellowBright(GetServerPaths("pocketmine"))}`, + `* - Dragonfly: ${cli_color.yellowBright(GetServerPaths("dragonfly"))}`, + `* - Java Server: ${cli_color.yellowBright(GetServerPaths("java"))}`, + `* - Spigot Server: ${cli_color.yellowBright(GetServerPaths("spigot"))}`, "*", "**************************************************************", "* Servers currently available:", `* - Bedrock: ${SystemInfo.valid_platform.bedrock}`, - `* - Java: ${SystemInfo.valid_platform.java}`, `* - Pocketmine-MP: ${SystemInfo.valid_platform.pocketmine}`, - `* - JSPrismarine: ${SystemInfo.valid_platform.jsprismarine}`, + `* - Dragonfly: ${SystemInfo.valid_platform.dragonfly}`, + `* - Java: ${SystemInfo.valid_platform.java}`, + `* - Spigot: ${SystemInfo.valid_platform.java}`, "*", "**************************************************************" ]; - console.log(help.join("\n")) + console.log( + cli_color.whiteBright(help.join("\n") + .replace(/true/gi, cli_color.greenBright("true")) + .replace(/false/gi, cli_color.redBright("false")) + .replace(/undefined/gi, cli_color.red("undefined")) + )); process.exit(0) } @@ -180,9 +192,9 @@ if (bds_version){ } console.log(`Selected platform: ${GetPlatform()}, Total available versions: ${Version.length}`); - console.log("Option Version"); + console.log(`${cli_color.red("Option")} ${cli_color.green("Version")}`); - for (let option in Version) console.log(`${parseInt(option) + 1} -------- ${Version[option]}`); + for (let option in Version) console.log(`${cli_color.red(parseInt(option) + 1)}: ${cli_color.green(Version[option])}`); StartQuestion(readline.createInterface({input: process.stdin,output: process.stdout})); } else bds.download(bds_version, true, function(){ -- 2.49.0