feat(cli): dts flag for build command

This commit is contained in:
LongYinan 2021-10-01 14:41:52 +08:00
parent e69a763284
commit 0e8de173a4
4 changed files with 7 additions and 18 deletions

View file

@ -38,6 +38,8 @@ export class BuildCommand extends Command {
features?: string = Option.String('--features')
dts?: string = Option.String('--dts')
cargoFlags = Option.String('--cargo-flags', '')
cargoCwd?: string = Option.String('--cargo-cwd')
@ -198,7 +200,7 @@ export class BuildCommand extends Command {
await processIntermediateTypeFile(
intermediateTypeFile,
join(this.destDir ?? '.', 'type.d.ts'),
join(this.destDir ?? '.', this.dts ?? 'index.d.ts'),
)
}
}

View file

@ -4,5 +4,5 @@ import { join } from 'path'
import test from 'ava'
test('should generate correct type def file', (t) => {
t.snapshot(readFileSync(join(__dirname, '..', 'type.d.ts'), 'utf8'))
t.snapshot(readFileSync(join(__dirname, '..', 'index.d.ts'), 'utf8'))
})

View file

@ -2,21 +2,8 @@ export function getWords(): Array<string>
export function getNums(): Array<number>
export function sumNums(nums: Array<number>): number
export function getCwd(callback: (arg0: string) => void): void
export enum Kind {
Dog = 0,
Cat = 1,
Duck = 2,
}
export enum CustomNumEnum {
One = 1,
Two = 2,
Three = 3,
Four = 4,
Six = 6,
Eight = 8,
Nine = 9,
Ten = 10,
}
export enum Kind { Dog = 0, Cat = 1, Duck = 2 }
export enum CustomNumEnum { One = 1, Two = 2, Three = 3, Four = 4, Six = 6, Eight = 8, Nine = 9, Ten = 10 }
export function enumToI32(e: CustomNumEnum): number
export function mapOption(val: number | undefined): number | undefined
export function add(a: number, b: number): number

View file

@ -2,7 +2,7 @@
"name": "napi-examples",
"private": true,
"main": "./index.node",
"types": "./type.d.ts",
"types": "./index.d.ts",
"scripts": {
"build": "node ../../cli/scripts/index.js build --features \"latest\"",
"build-napi3": "node ../../cli/scripts/index.js build --features \"napi3\"",