Skip to content

Commit

Permalink
feat(cli): dts flag for build command
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Oct 1, 2021
1 parent e69a763 commit 0e8de17
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
4 changes: 3 additions & 1 deletion cli/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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'),
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/napi/__test__/typegen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
})
17 changes: 2 additions & 15 deletions examples/napi/type.d.ts → examples/napi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/napi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\"",
Expand Down

0 comments on commit 0e8de17

Please sign in to comment.