Rewrite mocha test to Bds Maneger Core #231
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,12 +1,6 @@
|
|||||||
# Log
|
# Log
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
# test files
|
|
||||||
*.test
|
|
||||||
*test*.js*
|
|
||||||
test/
|
|
||||||
Test/
|
|
||||||
|
|
||||||
# Node
|
# Node
|
||||||
node_modules/
|
node_modules/
|
||||||
.dccache
|
.dccache
|
||||||
|
39
.test/core.js
Normal file
39
.test/core.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
const chai = require("chai");
|
||||||
|
const { assert } = chai;
|
||||||
|
const BdsCore = require("../index");
|
||||||
|
|
||||||
|
describe("Small functions", () => {
|
||||||
|
it("Detect Server is running", function (done) {
|
||||||
|
this.timeout(10000);
|
||||||
|
assert.equal(BdsCore.detect(), false);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
it("List Platforms Avaible", async function() {
|
||||||
|
this.timeout(10 * 1000);
|
||||||
|
await BdsCore.CheckSystem();
|
||||||
|
});
|
||||||
|
it("Update Platform to Java", function(done) {
|
||||||
|
BdsCore.platform_update("java");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
it("Update Platform to dragonfly", function(done) {
|
||||||
|
BdsCore.platform_update("dragonfly");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
it("Register And Delete API Token", function (done) {
|
||||||
|
const Token = BdsCore.token_register();
|
||||||
|
BdsCore.delete_token(Token);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
it("Get Server Config", function (done) {
|
||||||
|
BdsCore.get_server_config();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Slow Functions", function () {
|
||||||
|
it ("Download Server", async function () {
|
||||||
|
this.timeout(60 * 1000);
|
||||||
|
await BdsCore.download_server();
|
||||||
|
});
|
||||||
|
});
|
236
index.js
236
index.js
@ -1,188 +1,112 @@
|
|||||||
/* eslint-disable no-irregular-whitespace */
|
/* eslint-disable no-irregular-whitespace */
|
||||||
const { resolve } = require("path");
|
|
||||||
const path = require("path")
|
const path = require("path")
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const { randomUUID } = require("crypto");
|
const { randomUUID } = require("crypto");
|
||||||
const { bds_dir } = require("./lib/BdsSettings");
|
const { bds_dir } = require("./lib/BdsSettings");
|
||||||
|
|
||||||
require("./lib/Requests")
|
// Bds Maneger Core Package JSON File
|
||||||
|
module.exports.package_path = path.resolve(__dirname, "package.json");
|
||||||
const bds_core_package = resolve(__dirname, "package.json")
|
|
||||||
module.exports.package_path = bds_core_package
|
|
||||||
module.exports.package_json = require("./package.json");
|
module.exports.package_json = require("./package.json");
|
||||||
module.exports.extra_json = require("./BdsManegerInfo.json");
|
module.exports.extra_json = require("./BdsManegerInfo.json");
|
||||||
|
module.exports.BdsCoreVersion = module.exports.package_json.version;
|
||||||
|
|
||||||
// Inport and Export Arch
|
// Inport and Export Arch
|
||||||
const { arch } = require("./lib/BdsSystemInfo");
|
const { arch } = require("./lib/BdsSystemInfo");
|
||||||
module.exports.arch = arch
|
module.exports.arch = arch
|
||||||
|
|
||||||
|
// Core Settings
|
||||||
const { GetJsonConfig, UpdatePlatform, UpdateTelegramToken } = require("./lib/BdsSettings");
|
const { GetJsonConfig, UpdatePlatform, UpdateTelegramToken } = require("./lib/BdsSettings");
|
||||||
|
module.exports.getBdsConfig = GetJsonConfig;
|
||||||
|
module.exports.change_platform = UpdatePlatform;
|
||||||
|
module.exports.platform_update = UpdatePlatform;
|
||||||
|
module.exports.telegram_token_save = UpdateTelegramToken;
|
||||||
|
|
||||||
|
// Platforms Checkers
|
||||||
|
const { CheckSystemAsync, GetKernel } = require("./lib/BdsSystemInfo");
|
||||||
|
module.exports.CheckSystem = CheckSystemAsync;
|
||||||
|
module.exports.GetKernel = GetKernel;
|
||||||
|
|
||||||
// Bds Maneger Core Network
|
// Bds Maneger Core Network
|
||||||
const maneger_ips = require("./src/BdsNetwork")
|
const BdsNetwork = require("./src/BdsNetwork")
|
||||||
module.exports.internal_ip = maneger_ips.internal_ip
|
module.exports.internal_ip = BdsNetwork.LocalInterfaces;
|
||||||
module.exports.external_ip = maneger_ips.external_ip
|
module.exports.external_ip = BdsNetwork.GetExternalPublicAddress;
|
||||||
module.exports.tmphost = {
|
|
||||||
host: maneger_ips.host,
|
|
||||||
Response: maneger_ips.HostResponse
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get Old Method Config
|
// Bds Maneger Core API
|
||||||
module.exports.getBdsConfig = GetJsonConfig;
|
const BdsManegerAPI = require("./src/api/api");
|
||||||
|
module.exports.api = BdsManegerAPI;
|
||||||
/**
|
module.exports.BdsManegerAPI = BdsManegerAPI;
|
||||||
* Update Current Platform
|
|
||||||
*/
|
|
||||||
module.exports.change_platform = module.exports.platform_update = UpdatePlatform;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save Telegram token in Settings File
|
|
||||||
*/
|
|
||||||
module.exports.telegram_token_save = UpdateTelegramToken
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Bds Maneger Core Internal API REST
|
|
||||||
*
|
|
||||||
* @param {number} port - The port number, default is 1932
|
|
||||||
*
|
|
||||||
* @param {function} callback - The callback function after start API
|
|
||||||
*/
|
|
||||||
module.exports.api = require("./src/api/api");
|
|
||||||
|
|
||||||
|
// Bds Maneger Core API token Register
|
||||||
|
const path_tokens = path.join(bds_dir, "bds_tokens.json");
|
||||||
function token_register(Admin_Scoper = ["web_admin", "admin"]) {
|
function token_register(Admin_Scoper = ["web_admin", "admin"]) {
|
||||||
Admin_Scoper = Array.from(Admin_Scoper).filter(scoper => /admin/.test(scoper));
|
Admin_Scoper = Array.from(Admin_Scoper).filter(scoper => /admin/.test(scoper));
|
||||||
const bds_token_path = path.join(bds_dir, "bds_tokens.json");
|
let tokens = [];
|
||||||
let tokens = [];
|
if (fs.existsSync(path_tokens)) tokens = JSON.parse(fs.readFileSync(path_tokens, "utf8"));
|
||||||
if (fs.existsSync(bds_token_path)) tokens = JSON.parse(fs.readFileSync(bds_token_path, "utf8"));
|
// Get UUID
|
||||||
|
const getBdsUUId = randomUUID().split("-");
|
||||||
// Get UUID
|
const bdsuid = "bds_" + (getBdsUUId[0]+getBdsUUId[2].slice(0, 15));
|
||||||
const getBdsUUId = randomUUID().split("-");
|
// Save BdsUUID
|
||||||
const bdsuid = "bds_" + (getBdsUUId[0]+getBdsUUId[2].slice(0, 15));
|
tokens.push({
|
||||||
|
token: bdsuid,
|
||||||
// Save BdsUUID
|
date: new Date(),
|
||||||
tokens.push({
|
scopers: Admin_Scoper
|
||||||
token: bdsuid,
|
});
|
||||||
date: new Date(),
|
fs.writeFileSync(path_tokens, JSON.stringify(tokens, null, 4), "utf8");
|
||||||
scopers: Admin_Scoper
|
return bdsuid;
|
||||||
});
|
|
||||||
fs.writeFileSync(bds_token_path, JSON.stringify(tokens, null, 4), "utf8");
|
|
||||||
console.log(`Bds Maneger API REST token: "${bdsuid}"`);
|
|
||||||
return bdsuid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const path_tokens = path.join(bds_dir, "bds_tokens.json")
|
// Bds Maneger Core API Delet token
|
||||||
|
function delete_token(Token = "") {
|
||||||
|
if (!Token) return false;
|
||||||
|
if (typeof Token !== "string") return false;
|
||||||
|
let tokens = [];
|
||||||
|
if (fs.existsSync(path_tokens)) tokens = JSON.parse(fs.readFileSync(path_tokens, "utf8"));
|
||||||
|
if (tokens.filter(token => token.token === Token).length > 0) {
|
||||||
|
fs.writeFileSync(path_tokens, JSON.stringify(tokens, null, 4), "utf8");
|
||||||
|
return true;
|
||||||
|
} else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check Exists Tokens Files
|
||||||
if (!(fs.existsSync(path_tokens))) token_register();
|
if (!(fs.existsSync(path_tokens))) token_register();
|
||||||
|
|
||||||
/**
|
// Server Settings
|
||||||
* Register tokens to use in Bds Maneger REST and other supported applications
|
module.exports.token_register = token_register;
|
||||||
*
|
module.exports.bds_maneger_token_register = token_register;
|
||||||
* @example token_register()
|
module.exports.delete_token = delete_token;
|
||||||
*/
|
module.exports.bds_maneger_delete_token = delete_token;
|
||||||
module.exports.token_register = token_register
|
|
||||||
|
|
||||||
/**
|
// Bds Maneger Settings
|
||||||
* Register tokens to use in Bds Maneger REST and other supported applications
|
|
||||||
*
|
|
||||||
* @example token_register()
|
|
||||||
*/
|
|
||||||
module.exports.bds_maneger_token_register = token_register
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update, Get and more to Modifications Bds Settings File
|
|
||||||
*/
|
|
||||||
module.exports.BdsSettigs = require("./lib/BdsSettings");
|
module.exports.BdsSettigs = require("./lib/BdsSettings");
|
||||||
|
|
||||||
// Requires
|
// Bds Maneger Core Backups
|
||||||
const { World_BAckup } = require("./src/BdsBackup");
|
const { World_BAckup } = require("./src/BdsBackup");
|
||||||
|
module.exports.backup = World_BAckup;
|
||||||
|
module.exports.core_backup = World_BAckup;
|
||||||
|
|
||||||
|
// Server Settings
|
||||||
const { config, get_config } = require("./src/ServerSettings");
|
const { config, get_config } = require("./src/ServerSettings");
|
||||||
|
module.exports.set_config = config;
|
||||||
|
module.exports.update_config = config;
|
||||||
|
module.exports.get_config = get_config;
|
||||||
|
module.exports.server_config = get_config;
|
||||||
|
module.exports.get_server_config = get_config;
|
||||||
|
|
||||||
|
// Dowloand Server
|
||||||
const download = require("./src/BdsServersDownload");
|
const download = require("./src/BdsServersDownload");
|
||||||
const { start, stop, BdsCommand, CronBackups } = require("./src/BdsManegerServer")
|
module.exports.download = download;
|
||||||
|
module.exports.download_server = download;
|
||||||
|
|
||||||
/**
|
// Bds Maneger Core Server
|
||||||
* sending commands more simply to the server
|
const { start, stop, BdsCommand } = require("./src/BdsManegerServer")
|
||||||
*
|
module.exports.command = BdsCommand;
|
||||||
* @example bds.command("say hello from Bds Maneger")
|
module.exports.server_command = BdsCommand;
|
||||||
*/
|
module.exports.start = start;
|
||||||
module.exports.command = BdsCommand
|
module.exports.stop = stop;
|
||||||
// New management method
|
|
||||||
|
|
||||||
// Start Server
|
|
||||||
/**
|
|
||||||
* to start the server here in the sera script with child_process, then you will have to use the return function for your log custumization or anything else
|
|
||||||
*
|
|
||||||
* @example const server = bds.start();
|
|
||||||
* server.log(function (log){console.log(log)})
|
|
||||||
*/
|
|
||||||
module.exports.start = start
|
|
||||||
|
|
||||||
// Stop Server
|
|
||||||
/**
|
|
||||||
* use this command for the server, that's all
|
|
||||||
*/
|
|
||||||
module.exports.stop = stop
|
|
||||||
|
|
||||||
// Create Backup of Bds Maneger Core and Servers along with your maps and settings
|
|
||||||
/**
|
|
||||||
* backup your map locally
|
|
||||||
*/
|
|
||||||
module.exports.backup = World_BAckup
|
|
||||||
|
|
||||||
|
// Process Manager Kill and Detect Server
|
||||||
const { Kill, Detect } = require("./src/CheckKill")
|
const { Kill, Detect } = require("./src/CheckKill")
|
||||||
|
module.exports.detect = Detect;
|
||||||
/**
|
module.exports.bds_detect = Detect;
|
||||||
* identify if there are any servers running in the background
|
module.exports.detect_server = Detect;
|
||||||
*
|
module.exports.kill = Kill;
|
||||||
* @example bds.detect()
|
|
||||||
* true: if the server is running
|
|
||||||
* false: if not already
|
|
||||||
*/
|
|
||||||
module.exports.detect = Detect
|
|
||||||
module.exports.bds_detect = Detect
|
|
||||||
|
|
||||||
/**
|
|
||||||
* this function will be used to kill the server in the background
|
|
||||||
*/
|
|
||||||
module.exports.kill = Kill
|
|
||||||
|
|
||||||
/**
|
|
||||||
* download some version of the java and Bedrock servers in the highest possible form
|
|
||||||
*
|
|
||||||
* use download( version, boolean ) // the boolean is for if you want to force the installation of the server
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* bedrock: download("1.16.201.02")
|
|
||||||
*
|
|
||||||
* java: download("1.16.5")
|
|
||||||
*
|
|
||||||
* any platform: download("latest") || download(true) // It will download the latest version available for download
|
|
||||||
*/
|
|
||||||
module.exports.download = download
|
|
||||||
|
|
||||||
/**
|
|
||||||
* use this command to modify server settings
|
|
||||||
*
|
|
||||||
* @example set_config({
|
|
||||||
world: "Bds Maneger",
|
|
||||||
description: "The Bds Maneger",
|
|
||||||
gamemode: "creative",
|
|
||||||
difficulty: "normal",
|
|
||||||
players: 10,
|
|
||||||
commands: true,
|
|
||||||
account: true,
|
|
||||||
whitelist: true,
|
|
||||||
port: 19132,
|
|
||||||
portv6: 19133,
|
|
||||||
seed: ""
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
module.exports.set_config = config
|
|
||||||
|
|
||||||
/**
|
|
||||||
* takes the server settings in JSON format
|
|
||||||
*/
|
|
||||||
module.exports.get_config = get_config
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load Crontab Backup
|
|
||||||
*/
|
|
||||||
module.exports.Cron_Loaded = CronBackups;
|
|
||||||
|
831
package-lock.json
generated
831
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -11,7 +11,7 @@
|
|||||||
"start": "node bin/bds_maneger.js -s",
|
"start": "node bin/bds_maneger.js -s",
|
||||||
"start:telegram": "node bin/telegram_bot.js -e js",
|
"start:telegram": "node bin/telegram_bot.js -e js",
|
||||||
"stop": "node -p 'console.log(require(\"./\").kill());'",
|
"stop": "node -p 'console.log(require(\"./\").kill());'",
|
||||||
"test": "node .Build/test/ci.js",
|
"test": "mocha .test/*.js",
|
||||||
"ci": "node .Build/test/ci.js",
|
"ci": "node .Build/test/ci.js",
|
||||||
"eslint": "eslint --debug .",
|
"eslint": "eslint --debug .",
|
||||||
"eslint:fix": "eslint --debug --fix .",
|
"eslint:fix": "eslint --debug --fix .",
|
||||||
@ -81,7 +81,9 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@actions/core": "^1.5.0",
|
"@actions/core": "^1.5.0",
|
||||||
|
"chai": "^4.3.4",
|
||||||
"eslint": "^8.0.0",
|
"eslint": "^8.0.0",
|
||||||
|
"mocha": "^9.1.3",
|
||||||
"nodemon": "^2.0.12",
|
"nodemon": "^2.0.12",
|
||||||
"os-tmpdir": "^2.0.0"
|
"os-tmpdir": "^2.0.0"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user