-
Notifications
You must be signed in to change notification settings - Fork 21
/
update-searchbase.js
56 lines (53 loc) · 1.52 KB
/
update-searchbase.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
var fs = require('fs');
const packageJSON = require('./packages/searchbase/package.json');
var walk = function(dir, done) {
var results = [];
fs.readdir(dir, function(err, list) {
if (err) return done(err);
var i = 0;
(function next() {
var file = list[i++];
if (!file) return done(null, results);
file = dir + '/' + file;
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
walk(file, function(err, res) {
results = results.concat(res);
next();
});
} else {
results.push(file);
next();
}
});
})();
});
};
walk(__dirname, function(err, results) {
if (err) throw err;
var filesToUpdate = results
.filter(item => item.includes('package.json'))
.filter(item => !item.includes('packages/searchbox'))
.filter(item => !item.includes('node_modules'));
filesToUpdate.forEach(file => {
var jsonFile = require(file);
if (
true &&
jsonFile.dependencies &&
jsonFile.dependencies['@appbaseio/searchbase']
) {
console.log('Updating version of', file.replace('$var', ''));
jsonFile.dependencies['@appbaseio/searchbase'] = packageJSON.version;
var updatedJSON = JSON.stringify(jsonFile, null, 4);
fs.writeFile(file, updatedJSON, 'utf8', err => {
if (err) {
console.log(
'Error while updating version of',
file.replace('$var', '')
);
throw err;
}
});
}
});
});