generated from napi-rs/package-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
137 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import test from 'ava' | ||
|
||
import { plus100 } from '../index' | ||
import { defineCommand } from '../index' | ||
|
||
test('sync function from native code', (t) => { | ||
const fixture = 42 | ||
t.is(plus100(fixture), fixture + 100) | ||
test('define command', (t) => { | ||
const cmd = { | ||
meta: {}, | ||
options: {}, | ||
callback: (ctx: any) => { | ||
console.log(ctx) | ||
}, | ||
} | ||
t.deepEqual(defineCommand(cmd), cmd) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,33 @@ | ||
#![deny(clippy::all)] | ||
|
||
use std::collections::HashMap; | ||
|
||
use napi::JsFunction; | ||
use napi_derive::napi; | ||
|
||
#[napi(object)] | ||
pub struct Context {} | ||
|
||
#[napi(object)] | ||
pub struct CommandMeta { | ||
pub name: Option<String>, | ||
pub version: Option<String>, | ||
pub description: Option<String>, | ||
pub hidden: Option<bool>, | ||
} | ||
|
||
#[napi(object)] | ||
pub struct CommandOption {} | ||
|
||
#[napi(object)] | ||
pub struct Command { | ||
pub meta: CommandMeta, | ||
pub options: HashMap<String, CommandOption>, | ||
#[napi(ts_type = "(ctx: Context) => void")] | ||
pub callback: JsFunction, | ||
} | ||
|
||
#[napi] | ||
pub fn plus_100(input: u32) -> u32 { | ||
input + 100 | ||
pub fn define_command(options: Command) -> Command { | ||
options | ||
} |