plugins-rs 0.1.2

js plugins for a rust app
docs.rs failed to build plugins-rs-0.1.2
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

PluginSystem


Cargo.toml

plugin-rs = { version = "0.1.2" }


Features

  • Embeded Plugins
  • Simple Standalone Plugins
  • Archived Plugins with .7z, .zip, .tar, .tar.gz, .tar.xz

Not Supported yet

  • packages like npm, jsr, git (comming soon)

main.rs

use plugins_rs::bind_dir;
use plugins_rs::{ Source, PluginSystem };

fn main() {

    let mut plugins = match PluginSystem::builder()
        .add_source(Source::from_static(std::env::current_dir().unwrap().join("javascript").join("plugins")))
        .add_embed(Source::from_embed(bind_dir!("javascript/embed")))
        .run(None) {
            Ok(prt) => prt,
            Err(err) => panic!("{}", err),
        };

    loop {
        println!("exec() > {:?}", plugins.execute("namespace", "base", "exec()").unwrap());
        println!("do_action.audio_dir() > {:?}", plugins.execute("namespace", "base", "do_action.audio_dir()").unwrap());
        println!("demo.title > {:?}", plugins.execute("namespace", "base", "demo.title").unwrap());
        std::thread::sleep(std::time::Duration::from_millis(1000));
    }

}

Static Plugins

javascript/static/{myplugin}/plugin.json

{
    "name": "Test Plugin",
    "description": "Test Plugin",
    "identifier": "com.test.plugin",
    "version": "1.0.0",
    "entry": "index.ts"
}

javascript/static/{myplugin}/index.ts


// your Plugin Logic

globalThis.Plugins.registerPlugin("base", {
    name: "Base Test Plugin",
    exec: function () {
        return Date.now();
    },
    demo: CustomApi,
    do_action
});

Embeded Plugins

to register plugins or custom api entry.ts as entry required

example 1: javascript/embed/{myplugin}/entry.ts


// your Plugin Logic

globalThis.Plugins.registerPlugin("base", {
    name: "Base Test Plugin",
    exec: function () {
        return Date.now();
    },
    demo: CustomApi,
    do_action
});

example 2: javascript/embed/{myplugin}/entry.ts

declare global {
    var  CustomApi: {
        title: string;
    }
}

globalThis.CustomApi = {
    title : "DemoProperty"
};