2021-08-07 01:22:53 +09:00
|
|
|
import { readFileSync, writeFileSync } from 'fs'
|
|
|
|
import { join } from 'path'
|
2020-10-15 21:16:52 +09:00
|
|
|
|
2021-08-07 01:22:53 +09:00
|
|
|
import * as esbuild from 'esbuild'
|
|
|
|
import { groupBy, mapValues } from 'lodash'
|
2020-10-15 21:16:52 +09:00
|
|
|
|
2021-08-07 01:22:53 +09:00
|
|
|
import { parseTriple } from './cli/src/parse-triple'
|
2020-10-15 21:16:52 +09:00
|
|
|
|
2021-07-22 14:35:01 +09:00
|
|
|
const RAW_LIST = readFileSync(join(__dirname, 'triples', 'target-list'), 'utf8')
|
2020-10-15 21:16:52 +09:00
|
|
|
|
2021-07-22 14:35:01 +09:00
|
|
|
const SUPPORTED_PLATFORM = new Set([
|
|
|
|
'darwin',
|
|
|
|
'ios',
|
|
|
|
'android',
|
|
|
|
'win32',
|
|
|
|
'linux',
|
|
|
|
'freebsd',
|
|
|
|
])
|
|
|
|
|
|
|
|
const tripleLists = RAW_LIST.trim()
|
2020-10-15 21:16:52 +09:00
|
|
|
.split('\n')
|
|
|
|
.filter((line) => !line.startsWith('wasm') && line.trim().length)
|
|
|
|
.map(parseTriple)
|
|
|
|
.reduce((acc, cur) => {
|
|
|
|
acc[cur.raw] = cur
|
|
|
|
return acc
|
|
|
|
}, {})
|
|
|
|
|
|
|
|
const platformArchTriples = mapValues(
|
2021-07-22 14:35:01 +09:00
|
|
|
groupBy(
|
2021-08-07 01:22:53 +09:00
|
|
|
Object.values(tripleLists).filter((k: { platform?: string }) =>
|
2021-07-22 14:35:01 +09:00
|
|
|
SUPPORTED_PLATFORM.has(k.platform),
|
|
|
|
),
|
|
|
|
'platform',
|
|
|
|
),
|
2020-10-15 21:16:52 +09:00
|
|
|
(v) => groupBy(v, 'arch'),
|
|
|
|
)
|
|
|
|
|
|
|
|
const fileContent = `
|
|
|
|
module.exports.platformArchTriples = ${JSON.stringify(platformArchTriples)}
|
|
|
|
`
|
|
|
|
|
|
|
|
writeFileSync(
|
|
|
|
join(__dirname, 'triples', 'index.js'),
|
2021-07-22 14:35:01 +09:00
|
|
|
esbuild.transformSync(fileContent, {
|
|
|
|
minify: true,
|
|
|
|
}).code,
|
2020-10-15 21:16:52 +09:00
|
|
|
)
|