napi-rs/cli/src/consts.ts

37 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-09-04 17:22:15 +09:00
import { join } from 'path'
import { DefaultPlatforms, PlatformDetail, parseTriple } from './parse-triple'
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)
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]
const releaseVersion = process.env.RELEASE_VERSION
const releaseVersionWithoutPrefix = releaseVersion?.startsWith('v')
? releaseVersion.substring(1)
: releaseVersion
const version = releaseVersionWithoutPrefix ?? packageVersion
const packageName = napi?.package?.name ?? name
2020-09-04 17:22:15 +09:00
const binaryName: string = napi?.name ?? 'index'
2020-09-04 17:22:15 +09:00
return {
platforms,
version,
packageName,
binaryName,
packageJsonPath,
content: pkgJson,
}
}