UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

94 lines (93 loc) 2.9 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ToolCommandContextFactory = void 0; const Log_1 = __importDefault(require("../../core/Log")); /** * Factory to create ToolCommandContext from various sources. */ class ToolCommandContextFactory { /** * Create a minimal context for commands that don't need a project. */ static createMinimal(creatorTools, output) { return { creatorTools, output, scope: "ui", }; } /** * Create a context with a project. */ static createWithProject(creatorTools, project, output) { return { creatorTools, project, output, scope: "ui", }; } /** * Create a context for serve mode with Minecraft connection. */ static createServeContext(creatorTools, project, minecraft, output) { return { creatorTools, project, minecraft, output, scope: "serveTerminal", }; } /** * Create a context for MCP or HTTP API with session support. */ static createSessionContext(creatorTools, session, minecraft, output, scope) { return { creatorTools, session, minecraft, output, scope, }; } /** * Create a context with a ServerManager for BDS lifecycle operations. * Used when the caller has a ServerManager (e.g., Electron app, serve mode, tests). */ static createWithServer(creatorTools, serverManager, output, scope = "ui", options) { return { creatorTools, project: options?.project, session: { sessionName: options?.sessionName || "default", serverManager, slot: options?.slot ?? 0, }, output, scope, }; } /** * Create a console-based output writer for terminal use. */ static createConsoleOutput() { return { info: (msg) => Log_1.default.message(msg), success: (msg) => Log_1.default.message(`✓ ${msg}`), warn: (msg) => Log_1.default.debug(`⚠ ${msg}`), error: (msg) => Log_1.default.error(msg), debug: (msg) => Log_1.default.verbose(` ${msg}`), progress: (current, total, msg) => { const pct = Math.round((current / total) * 100); Log_1.default.message(`[${pct}%] ${msg || ""}`); }, }; } } exports.ToolCommandContextFactory = ToolCommandContextFactory;