feat(cli): provide a way to override the native package name

This commit is contained in:
LongYinan 2021-12-22 20:24:15 +08:00
parent 46168ee6d6
commit 046f75dc29
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
2 changed files with 15 additions and 3 deletions

View file

@ -79,6 +79,13 @@ export class BuildCommand extends Command {
)} to disable it. Only affect if ${chalk.green('--target')} specified.`,
})
jsPackageName = Option.String('--js-package-name', {
description: `Package name in generated js binding file, Only affect if ${chalk.green(
'--target',
)} specified and ${chalk.green('--js')} is not false.`,
required: false,
})
cargoCwd?: string = Option.String('--cargo-cwd', {
description: `The cwd of ${chalk.underline(
chalk.yellow('Cargo.toml'),
@ -304,7 +311,12 @@ export class BuildCommand extends Command {
this.appendPlatformToFilename
? join(process.cwd(), this.jsBinding)
: null
await writeJsBinding(binaryName, packageName, jsBindingFilePath, idents)
await writeJsBinding(
binaryName,
this.jsPackageName ?? packageName,
jsBindingFilePath,
idents,
)
if (this.pipe && jsBindingFilePath) {
const pipeCommand = `${this.pipe} ${jsBindingFilePath}`
console.info(`Run ${chalk.green(pipeCommand)}`)

View file

@ -18,10 +18,10 @@ export function getNapiConfig(
const platforms = [...defaultPlatforms, ...additionPlatforms]
const releaseVersion = process.env.RELEASE_VERSION
const releaseVersionWithoutPrefix = releaseVersion?.startsWith('v')
? releaseVersion.substr(1)
? releaseVersion.substring(1)
: releaseVersion
const version = releaseVersionWithoutPrefix ?? packageVersion
const packageName = name
const packageName = napi?.package?.name ?? name
const binaryName: string = napi?.name ?? 'index'