-
Notifications
You must be signed in to change notification settings - Fork 10
/
getPreferred.js
51 lines (46 loc) · 1.22 KB
/
getPreferred.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
'use strict';
const fs = require('fs');
const path = require('path');
const rr = require('recursive-readdir');
const yaml = require('js-yaml');
const helpers = require('./helpers.js');
var results = [];
function doit(input) {
var src = JSON.parse(fs.readFileSync(input,'utf8'));
let serviceName = helpers.extractServiceName(input);
if (src.metadata && src.metadata.apiVersion) {
var entry = results.find(function(e,i,a){
return e.serviceName == serviceName;
});
if (!entry) {
entry = {serviceName: serviceName, versions:[]};
results.push(entry);
}
entry.versions.push(src.metadata.apiVersion);
}
}
var inputspec = process.argv[2];
if (inputspec) {
inputspec = path.resolve(inputspec);
var stats = fs.statSync(inputspec);
if (stats.isFile()) {
doit(inputspec);
}
else {
rr(inputspec, function(err, files) {
for (var f in files) {
var filename = files[f];
if (filename.indexOf('normal')>=0) {
doit(filename);
}
}
});
}
}
process.on('exit',function(){
for (var entry of results) {
entry.versions = entry.versions.sort();
entry.preferred = entry.versions.pop();
}
fs.writeFileSync('./preferred.json',JSON.stringify(results,null,2),'utf8');
});