forked from napi-rs/napi-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-triple-list.ts
48 lines (40 loc) · 1.06 KB
/
generate-triple-list.ts
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
import { readFileSync, writeFileSync } from 'fs'
import { join } from 'path'
import * as esbuild from 'esbuild'
import { groupBy, mapValues } from 'lodash'
import { parseTriple } from './cli/src/parse-triple'
const RAW_LIST = readFileSync(join(__dirname, 'triples', 'target-list'), 'utf8')
const SUPPORTED_PLATFORM = new Set([
'darwin',
'ios',
'android',
'win32',
'linux',
'freebsd',
])
const tripleLists: { [key: string]: { platform?: string } } = RAW_LIST.trim()
.split('\n')
.filter((line) => !line.startsWith('wasm') && line.trim().length)
.map(parseTriple)
.reduce((acc, cur) => {
acc[cur.raw] = cur
return acc
}, {})
const platformArchTriples = mapValues(
groupBy(
Object.values(tripleLists).filter((k) =>
SUPPORTED_PLATFORM.has(k.platform!),
),
'platform',
),
(v) => groupBy(v, 'arch'),
)
const fileContent = `
module.exports.platformArchTriples = ${JSON.stringify(platformArchTriples)}
`
writeFileSync(
join(__dirname, 'triples', 'index.js'),
esbuild.transformSync(fileContent, {
minify: true,
}).code,
)