@anycli/config
Version:
base config object and standard interfaces for anycli components
47 lines (46 loc) • 1.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const command_1 = require("./command");
const debug_1 = require("./debug");
const debug = debug_1.default();
var Manifest;
(function (Manifest) {
function build(version, dir, findCommand) {
let globby;
try {
globby = require('globby');
}
catch (_a) {
debug('not loading plugins, globby not found');
return {};
}
debug(`loading IDs from ${dir}`);
const ids = globby.sync(['**/*.+(js|ts)', '!**/*.+(d.ts|test.ts|test.js)'], { cwd: dir })
.map(file => {
const p = path.parse(file);
const topics = p.dir.split('/');
let command = p.name !== 'index' && p.name;
return [...topics, command].filter(f => f).join(':');
});
debug('found ids', ids);
let commands = ids.map(id => {
try {
return [id, command_1.Command.toCached(findCommand(id))];
}
catch (err) {
process.emitWarning(err);
}
});
return {
version,
commands: commands
.filter((f) => !!f)
.reduce((commands, [id, c]) => {
commands[id] = c;
return commands;
}, {})
};
}
Manifest.build = build;
})(Manifest = exports.Manifest || (exports.Manifest = {}));