feat(cli): add build option to not include the header in dts file (#1140)

* Add build option to not include the header in dts file

* Fix lint
This commit is contained in:
Gabriel Francisco 2022-04-22 05:52:43 -03:00 committed by GitHub
parent 4f422b6625
commit c39060984d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -110,6 +110,10 @@ export class BuildCommand extends Command {
)} file, relative to cwd`, )} file, relative to cwd`,
}) })
noDtsHeader = Option.Boolean('--no-dts-header', false, {
description: `Don't generate ${chalk.green('.d.ts')} header`,
})
project = Option.String('-p', { project = Option.String('-p', {
description: `Bypass to ${chalk.green('cargo -p')}`, description: `Bypass to ${chalk.green('cargo -p')}`,
}) })
@ -497,6 +501,7 @@ export class BuildCommand extends Command {
const idents = await processIntermediateTypeFile( const idents = await processIntermediateTypeFile(
intermediateTypeFile, intermediateTypeFile,
dtsFilePath, dtsFilePath,
this.noDtsHeader,
) )
await writeJsBinding( await writeJsBinding(
binaryName, binaryName,
@ -545,6 +550,7 @@ interface TypeDef {
async function processIntermediateTypeFile( async function processIntermediateTypeFile(
source: string, source: string,
target: string, target: string,
noDtsHeader: boolean,
): Promise<string[]> { ): Promise<string[]> {
const idents: string[] = [] const idents: string[] = []
if (!existsSync(source)) { if (!existsSync(source)) {
@ -654,7 +660,9 @@ async function processIntermediateTypeFile(
return acc + `export namespace ${mod} {\n${convertDefs(defs, true)}}\n` return acc + `export namespace ${mod} {\n${convertDefs(defs, true)}}\n`
}, '') }, '')
const dtsHeader = `/* tslint:disable */ const dtsHeader = noDtsHeader
? ''
: `/* tslint:disable */
/* eslint-disable */ /* eslint-disable */
/* auto-generated by NAPI-RS */\n /* auto-generated by NAPI-RS */\n