UNPKG

bedrock-development

Version:

APIs for creating and editing files related to Minecraft Bedrock development.

54 lines (53 loc) 2.77 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var _a; import { chalk } from "../../utils.js"; import { MinecraftWorld } from "../../types/index.js"; import { Option } from "commander"; import { createInterface } from "readline"; import { CommandMap } from "../command_map.js"; CommandMap.addCommand("root.world.export", { parent: (_a = CommandMap.getCommandEntry("root.world")) === null || _a === void 0 ? void 0 : _a.command, commandOptions(command) { command .name("export") .description("export selected world as .mcworld or .mctemplate") .option("-w --world <name|index>", "the name or index of the world to add packs to") .option("-p, --packs", "package the world's behavior and resource packs") .addOption(new Option("-t, --type <export type>", "what format should be exported").default("world").choices(["world", "template"])); }, commandAction: triggerWorldsExport, }); function triggerWorldsExport(options) { return __awaiter(this, void 0, void 0, function* () { const worlds = MinecraftWorld.getAllWorlds(); if (!options.world) { yield new Promise(resolve => { const readline = createInterface({ input: process.stdin, output: process.stdout }); const worldOptions = worlds.map((world, index) => `[${index}] ${chalk.green(`${world.Name}`)}`); readline.question(`Select World \n${worldOptions.join('\n')}\nIndex or Name: `, (selection) => { options.world = selection; readline.close(); resolve(); }); }); } const selectedWorld = worlds.find((worldOption, index) => index === Number(options.world) || worldOption.Name === options.world); if (selectedWorld) { yield selectedWorld.exportWorld(options.packs, options.type); } else { console.error(`${chalk.red(`${options.world} does not match the any names or indices in the world list`)}`); } }); }