UNPKG

papermc-api

Version:

Its a PaperMC Downloads API client for node.js.

99 lines (98 loc) 4.54 kB
"use strict"; 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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DownloadCommand = void 0; const chalk_1 = __importDefault(require("chalk")); const commander_1 = require("commander"); const inquirer_1 = __importDefault(require("inquirer")); const PaperAPI_1 = require("../../class/PaperAPI"); const downloadBuild_1 = require("../util/downloadBuild"); let cmd = new commander_1.Command("download") .argument("<project>", "It's field must be a project ID or in this format <paperProject>@<version>-[build] (The build field is optional). Example: paper@1.19.2") .option("-P, --path <path>", "Set the path where the Jar is downloaded.") .description("Downloads PaperMC project application. ") .action((proj_id, opts) => __awaiter(void 0, void 0, void 0, function* () { let map = proj_id.split("@"); if (map.length > 1) { let mapP = map[1].split("-"); let versId = mapP[0]; let proj = yield PaperAPI_1.PaperAPI.project(map[0]); if (!proj) { console.log(chalk_1.default.red(`${proj_id} is invalid project ID.`)); return; } console.log("Project Name: " + chalk_1.default.blue(proj.project_name)); let vers = yield proj.getVersion(versId); if (!vers) { console.log(chalk_1.default.red(`An exception occurred while trying to get version ${versId} information.`)); return; } console.log("Project Version: " + chalk_1.default.blue(vers.version)); let buildId = vers.builds[vers.builds.length - 1]; if (typeof mapP[1] != 'undefined') { buildId = mapP[1]; } let buld = yield vers.getBuild(buildId); if (!buld) { console.log(chalk_1.default.red(`An exception occurred while trying to get ${buildId} build information.`)); return; } console.log("Project Build: " + chalk_1.default.blue(buld.build)); (0, downloadBuild_1.DownloadBuild)(buld, opts.path); return; } let project = yield PaperAPI_1.PaperAPI.project(proj_id); if (!project) { console.log(chalk_1.default.red(`${proj_id} is invalid project ID.`)); return; } const prompt = inquirer_1.default.createPromptModule(); let ans = yield prompt({ type: "list", name: "version_selector", message: "Select the version you want", choices: project.versions, default: project.versions[project.versions.length - 1] }); let vers = yield project.getVersion(ans.version_selector); if (!vers) { console.log(chalk_1.default.red(`An exception occurred while trying to get version ${ans.version_selector} information.`)); return; } let ans2 = yield prompt({ name: "sb", message: "You want to select the build of this version.", type: "confirm", default: false }); let bv = "latest"; if (ans2.sb) { let anx = yield prompt({ type: "list", name: "build_select", message: "Select the build you want", choices: vers.builds, default: vers.builds[vers.builds.length - 1] }); bv = anx.build_select; } let build = yield vers.getBuild(bv); if (!build) { console.log(chalk_1.default.red(`An exception occurred while trying to get ${bv} build information.`)); return; } console.log(chalk_1.default.greenBright("Downloading in current working directory.")); (0, downloadBuild_1.DownloadBuild)(build, opts.path); })); exports.DownloadCommand = cmd;