feat: support --cargo-name config in napi cli
This commit is contained in:
parent
9c45704eae
commit
4226561c7e
1 changed files with 27 additions and 23 deletions
50
src/build.ts
50
src/build.ts
|
@ -28,6 +28,9 @@ export class BuildCommand extends Command {
|
||||||
@Command.String('--config,-c')
|
@Command.String('--config,-c')
|
||||||
configFileName?: string
|
configFileName?: string
|
||||||
|
|
||||||
|
@Command.String('--cargo-name')
|
||||||
|
cargoName?: string
|
||||||
|
|
||||||
@Command.String({
|
@Command.String({
|
||||||
required: false,
|
required: false,
|
||||||
})
|
})
|
||||||
|
@ -36,31 +39,32 @@ export class BuildCommand extends Command {
|
||||||
@Command.Path('build')
|
@Command.Path('build')
|
||||||
async execute() {
|
async execute() {
|
||||||
const { binaryName } = getNapiConfig(this.configFileName)
|
const { binaryName } = getNapiConfig(this.configFileName)
|
||||||
let tomlContentString: string
|
let dylibName = this.cargoName
|
||||||
let tomlContent: any
|
if (!dylibName) {
|
||||||
try {
|
let tomlContentString: string
|
||||||
debug('Start read toml')
|
let tomlContent: any
|
||||||
tomlContentString = await readFileAsync(
|
try {
|
||||||
join(process.cwd(), 'Cargo.toml'),
|
debug('Start read toml')
|
||||||
'utf-8',
|
tomlContentString = await readFileAsync(
|
||||||
)
|
join(process.cwd(), 'Cargo.toml'),
|
||||||
} catch {
|
'utf-8',
|
||||||
throw new TypeError(`Could not find Cargo.toml in ${process.cwd()}`)
|
)
|
||||||
}
|
} catch {
|
||||||
|
throw new TypeError(`Could not find Cargo.toml in ${process.cwd()}`)
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
debug('Start parse toml')
|
debug('Start parse toml')
|
||||||
tomlContent = toml.parse(tomlContentString)
|
tomlContent = toml.parse(tomlContentString)
|
||||||
} catch {
|
} catch {
|
||||||
throw new TypeError('Could not parse the Cargo.toml')
|
throw new TypeError('Could not parse the Cargo.toml')
|
||||||
}
|
}
|
||||||
|
|
||||||
let dylibName
|
if (tomlContent.package ?? tomlContent.package.name) {
|
||||||
|
dylibName = tomlContent.package.name.replace(/-/g, '_')
|
||||||
if (tomlContent.package ?? tomlContent.package.name) {
|
} else {
|
||||||
dylibName = tomlContent.package.name.replace(/-/g, '_')
|
throw new TypeError('No package.name field in Cargo.toml')
|
||||||
} else {
|
}
|
||||||
throw new TypeError('No package.name field in Cargo.toml')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(`Dylib name: ${chalk.greenBright(dylibName)}`)
|
debug(`Dylib name: ${chalk.greenBright(dylibName)}`)
|
||||||
|
|
Loading…
Reference in a new issue