UNPKG

1.69 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports._formatDefTable = _formatDefTable;
7exports.name = exports.description = void 0;
8exports.run = run;
9exports.setup = setup;
10
11var _libDefs = require("../lib/libDefs.js");
12
13var _flowVersion = require("../lib/flowVersion");
14
15var _table = require("table");
16
17function _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
29const name = 'search <term>';
30exports.name = name;
31const description = 'Perform a simple search (by name) of available libdefs';
32exports.description = description;
33
34function 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
47async 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