forked from williamkapke/node-compat-table
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuildrhino.js
66 lines (58 loc) · 2.47 KB
/
buildrhino.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
var pug = require('pug')
var utils = require('./utils.js');
var $escape = utils.$escape
var $get = utils.$get
var testers = utils.objectifiedTesters();
var results = {
flagged: {},
unflagged: {}
}
// TODO load versions some better way
const engine = 'rhino';
const headers = require('./rhinoversions');
Object.keys(headers).forEach((version) => {
if (headers[version].flagged) {
results.flagged[version] = require(`./rhino-results/${version}-es6.json`)
results.unflagged[version] = require(`./rhino-results/${version}.json`)
} else {
results.flagged[version] = require(`./rhino-results/${version}.json`)
results.unflagged[version] = results.flagged[version]
}
//convert to the actual headers view model
headers[version] = {
super: version === 'nightly' ? 'Nightly!' : '',
version: version === 'nightly'? results.unflagged[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 VERSION_ES6 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('rhinoindex.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)