@feflow/cli
Version:
A front-end flow tool.
54 lines • 1.86 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var abbrev_1 = __importDefault(require("abbrev"));
var Commander = /** @class */ (function () {
function Commander(onRegistered) {
this.store = {};
this.invisibleStore = {};
this.alias = {};
if (typeof onRegistered === 'function')
this.onRegistered = onRegistered;
}
Commander.prototype.get = function (cmdName) {
if (Object.prototype.toString.call(cmdName) !== '[object String]') {
return;
}
var finalName = cmdName.toLowerCase();
var invisibleCommand = this.invisibleStore[finalName];
if (invisibleCommand) {
return invisibleCommand;
}
return this.store[this.alias[finalName]];
};
Commander.prototype.list = function () {
return this.store;
};
Commander.prototype.register = function (cmdName, desc, fn, options, pluginName) {
var storeKey = cmdName.toLowerCase();
this.store[storeKey] = {
runFn: fn,
desc: desc,
options: options,
pluginName: pluginName,
};
this.alias = (0, abbrev_1.default)(Object.keys(this.store));
if (this.onRegistered) {
this.onRegistered(storeKey);
}
};
Commander.prototype.registerInvisible = function (cmdName, fn, options, pluginName) {
var storeKey = cmdName.toLowerCase();
this.invisibleStore[storeKey] = {
runFn: fn,
desc: '',
options: options,
pluginName: pluginName,
};
};
return Commander;
}());
exports.default = Commander;
//# sourceMappingURL=index.js.map