UNPKG

1.28 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const cli_ux_1 = require("cli-ux");
4const globby = require("globby");
5const _ = require("lodash");
6const path = require("path");
7const Config = require(".");
8const debug = require('debug')('@anycli/config');
9var Manifest;
10(function (Manifest) {
11 function build(version, dir, findCommand) {
12 debug(`loading IDs from ${dir}`);
13 const ids = globby.sync(['**/*.+(js|ts)', '!**/*.+(d.ts|test.ts|test.js)'], { cwd: dir })
14 .map(file => {
15 const p = path.parse(file);
16 const topics = p.dir.split('/');
17 let command = p.name !== 'index' && p.name;
18 return _([...topics, command]).compact().join(':');
19 });
20 debug('found ids', ids);
21 let commands = ids.map(id => {
22 try {
23 return [id, Config.Command.toCached(findCommand(id))];
24 }
25 catch (err) {
26 cli_ux_1.default.warn(err);
27 }
28 });
29 return {
30 version,
31 commands: _(commands)
32 .compact()
33 .fromPairs()
34 .value()
35 };
36 }
37 Manifest.build = build;
38})(Manifest = exports.Manifest || (exports.Manifest = {}));