UNPKG

5.32 kBJavaScriptView Raw
1"use strict";
2var __assign = (this && this.__assign) || Object.assign || function(t) {
3 for (var s, i = 1, n = arguments.length; i < n; i++) {
4 s = arguments[i];
5 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6 t[p] = s[p];
7 }
8 return t;
9};
10var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
11 return new (P || (P = Promise))(function (resolve, reject) {
12 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
13 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
14 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
15 step((generator = generator.apply(thisArg, _arguments || [])).next());
16 });
17};
18var __generator = (this && this.__generator) || function (thisArg, body) {
19 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
20 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
21 function verb(n) { return function (v) { return step([n, v]); }; }
22 function step(op) {
23 if (f) throw new TypeError("Generator is already executing.");
24 while (_) try {
25 if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
26 if (y = 0, t) op = [0, t.value];
27 switch (op[0]) {
28 case 0: case 1: t = op; break;
29 case 4: _.label++; return { value: op[1], done: false };
30 case 5: _.label++; y = op[1]; op = [0]; continue;
31 case 7: op = _.ops.pop(); _.trys.pop(); continue;
32 default:
33 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
34 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
35 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
36 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
37 if (t[2]) _.ops.pop();
38 _.trys.pop(); continue;
39 }
40 op = body.call(thisArg, _);
41 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
42 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
43 }
44};
45var _this = this;
46Object.defineProperty(exports, "__esModule", { value: true });
47var command_1 = require("./command");
48var common_1 = require("./common");
49function toCommand(modulePath) {
50 var m = require(modulePath);
51 var name;
52 name = m.name ? m.name : common_1.fsPath.basename(modulePath, '.js');
53 name = name.endsWith('.cmd') ? common_1.fsPath.basename(name, '.cmd') : name;
54 var alias = m.alias;
55 if (!common_1.R.is(Array, alias)) {
56 alias = [alias];
57 }
58 alias = common_1.R.reject(common_1.R.isNil)(alias);
59 var action = m.cmd || m.default;
60 return {
61 name: name,
62 alias: alias,
63 description: m.description,
64 group: m.group,
65 args: m.args,
66 validate: m.validate,
67 action: action,
68 };
69}
70function toCommands(modulePaths) {
71 var commands = modulePaths
72 .map(toCommand)
73 .filter(function (item) { return common_1.R.is(Function, item.action); });
74 var result = {};
75 commands.forEach(function (cmd) { return (result[cmd.name] = cmd); });
76 return result;
77}
78function pathToCommands(path) {
79 return __awaiter(this, void 0, void 0, function () {
80 var paths;
81 return __generator(this, function (_a) {
82 switch (_a.label) {
83 case 0: return [4, common_1.file.glob(path)];
84 case 1:
85 paths = _a.sent();
86 return [2, toCommands(paths)];
87 }
88 });
89 });
90}
91exports.default = (function (param) { return __awaiter(_this, void 0, void 0, function () {
92 var out, _i, param_1, path, _a;
93 return __generator(this, function (_b) {
94 switch (_b.label) {
95 case 0:
96 if (!(typeof param === 'string')) return [3, 2];
97 return [4, pathToCommands(param)];
98 case 1:
99 param = _b.sent();
100 _b.label = 2;
101 case 2:
102 if (!Array.isArray(param)) return [3, 7];
103 out = {};
104 _i = 0, param_1 = param;
105 _b.label = 3;
106 case 3:
107 if (!(_i < param_1.length)) return [3, 6];
108 path = param_1[_i];
109 _a = [{}, out];
110 return [4, pathToCommands(path)];
111 case 4:
112 out = __assign.apply(void 0, _a.concat([(_b.sent())]));
113 _b.label = 5;
114 case 5:
115 _i++;
116 return [3, 3];
117 case 6:
118 param = out;
119 _b.label = 7;
120 case 7:
121 command_1.default(param);
122 return [2];
123 }
124 });
125}); });
126//# sourceMappingURL=init.js.map
\No newline at end of file