UNPKG

mongoose-management

Version:
47 lines (46 loc) 2.28 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(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 }); const chalk_1 = __importDefault(require("chalk")); const inquirer_1 = require("inquirer"); const abstract_1 = __importDefault(require("./abstract")); class GroupMenu extends abstract_1.default { exec(group) { return __awaiter(this, void 0, void 0, function* () { const choices = this.getChoiceList(group.getCollections()); if (choices.length === 0) { choices.push(new inquirer_1.Separator('- No collections defined -')); } const result = yield this.prompts.menu('Choose a collection or a command:', [ new inquirer_1.Separator(`Group: ${chalk_1.default.bold(group.getPath())}`), new inquirer_1.Separator(' '), new inquirer_1.Separator('Collections list'), new inquirer_1.Separator(' '), ...choices, new inquirer_1.Separator(' '), new inquirer_1.Separator(), this.getMenuChoiceCreate('collection'), this.getMenuChoiceRemove('group'), this.getMenuChoiceSave(), this.getMenuChoiceWrite(), this.getMenuChoiceBack(), new inquirer_1.Separator(' '), ]); return result; }); } getChoiceList(collections) { return collections.map((d) => ({ name: d.getName(), value: { data: d }, short: d.getName() })); } } exports.default = GroupMenu;