-
Notifications
You must be signed in to change notification settings - Fork 19
/
symbols.js
32 lines (24 loc) · 1.53 KB
/
symbols.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
var exec = require('child_process').execSync
var path = require('path')
var symbols = exec(`nm -gU "${path.join(require.resolve('sodium-native'), '../prebuilds/darwin-x64/libsodium.dylib')}"`).toString().trim().split('\n')
var native = new Set(Object.keys(require('sodium-native')).sort())
var js = new Set(Object.keys(require('sodium-javascript')).sort())
symbols = symbols.map(l => l.split(' ').pop().replace(/^_/, '').replace(/_[^_]*bytes.*/, (s) => s.toUpperCase()))
var missing = []
console.log(`
<!-- Generated by build-scripts/symbols.js with
sodium-native@${require('sodium-native/package.json').version}
sodium-javascript@${require('sodium-javascript/package.json').version} -->\
`)
const max = symbols.filter(s => native.has(s) || js.has(s)).map(s => s.length).reduce((a, b) => Math.max(a, b))
const lines = ':-' + ''.padEnd(max, '--') + '-:'
const center = s => s.padStart(Math.floor((max + s.length) / 2), ' ').padEnd(max, ' ')
console.log(`| ${center('C Library Symbol')} | \`sodium-native\` | \`sodium-javascript\` |`)
console.log(`|${lines}|:--------------------:|:--------------------:|`)
for (var i = 0; i < symbols.length; i++) {
var s = symbols[i]
if (!(native.has(s) || js.has(s))) missing.push(s)
else console.log(`| \`${(s + '`').padEnd(max + 1, ' ')} | ${native.has(s) ? ' :white_check_mark: ' : ':small_red_triangle:'} | ${js.has(s) ? ' :white_check_mark: ' : ':small_red_triangle:'} |`)
}
console.log('\n### Missing altogether (Ctrl + F friendly)\n')
console.log(missing.map(s => '`' + s + '`').join(', '))