Update server platforms to v2 paths #465
10
example/pocketmine.ts
Normal file
10
example/pocketmine.ts
Normal 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));
|
@@ -50,6 +50,7 @@ export type actionCallback = actionsPlayer|actionsPort|actionsServerStarted|acti
|
|||||||
export type actionConfig = actionCallback|actionRun|actionPlugin|actionHooks;
|
export type actionConfig = actionCallback|actionRun|actionPlugin|actionHooks;
|
||||||
|
|
||||||
export declare interface actions {
|
export declare interface actions {
|
||||||
|
on(act: "error", fn: (data: any) => void): this;
|
||||||
on(act: "playerConnect"|"playerDisconnect"|"playerUnknown", fn: (data: playerBase) => void): this;
|
on(act: "playerConnect"|"playerDisconnect"|"playerUnknown", fn: (data: playerBase) => void): this;
|
||||||
on(act: "portListening", fn: (data: portListen) => void): this;
|
on(act: "portListening", fn: (data: portListen) => void): this;
|
||||||
on(act: "serverStarted", fn: (data: serverStarted) => void): this;
|
on(act: "serverStarted", fn: (data: serverStarted) => void): this;
|
||||||
|
@@ -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"));
|
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
|
// Create folder if not exists
|
||||||
const serverRoot = path.join(bdsRoot, platform, options.id);
|
const serverRoot = path.join(bdsRoot, platform, options.id);
|
||||||
if (!(await exists(serverRoot))) await fs.mkdir(serverRoot, {recursive: true});
|
if (!(await exists(serverRoot))) await fs.mkdir(serverRoot, {recursive: true});
|
||||||
const serverPath = path.join(serverRoot, "server");
|
const serverPath = path.join(serverRoot, "server");
|
||||||
|
|
||||||
if (!(await exists(serverPath))) await fs.mkdir(serverPath, {recursive: true});
|
if (!(await exists(serverPath))) await fs.mkdir(serverPath, {recursive: true});
|
||||||
const hooksPath = path.join(serverRoot, "hooks");
|
const hooksPath = path.join(serverRoot, "hooks");
|
||||||
|
|
||||||
if (!(await exists(hooksPath))) await fs.mkdir(hooksPath, {recursive: true});
|
if (!(await exists(hooksPath))) await fs.mkdir(hooksPath, {recursive: true});
|
||||||
const backupPath = path.join(serverRoot, "backup");
|
const backupPath = path.join(serverRoot, "backup");
|
||||||
|
|
||||||
if (!(await exists(backupPath))) await fs.mkdir(backupPath, {recursive: true});
|
if (!(await exists(backupPath))) await fs.mkdir(backupPath, {recursive: true});
|
||||||
const logsPath = path.join(serverRoot, "logs");
|
const logsPath = path.join(serverRoot, "logs");
|
||||||
|
|
||||||
if (!(await exists(logsPath))) await fs.mkdir(logsPath, {recursive: true});
|
if (!(await exists(logsPath))) await fs.mkdir(logsPath, {recursive: true});
|
||||||
let buildFolder: string;
|
let buildFolder: string;
|
||||||
|
|
||||||
if (options?.withBuildFolder) {
|
if (options?.withBuildFolder) {
|
||||||
const buildFolder = path.join(serverRoot, "build");
|
buildFolder = path.join(serverRoot, "build");
|
||||||
if (!(await exists(buildFolder))) await fs.mkdir(buildFolder, {recursive: true});
|
if (!(await exists(buildFolder))) await fs.mkdir(buildFolder, {recursive: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -108,7 +108,7 @@ export async function installServer(version: string|boolean, platformOptions: bd
|
|||||||
const { serverPath } = await pathControl("pocketmine", platformOptions);
|
const { serverPath } = await pathControl("pocketmine", platformOptions);
|
||||||
await installPhp(serverPath);
|
await installPhp(serverPath);
|
||||||
const info = await platformManeger.pocketmine.find(version);
|
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;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user