npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tauria-tsgen

v0.2.2

Published

A CLI tool to generate TypeScript interfaces from Rust Tauri commands.

Downloads

16

Readme

tauria-tsgen (npm package)

This is the npm package for tauria-tsgen, a CLI tool that automatically generates TypeScript interfaces and wrapper functions from Rust Tauri commands.

Installation

To install the tauria-tsgen CLI tool, run the following command:

npm install tauria-tsgen --save-dev

Usage

After installation, you can use the tauria-tsgen command directly:

taura-tsgen --help

Recommended Usage (with configuration file)

For more complex projects, it is recommended to use a configuration file.

  1. Create a configuration file

    Create a file named tauria-tsgen-config.json in your project root:

    {
      "input_path": "src-tauri/src",
      "output_path": "src/app/external/tauri-api"
    }
  2. Add a script to package.json

    Add the following script to your package.json:

    "scripts": {
      "maketsif": "tauria-tsgen --config tauria-tsgen-config.json"
    }
  3. Run the script

    You can now generate the TypeScript interfaces by running:

    npm run maketsif

For detailed usage instructions, command-line arguments, and examples, please refer to the main GitHub repository:

tauria-tsgen GitHub Repository

Input and Output Examples

Rust Input Example (src/cmd1.rs)

use tauri::command;

#[command]
pub fn command1() -> String {
    "Command 1 executed".to_string()
}

Rust Input Example (src/cmd2.rs)

use tauri::command;

#[command]
pub fn command2() -> String {
    "Command 2 executed".to_string()
}

Generated TypeScript Output Example (output_directory/interface/commands/Cmd1.ts)

// src/bindings/commands/Cmd1.ts

import { invoke } from '@tauri-apps/api/tauri';

export class Cmd1 {
  static async command1(): Promise<string> {
    return await invoke('command1');
  }
}

Generated TypeScript Output Example (output_directory/interface/commands/Cmd2.ts)

// src/bindings/commands/Cmd2.ts

import { invoke } from '@tauri-apps/api/tauri';

export class Cmd2 {
  static async command2(): Promise<string> {
    return await invoke('command2');
  }
}

Generated File Directory Structure

tauria-tsgen generates TypeScript files while maintaining the directory structure of the input Rust files. For example, if you specify ./src/bindings for --output-path, files will be generated directly within that directory with the following structure:

./src/bindings/  <-- This is the directory specified by --output-path
├───tauria-api/
│   ├───Cmd1.ts
│   ├───Cmd2.ts
│   └───index.ts
├───interface/
│   ├───commands/
│   │   ├───Cmd1.ts
│   │   └───Cmd2.ts
│   └───types/
│       └───index.ts
└───index.ts
  • tauria-api/: Wrapper functions that directly call Tauri's invoke function are generated.
  • interface/commands/: TypeScript interfaces corresponding to functions with #[tauri::command] are generated. The file names are determined based on the Rust module names.
  • interface/types/: TypeScript interfaces and types corresponding to Rust structs, enums, etc., are generated.
  • index.ts: This is an entry point file that exports all generated commands and types.

Usage Example of Generated API

The Tauri command wrappers generated by tauria-tsgen can be instantiated via a factory function, allowing type-safe calls to Rust commands.

TypeScript Usage Example

import { createCmd } from './tauria-api'; // Assuming your TypeScript config or bundler resolves from the output directory
// Or, if the output directory is 'src/generated-api' and you're importing from 'src/main.ts':
// import { createCmd } from './generated-api/tauria-api';

async function callTauriCommands() {
  const cmdApi = createCmd(); // Instantiate Cmd class

  try {
    // Call the Rust command1
    const result = await cmdApi.command1();
    console.log('Result of command1:', result);

    // Other commands can be called similarly
    // const result = await cmdApi.some_other_command();
    // console.log('Result of other command:', result);

  } catch (error) {
    console.error('Error calling Tauri command:', error);
  }
}

callTauriCommands();

License

This project is licensed under the MIT License. See the LICENSE file for details.