UNPKG

quicksilver-cli

Version:
52 lines (51 loc) 2.19 kB
"use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = require("./command"); const path = __importStar(require("path")); const fs = __importStar(require("fs")); const extensionName = ".js"; exports.commands = fs.readdirSync(__dirname) .filter(fileName => new RegExp(`\\${extensionName}`).test(fileName)) .map(file => path.basename(file, extensionName)) .map(p => Object.values(require(`./${p}`))) .reduce((accumulator, current) => accumulator.concat(current), []) .filter(item => Object.getPrototypeOf(item) == command_1.Command) .map(item => item); exports.commandNames = exports.commands.map(command => getName(command)); exports.commandMap = exports.commands.reduce((accumulator, current) => { accumulator[getName(current)] = current; return accumulator; }, {}); function getCommand(commandNameOrAlias) { return exports.commands.filter(command => getName(command) === commandNameOrAlias || getAlias(command).includes(commandNameOrAlias))[0]; } exports.getCommand = getCommand; function isCommand(commandNameOrAlias, command) { return getName(command) === commandNameOrAlias || getAlias(command).includes(commandNameOrAlias); } exports.isCommand = isCommand; function getName(command) { return Reflect.get(command, "NAME"); } exports.getName = getName; function getAlias(command) { return Reflect.get(command, "ALIAS"); } exports.getAlias = getAlias; function getAliasReduce(command) { const alias = getAlias(command); return alias == null || alias.length == 0 ? "" : `(${alias.join(", ")})`; } exports.getAliasReduce = getAliasReduce; function getFields(command) { return Reflect.get(command, "FIELDS"); } exports.getFields = getFields; function getDescription(command) { return Reflect.get(command, "DESCRIPTION"); } exports.getDescription = getDescription;