-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (44 loc) · 1.28 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
const all = require('./index.json')
function applyCodename(obj, lifecycle)
{
const {codename} = lifecycle
if(codename
&& (!obj[codename] || obj[codename].release < lifecycle.release))
obj[codename] = lifecycle
return obj
}
function generateConstants(all)
{
const osFamily = {}
for(const lifecycle of all)
{
const osFamilyName = lifecycle.name
let family = osFamily[osFamilyName]
if(!family) osFamily[osFamilyName] = family = {}
family[lifecycle.version] = lifecycle
applyCodename(family, lifecycle)
if(!family.newest
|| (osFamilyName === 'Ubuntu'
&& family.newest.version.substr(0, 5) < lifecycle.version.substr(0, 5))
|| (osFamilyName !== 'Ubuntu'
&& family.newest.release < lifecycle.release))
family.newest = lifecycle
}
const result = {all}
for(const [name, family] of Object.entries(osFamily))
{
result[name] = family
for(const lifecycle of Object.values(family))
applyCodename(result, lifecycle)
}
return result
}
function filterMaintained({eol, release})
{
return new Date(release) < this && this < new Date(eol)
}
module.exports = exports = function(now = new Date())
{
return generateConstants(all.filter(filterMaintained, now))
}
Object.assign(exports, generateConstants(all))