-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
130 lines (111 loc) · 3.52 KB
/
index.js
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
'use strict';
//Adapted from brunocartier's bower-update-all to be used with gulp
var gutil = require('gulp-util');
var execSync = require('child_process').execSync;
var through = require('through2');
var pluginName = 'bower-update-all';
var pluginError = gutil.PluginError;
//isGitOnly flag used to download from dependencies only in git repos
/*jslint indent: 4, maxlen: 80, node: true */
module.exports = function (isGitOnly, isSave) {
'use strict';
var DependencyUpdater;
var handleFile;
DependencyUpdater = function () {
var // Functions
updateDependency,
addDependency,
updateNext,
// Variables
self = {},
dependencies = [];
updateDependency = function (dep, cb) {
var command = 'bower install ' + dep.name + ' --force-latest';
if(isSave) {
command += ' --save';
}
if (dep.dev) {
command += '-dev';
}
var err = execSync(command);
if (err) {
console.log('Updated ' + dep.name + ' - ' + err);
}
cb();
};
addDependency = function (name, dev) {
dependencies.push({
name: name,
dev: !!dev
});
};
updateNext = function () {
if (dependencies.length) {
updateDependency(
dependencies.shift(),
updateNext
);
} else {
console.log('➤ All dependencies updated!');
}
return true;
};
self.addDependency = addDependency;
self.updateNext = updateNext;
return self;
};
handleFile = function (data) {
console.log('➤ Getting and parsing bower.json file...');
var bowerJson = JSON.parse(data),
updater = new DependencyUpdater(),
value = '';
if (bowerJson.dependencies) {
Object
.keys(bowerJson.dependencies)
.forEach(function (dep) {
value = bowerJson.dependencies[dep];
if(isGitOnly) {
if(value.indexOf('git') > -1) {
updater.addDependency(value);
}
}
else {
updater.addDependency(value);
}
});
}
if (bowerJson.devDependencies) {
Object
.keys(bowerJson.devDependencies)
.forEach(function (dep) {
if(isGitOnly) {
if(value.indexOf('git') > -1) {
updater.addDependency(value);
}
}
else {
updater.addDependency(value);
}
});
}
return updater.updateNext();
};
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
console.log('✘ Problem getting your file, please try again.');
cb(null, file);
return;
}
if (file.isStream()) {
cb(new pluginError(pluginName, 'Streaming not supported'));
return;
}
if(!enc){
enc = 'utf8';
}
var content = file.contents.toString(enc);
handleFile(content);
//push back file to stream
cb(null, file);
});
};