1 | "use strict";
|
2 | var _this = this;
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | var tslib_1 = require("tslib");
|
5 | var command_1 = require("./command");
|
6 | var common_1 = require("./common");
|
7 | function toCommand(modulePath) {
|
8 | var m = require(modulePath);
|
9 | var name;
|
10 | name = m.name ? m.name : common_1.fsPath.basename(modulePath, '.js');
|
11 | name = name.endsWith('.cmd') ? common_1.fsPath.basename(name, '.cmd') : name;
|
12 | var alias = m.alias;
|
13 | if (!common_1.R.is(Array, alias)) {
|
14 | alias = [alias];
|
15 | }
|
16 | alias = common_1.R.reject(common_1.R.isNil)(alias);
|
17 | var action = m.cmd || m.default;
|
18 | return {
|
19 | name: name,
|
20 | alias: alias,
|
21 | description: m.description,
|
22 | group: m.group,
|
23 | args: m.args,
|
24 | validate: m.validate,
|
25 | action: action,
|
26 | };
|
27 | }
|
28 | function toCommands(modulePaths) {
|
29 | var commands = modulePaths
|
30 | .map(toCommand)
|
31 | .filter(function (item) { return common_1.R.is(Function, item.action); });
|
32 | var result = {};
|
33 | commands.forEach(function (cmd) { return (result[cmd.name] = cmd); });
|
34 | return result;
|
35 | }
|
36 | function pathToCommands(path) {
|
37 | return tslib_1.__awaiter(this, void 0, void 0, function () {
|
38 | var paths;
|
39 | return tslib_1.__generator(this, function (_a) {
|
40 | switch (_a.label) {
|
41 | case 0: return [4, common_1.file.glob(path)];
|
42 | case 1:
|
43 | paths = _a.sent();
|
44 | return [2, toCommands(paths)];
|
45 | }
|
46 | });
|
47 | });
|
48 | }
|
49 | exports.default = (function (param) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
50 | var out, _i, param_1, path, _a;
|
51 | return tslib_1.__generator(this, function (_b) {
|
52 | switch (_b.label) {
|
53 | case 0:
|
54 | if (!(typeof param === 'string')) return [3, 2];
|
55 | return [4, pathToCommands(param)];
|
56 | case 1:
|
57 | param = _b.sent();
|
58 | _b.label = 2;
|
59 | case 2:
|
60 | if (!Array.isArray(param)) return [3, 7];
|
61 | out = {};
|
62 | _i = 0, param_1 = param;
|
63 | _b.label = 3;
|
64 | case 3:
|
65 | if (!(_i < param_1.length)) return [3, 6];
|
66 | path = param_1[_i];
|
67 | _a = [{}, out];
|
68 | return [4, pathToCommands(path)];
|
69 | case 4:
|
70 | out = tslib_1.__assign.apply(void 0, _a.concat([(_b.sent())]));
|
71 | _b.label = 5;
|
72 | case 5:
|
73 | _i++;
|
74 | return [3, 3];
|
75 | case 6:
|
76 | param = out;
|
77 | _b.label = 7;
|
78 | case 7:
|
79 | command_1.default(param);
|
80 | return [2];
|
81 | }
|
82 | });
|
83 | }); });
|
84 |
|
\ | No newline at end of file |