install.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. var endpointParser = require('bower-endpoint-parser');
  2. var Project = require('../core/Project');
  3. var cli = require('../util/cli');
  4. var Tracker = require('../util/analytics').Tracker;
  5. var defaultConfig = require('../config');
  6. function install(logger, endpoints, options, config) {
  7. var project;
  8. var decEndpoints;
  9. var tracker;
  10. options = options || {};
  11. config = defaultConfig(config);
  12. if (options.save === undefined) {
  13. options.save = config.defaultSave;
  14. }
  15. project = new Project(config, logger);
  16. tracker = new Tracker(config);
  17. // Convert endpoints to decomposed endpoints
  18. endpoints = endpoints || [];
  19. decEndpoints = endpoints.map(function (endpoint) {
  20. return endpointParser.decompose(endpoint);
  21. });
  22. tracker.trackDecomposedEndpoints('install', decEndpoints);
  23. return project.install(decEndpoints, options, config);
  24. }
  25. // -------------------
  26. install.line = function (logger, argv) {
  27. var options = install.options(argv);
  28. return install(logger, options.argv.remain.slice(1), options);
  29. };
  30. install.options = function (argv) {
  31. return cli.readOptions({
  32. 'force-latest': { type: Boolean, shorthand: 'F'},
  33. 'production': { type: Boolean, shorthand: 'p' },
  34. 'save': { type: Boolean, shorthand: 'S' },
  35. 'save-dev': { type: Boolean, shorthand: 'D' }
  36. }, argv);
  37. };
  38. install.completion = function () {
  39. // TODO:
  40. };
  41. module.exports = install;