forked from compat-table/compat-table
-
Notifications
You must be signed in to change notification settings - Fork 33
/
build.js
59 lines (52 loc) · 2.25 KB
/
build.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
var pug = require('pug')
var utils = require('./utils.js');
var $escape = utils.$escape
var $get = utils.$get
var testers = utils.objectifiedTesters();
var results = {
unflagged: {},
flagged: {}
}
const engine = 'v8'
var headers = require('./versions.js')(engine)
Object.keys(headers).forEach((version) => {
results.unflagged[version] = require(`./results/${engine}/${version}.json`)
results.flagged[version] = require(`./results/${engine}/${version}--harmony.json`)
//convert to the actual headers view model
headers[version] = {
super: version === 'nightly' ? 'Nightly!' : '',
version: version === 'nightly'? results.flagged[version]._version.replace(/-.*/, '') : version,
includes: headers[version]
}
})
function requiresFlag (nodeVersion, esVersion, path) {
var flagged = $get(results.flagged, nodeVersion, esVersion)
var unflagged = $get(results.unflagged, nodeVersion, esVersion)
return flagged && unflagged && flagged[path] === true && unflagged[path] !== true
}
function result (type, nodeVersion, esVersion, path) {
var result = $get(results, type, nodeVersion)
if (result === undefined) return ''
result = $get(result, esVersion, path)
var flaggd = type === 'flagged'
var flagRequired = flaggd && requiresFlag(nodeVersion, esVersion, path)
var title = result === true ? (flagRequired ? 'Yes, but requires --harmony flag' : 'Test passed') : typeof result === 'string' ? result : 'Test failed'
result = result === true ? 'Yes' : typeof result === 'string' ? 'Error' : 'No'
return `<div class="${result} ${type} ${flagRequired ? 'required' : ''}" title="${$escape(title)}">${result === 'Yes' && flagRequired ? 'Flag' : result}</div>`
}
var html = pug.renderFile('index.pug', {
pretty: true,
flaggable: true,
headers: headers,
testers: testers,
results: function (nodeVersion, esVersion, path) {
return result('unflagged', nodeVersion, esVersion, path) + result('flagged', nodeVersion, esVersion, path)
},
requiresFlag: requiresFlag,
percent: function (nodeVersion, esVersion, unflagged) {
var datasource = unflagged ? results.unflagged : results.flagged
var data = $get(datasource, nodeVersion, esVersion)
return data ? Math.floor(data._percent * 100) : ''
}
})
require('fs').writeFileSync('./index.html', html)