Update server platforms to v2 paths #465

Merged
Sirherobrine23 merged 4 commits from multi-server-installs into main 2022-09-27 23:29:33 +00:00
4 changed files with 21 additions and 2 deletions
Showing only changes of commit 3cdbb81aad - Show all commits

10
example/pocketmine.ts Normal file
View File

@@ -0,0 +1,10 @@
import { installServer, startServer } from "../src/pocketmine";
(async function(){
await installServer("latest");
const serverManeger = await startServer();
serverManeger.on("log", console.log);
serverManeger.on("portListening", console.log);
serverManeger.on("serverStarted", () => serverManeger.stopServer());
return serverManeger.waitExit();
})().catch(err => console.trace(err));

View File

@@ -50,6 +50,7 @@ export type actionCallback = actionsPlayer|actionsPort|actionsServerStarted|acti
export type actionConfig = actionCallback|actionRun|actionPlugin|actionHooks;
export declare interface actions {
on(act: "error", fn: (data: any) => void): this;
on(act: "playerConnect"|"playerDisconnect"|"playerUnknown", fn: (data: playerBase) => void): this;
on(act: "portListening", fn: (data: portListen) => void): this;
on(act: "serverStarted", fn: (data: serverStarted) => void): this;

View File

@@ -45,20 +45,28 @@ export async function pathControl(platform: bdsPlatform, options?: bdsPlatformOp
await fs.symlink(path.join(bdsRoot, platform, options.id), path.join(bdsRoot, platform, "default"));
}
// Get real id
if (options?.id === "default") options.id = path.basename(await fs.realpath(path.join(bdsRoot, platform, options.id)));
// Create folder if not exists
const serverRoot = path.join(bdsRoot, platform, options.id);
if (!(await exists(serverRoot))) await fs.mkdir(serverRoot, {recursive: true});
const serverPath = path.join(serverRoot, "server");
if (!(await exists(serverPath))) await fs.mkdir(serverPath, {recursive: true});
const hooksPath = path.join(serverRoot, "hooks");
if (!(await exists(hooksPath))) await fs.mkdir(hooksPath, {recursive: true});
const backupPath = path.join(serverRoot, "backup");
if (!(await exists(backupPath))) await fs.mkdir(backupPath, {recursive: true});
const logsPath = path.join(serverRoot, "logs");
if (!(await exists(logsPath))) await fs.mkdir(logsPath, {recursive: true});
let buildFolder: string;
if (options?.withBuildFolder) {
const buildFolder = path.join(serverRoot, "build");
buildFolder = path.join(serverRoot, "build");
if (!(await exists(buildFolder))) await fs.mkdir(buildFolder, {recursive: true});
}

View File

@@ -108,7 +108,7 @@ export async function installServer(version: string|boolean, platformOptions: bd
const { serverPath } = await pathControl("pocketmine", platformOptions);
await installPhp(serverPath);
const info = await platformManeger.pocketmine.find(version);
await saveFile(info?.url, {filePath: path.join(serverPath, "")});
await saveFile(info?.url, {filePath: path.join(serverPath, "pocketmine.phar")});
return info;
}