index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var abbrev = require('abbrev');
  2. var mout = require('mout');
  3. var commands = require('./commands');
  4. var pkg = require('../package.json');
  5. var abbreviations = abbrev(expandNames(commands));
  6. abbreviations.i = 'install';
  7. abbreviations.rm = 'uninstall';
  8. abbreviations.unlink = 'uninstall';
  9. abbreviations.ls = 'list';
  10. function expandNames(obj, prefix, stack) {
  11. prefix = prefix || '';
  12. stack = stack || [];
  13. mout.object.forOwn(obj, function (value, name) {
  14. name = prefix + name;
  15. stack.push(name);
  16. if (typeof value === 'object' && !value.line) {
  17. expandNames(value, name + ' ', stack);
  18. }
  19. });
  20. return stack;
  21. }
  22. function clearRuntimeCache() {
  23. // Note that in edge cases, some architecture components instance's
  24. // in-memory cache might be skipped.
  25. // If that's a problem, you should create and fresh instances instead.
  26. var PackageRepository = require('./core/PackageRepository');
  27. PackageRepository.clearRuntimeCache();
  28. }
  29. module.exports = {
  30. version: pkg.version,
  31. commands: commands,
  32. config: require('./config')(),
  33. abbreviations: abbreviations,
  34. reset: clearRuntimeCache
  35. };