1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports._formatDefTable = _formatDefTable;
|
7 | exports.name = exports.description = void 0;
|
8 | exports.run = run;
|
9 | exports.setup = setup;
|
10 |
|
11 | var _libDefs = require("../lib/libDefs.js");
|
12 |
|
13 | var _flowVersion = require("../lib/flowVersion");
|
14 |
|
15 | var _table = require("table");
|
16 |
|
17 | function _formatDefTable(defs) {
|
18 | const formatted = [['Name', 'Package Version', 'Flow Version']].concat(defs.map(def => {
|
19 | return [def.pkgName, def.pkgVersionStr, (0, _flowVersion.toSemverString)(def.flowVersion)];
|
20 | }));
|
21 |
|
22 | if (formatted.length === 1) {
|
23 | return 'No definitions found, sorry!';
|
24 | } else {
|
25 | return '\nFound definitions:\n' + (0, _table.table)(formatted);
|
26 | }
|
27 | }
|
28 |
|
29 | const name = 'search <term>';
|
30 | exports.name = name;
|
31 | const description = 'Perform a simple search (by name) of available libdefs';
|
32 | exports.description = description;
|
33 |
|
34 | function setup(yargs) {
|
35 | return yargs.positional('term', {
|
36 | describe: 'Please provide a term for which to search!',
|
37 | type: 'string'
|
38 | }).option({
|
39 | flowVersion: {
|
40 | alias: 'f',
|
41 | describe: 'The Flow version that fetched libdefs must be compatible with',
|
42 | type: 'string'
|
43 | }
|
44 | });
|
45 | }
|
46 |
|
47 | async function run(args) {
|
48 | let flowVersionStr;
|
49 |
|
50 | if (typeof args.flowVersion === 'string') {
|
51 | flowVersionStr = args.flowVersion;
|
52 | }
|
53 |
|
54 | const term = args.term;
|
55 |
|
56 | if (typeof term !== 'string') {
|
57 | throw new Error('term should be a string');
|
58 | }
|
59 |
|
60 | const defs = await (0, _libDefs.getCacheLibDefs)(process.stdout);
|
61 | const filtered = (0, _libDefs.filterLibDefs)(defs, {
|
62 | type: 'fuzzy',
|
63 | term,
|
64 | flowVersionStr
|
65 | });
|
66 | console.log(_formatDefTable(filtered));
|
67 | return 0;
|
68 | } |
\ | No newline at end of file |