UNPKG

1.55 kBJavaScriptView Raw
1var endpointParser = require('bower-endpoint-parser');
2var Project = require('../core/Project');
3var defaultConfig = require('../config');
4
5function install(logger, endpoints, options, config) {
6 var project;
7 var decEndpoints;
8
9 options = options || {};
10 config = defaultConfig(config);
11 if (options.save === undefined) {
12 options.save = config.defaultSave;
13 }
14 project = new Project(config, logger);
15
16 // Convert endpoints to decomposed endpoints
17 endpoints = endpoints || [];
18 decEndpoints = endpoints.map(function(endpoint) {
19 // handle @ as version divider
20 var splitParts = endpoint.split('/');
21 splitParts[splitParts.length - 1] = splitParts[
22 splitParts.length - 1
23 ].replace('@', '#');
24 endpoint = splitParts.join('/');
25
26 return endpointParser.decompose(endpoint);
27 });
28
29 return project.install(decEndpoints, options, config);
30}
31
32// -------------------
33
34install.readOptions = function(argv) {
35 var cli = require('../util/cli');
36
37 var options = cli.readOptions(
38 {
39 'force-latest': { type: Boolean, shorthand: 'F' },
40 production: { type: Boolean, shorthand: 'p' },
41 save: { type: Boolean, shorthand: 'S' },
42 'save-dev': { type: Boolean, shorthand: 'D' },
43 'save-exact': { type: Boolean, shorthand: 'E' }
44 },
45 argv
46 );
47
48 var packages = options.argv.remain.slice(1);
49
50 delete options.argv;
51
52 return [packages, options];
53};
54
55module.exports = install;