From 0e8de173a4519c70ab9fcf9a4e0ec01aaca64d97 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Fri, 1 Oct 2021 14:41:52 +0800 Subject: [PATCH] feat(cli): dts flag for build command --- cli/src/build.ts | 4 +++- examples/napi/__test__/typegen.spec.ts | 2 +- examples/napi/{type.d.ts => index.d.ts} | 17 ++--------------- examples/napi/package.json | 2 +- 4 files changed, 7 insertions(+), 18 deletions(-) rename examples/napi/{type.d.ts => index.d.ts} (83%) diff --git a/cli/src/build.ts b/cli/src/build.ts index e34baf3b..0638968b 100644 --- a/cli/src/build.ts +++ b/cli/src/build.ts @@ -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'), ) } } diff --git a/examples/napi/__test__/typegen.spec.ts b/examples/napi/__test__/typegen.spec.ts index 3dc2009c..68d624d0 100644 --- a/examples/napi/__test__/typegen.spec.ts +++ b/examples/napi/__test__/typegen.spec.ts @@ -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')) }) diff --git a/examples/napi/type.d.ts b/examples/napi/index.d.ts similarity index 83% rename from examples/napi/type.d.ts rename to examples/napi/index.d.ts index 2e744c54..a869439a 100644 --- a/examples/napi/type.d.ts +++ b/examples/napi/index.d.ts @@ -2,21 +2,8 @@ export function getWords(): Array export function getNums(): Array export function sumNums(nums: Array): 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 diff --git a/examples/napi/package.json b/examples/napi/package.json index fff1c381..a1f3924c 100644 --- a/examples/napi/package.json +++ b/examples/napi/package.json @@ -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\"",