UNPKG

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