This repository was archived by the owner on Sep 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.js
More file actions
74 lines (64 loc) · 1.82 KB
/
Copy pathindex.js
File metadata and controls
74 lines (64 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* Updates Bower components to the really latest versions.
*
* @author Artem Sapegin (http://sapegin.me)
*/
'use strict';
var chalk = require('chalk');
var bower = require('bower');
var _ = require('lodash');
var async = require('async');
var readlineSync = require('readline-sync');
module.exports = function(options, allDone) {
var bowerConfig = {
cwd: options.cwd
};
var getComponents = function(done) {
bower.commands.list({
map: true
}, bowerConfig)
.on('error', allDone)
.on('end', done.bind(null, null))
;
};
var updateComponents = function(data, done) {
var components = _.values(data.dependencies);
components = _.filter(components, isUpdateAvailable);
if (!components.length) {
done(null, []);
return;
}
var endpoints = _.map(components, function(component) { return component.endpoint.name; });
bower.commands.install(endpoints, {save: true, forceLatest: true}, bowerConfig)
.on('end', function(installed) {
var updated = [];
_.each(installed, function(component) {
var name = component.endpoint.name;
var meta = data.dependencies[name];
if (meta) {
updated.push({
name: name,
now: meta.update.latest,
then: meta.update.target
});
}
});
done(null, updated);
})
;
};
var isUpdateAvailable = function(component) {
if (!component.update || component.update.target === component.update.latest) return false;
if (options.interactive) {
console.log(component.endpoint.name + ': ' + chalk.red(component.update.target) + ' → ' + chalk.green(component.update.latest));
var answer = readlineSync.question('Update? (Y/n)').toLowerCase() !== 'n';
console.log(answer ? 'Updated.\n' : 'Skipped.\n');
return answer;
}
return true;
};
async.waterfall([
getComponents,
updateComponents
], allDone);
};