2020-09-04 17:22:15 +09:00
|
|
|
import { join } from 'path'
|
|
|
|
|
2020-10-15 21:16:52 +09:00
|
|
|
import { DefaultPlatforms, PlatformDetail, parseTriple } from './parse-triple'
|
|
|
|
|
2020-12-25 19:10:53 +09:00
|
|
|
export function getNapiConfig(
|
|
|
|
packageJson = 'package.json',
|
|
|
|
cwd = process.cwd(),
|
|
|
|
) {
|
|
|
|
const packageJsonPath = join(cwd, packageJson)
|
2020-09-04 17:22:15 +09:00
|
|
|
|
|
|
|
const pkgJson = require(packageJsonPath)
|
2020-10-15 21:16:52 +09:00
|
|
|
const { version: packageVersion, napi, name } = pkgJson
|
|
|
|
const additionPlatforms: PlatformDetail[] = (
|
|
|
|
napi?.triples?.additional ?? []
|
|
|
|
).map(parseTriple)
|
|
|
|
const defaultPlatforms =
|
|
|
|
napi?.triples?.defaults === false ? [] : [...DefaultPlatforms]
|
|
|
|
const platforms = [...defaultPlatforms, ...additionPlatforms]
|
2020-09-13 23:06:10 +09:00
|
|
|
const releaseVersion = process.env.RELEASE_VERSION
|
|
|
|
const releaseVersionWithoutPrefix = releaseVersion?.startsWith('v')
|
|
|
|
? releaseVersion.substr(1)
|
|
|
|
: releaseVersion
|
|
|
|
const version = releaseVersionWithoutPrefix ?? packageVersion
|
2020-09-04 17:22:15 +09:00
|
|
|
const packageName = name
|
|
|
|
|
2020-10-15 21:16:52 +09:00
|
|
|
const binaryName: string = napi?.name ?? 'index'
|
2020-09-04 17:22:15 +09:00
|
|
|
|
|
|
|
return {
|
|
|
|
platforms,
|
|
|
|
version,
|
|
|
|
packageName,
|
|
|
|
binaryName,
|
|
|
|
packageJsonPath,
|
|
|
|
content: pkgJson,
|
|
|
|
}
|
|
|
|
}
|