feat: commit build field
This commit is contained in:
1 parent
6f4028f065
commit
d9891d9f0c
9 files changed
+249
-248
No files matched your search
Whitespace-only changes.
+49
-28
@@ -1,12 +1,12 @@
|
||||
use mlua::{FromLua, Function, ToLua};
|
||||
|
||||
pub mod log;
|
||||
pub mod command;
|
||||
pub mod fs;
|
||||
pub mod network;
|
||||
pub mod dirs;
|
||||
pub mod path;
|
||||
pub mod fs;
|
||||
pub mod log;
|
||||
pub mod network;
|
||||
pub mod os;
|
||||
pub mod path;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PluginInfo<'lua> {
|
||||
@@ -16,9 +16,7 @@ pub struct PluginInfo<'lua> {
|
||||
pub version: String,
|
||||
|
||||
pub on_init: Option<Function<'lua>>,
|
||||
pub on_load: Option<Function<'lua>>,
|
||||
pub on_build_start: Option<Function<'lua>>,
|
||||
pub on_build_finish: Option<Function<'lua>>,
|
||||
pub build: PluginBuildInfo<'lua>,
|
||||
}
|
||||
|
||||
impl<'lua> FromLua<'lua> for PluginInfo<'lua> {
|
||||
@@ -30,9 +28,7 @@ impl<'lua> FromLua<'lua> for PluginInfo<'lua> {
|
||||
version: String::from("0.1.0"),
|
||||
|
||||
on_init: None,
|
||||
on_load: None,
|
||||
on_build_start: None,
|
||||
on_build_finish: None,
|
||||
build: Default::default(),
|
||||
};
|
||||
if let mlua::Value::Table(tab) = lua_value {
|
||||
if let Ok(v) = tab.get::<_, String>("name") {
|
||||
@@ -51,16 +47,6 @@ impl<'lua> FromLua<'lua> for PluginInfo<'lua> {
|
||||
if let Ok(v) = tab.get::<_, Function>("on_init") {
|
||||
res.on_init = Some(v);
|
||||
}
|
||||
if let Ok(v) = tab.get::<_, Function>("on_load") {
|
||||
res.on_load = Some(v);
|
||||
}
|
||||
if let Ok(v) = tab.get::<_, Function>("on_build_start") {
|
||||
res.on_build_start = Some(v);
|
||||
}
|
||||
if let Ok(v) = tab.get::<_, Function>("on_build_finish") {
|
||||
res.on_build_finish = Some(v);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
@@ -69,9 +55,8 @@ impl<'lua> FromLua<'lua> for PluginInfo<'lua> {
|
||||
|
||||
impl<'lua> ToLua<'lua> for PluginInfo<'lua> {
|
||||
fn to_lua(self, lua: &'lua mlua::Lua) -> mlua::Result<mlua::Value<'lua>> {
|
||||
|
||||
let res = lua.create_table()?;
|
||||
|
||||
|
||||
res.set("name", self.name.to_string())?;
|
||||
res.set("repository", self.repository.to_string())?;
|
||||
res.set("author", self.author.to_string())?;
|
||||
@@ -80,14 +65,50 @@ impl<'lua> ToLua<'lua> for PluginInfo<'lua> {
|
||||
if let Some(e) = self.on_init {
|
||||
res.set("on_init", e)?;
|
||||
}
|
||||
if let Some(e) = self.on_load {
|
||||
res.set("on_load", e)?;
|
||||
res.set("build", self.build)?;
|
||||
|
||||
Ok(mlua::Value::Table(res))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct PluginBuildInfo<'lua> {
|
||||
pub on_start: Option<Function<'lua>>,
|
||||
pub on_finish: Option<Function<'lua>>,
|
||||
}
|
||||
|
||||
impl<'lua> FromLua<'lua> for PluginBuildInfo<'lua> {
|
||||
fn from_lua(lua_value: mlua::Value<'lua>, _lua: &'lua mlua::Lua) -> mlua::Result<Self> {
|
||||
let mut res = Self {
|
||||
on_start: None,
|
||||
on_finish: None,
|
||||
};
|
||||
|
||||
if let mlua::Value::Table(t) = lua_value {
|
||||
if let Ok(v) = t.get::<_, Function>("on_start") {
|
||||
res.on_start = Some(v);
|
||||
}
|
||||
if let Ok(v) = t.get::<_, Function>("on_finish") {
|
||||
res.on_finish = Some(v);
|
||||
}
|
||||
}
|
||||
if let Some(e) = self.on_build_start {
|
||||
res.set("on_build_start", e)?;
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'lua> ToLua<'lua> for PluginBuildInfo<'lua> {
|
||||
fn to_lua(self, lua: &'lua mlua::Lua) -> mlua::Result<mlua::Value<'lua>> {
|
||||
|
||||
let res = lua.create_table()?;
|
||||
|
||||
|
||||
if let Some(v) = self.on_start {
|
||||
res.set("on_start", v)?;
|
||||
}
|
||||
if let Some(e) = self.on_build_finish {
|
||||
res.set("on_build_finish", e)?;
|
||||
|
||||
if let Some(v) = self.on_finish {
|
||||
res.set("on_finish", v)?;
|
||||
}
|
||||
|
||||
Ok(mlua::Value::Table(res))
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use mlua::UserData;
|
||||
|
||||
pub struct PluginOS;
|
||||
|
||||
+36
-19
@@ -3,20 +3,21 @@ use std::{
|
||||
path::PathBuf,
|
||||
};
|
||||
|
||||
use mlua::{Lua, Table};
|
||||
use mlua::{AsChunk, Lua, Table};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::tools::{app_path, clone_repo};
|
||||
use crate::{tools::{app_path, clone_repo}, CrateConfig};
|
||||
|
||||
use self::{
|
||||
interface::PluginInfo,
|
||||
interface::{
|
||||
command::PluginCommander, dirs::PluginDirs, fs::PluginFileSystem, log::PluginLogger,
|
||||
network::PluginNetwork,
|
||||
network::PluginNetwork, os::PluginOS, path::PluginPath,
|
||||
},
|
||||
};
|
||||
|
||||
pub mod argument;
|
||||
pub mod interface;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@@ -38,6 +39,7 @@ impl PluginManager {
|
||||
let lua = Lua::new();
|
||||
|
||||
let manager = lua.create_table().unwrap();
|
||||
let plugin_dir = Self::init_plugin_dir();
|
||||
|
||||
let api = lua.create_table().unwrap();
|
||||
|
||||
@@ -46,20 +48,14 @@ impl PluginManager {
|
||||
api.set("network", PluginNetwork).unwrap();
|
||||
api.set("dirs", PluginDirs).unwrap();
|
||||
api.set("fs", PluginFileSystem).unwrap();
|
||||
api.set("path", PluginPath).unwrap();
|
||||
api.set("os", PluginOS).unwrap();
|
||||
|
||||
lua.globals().set("plugin_lib", api).unwrap();
|
||||
lua.globals()
|
||||
.set("library_dir", plugin_dir.to_str().unwrap())
|
||||
.unwrap();
|
||||
|
||||
// lua.globals().set("PLUGIN_LOGGER", PluginLogger).unwrap();
|
||||
// lua.globals()
|
||||
// .set("PLUGIN_COMMAND", PluginCommander)
|
||||
// .unwrap();
|
||||
// lua.globals().set("PLUGIN_FS", PluginFileSystem).unwrap();
|
||||
// lua.globals()
|
||||
// .set("PLUGIN_DOWNLOAD", PluginDownloader)
|
||||
// .unwrap();
|
||||
// lua.globals().set("PLUGIN_DIRS", PluginDirs).unwrap();
|
||||
|
||||
let plugin_dir = Self::init_plugin_dir();
|
||||
let mut index: u32 = 1;
|
||||
let mut init_list: Vec<(u32, PathBuf, PluginInfo)> = Vec::new();
|
||||
for entry in std::fs::read_dir(&plugin_dir).ok()? {
|
||||
@@ -77,6 +73,9 @@ impl PluginManager {
|
||||
let info = lua.load(&buffer).eval::<PluginInfo>().unwrap();
|
||||
let _ = manager.set(index, info.clone());
|
||||
|
||||
let dir_name_str = plugin_dir.name().unwrap().to_string();
|
||||
lua.globals().set("current_dir_name", dir_name_str).unwrap();
|
||||
|
||||
// call `on_init` if file "dcp.json" not exists
|
||||
let dcp_file = plugin_dir.join("dcp.json");
|
||||
if !dcp_file.is_file() {
|
||||
@@ -88,9 +87,6 @@ impl PluginManager {
|
||||
}
|
||||
}
|
||||
|
||||
lua.globals()
|
||||
.set("LIBDIR", plugin_dir.join("library").to_str().unwrap())
|
||||
.unwrap();
|
||||
lua.globals().set("manager", manager).unwrap();
|
||||
|
||||
for (idx, path, info) in init_list {
|
||||
@@ -113,14 +109,35 @@ impl PluginManager {
|
||||
Some(Self { lua })
|
||||
}
|
||||
|
||||
pub fn load_all_plugins(&self) -> anyhow::Result<()> {
|
||||
// pub fn load_all_plugins(&self) -> anyhow::Result<()> {
|
||||
// let lua = &self.lua;
|
||||
// let manager = lua.globals().get::<_, Table>("manager")?;
|
||||
// for i in 1..(manager.len()? as i32 + 1) {
|
||||
// let _ = manager.get::<i32, PluginInfo>(i)?;
|
||||
// let code = format!("manager[{i}].on_load()");
|
||||
// lua.load(&code).exec()?;
|
||||
// }
|
||||
// Ok(())
|
||||
// }
|
||||
|
||||
pub fn on_build_event(&self, crate_config: &CrateConfig, platform: &str) -> anyhow::Result<()> {
|
||||
let lua = &self.lua;
|
||||
|
||||
let manager = lua.globals().get::<_, Table>("manager")?;
|
||||
|
||||
let info = json!({
|
||||
"name": crate_config.dioxus_config.application.name,
|
||||
"platform": platform,
|
||||
"out_dir": crate_config.out_dir.to_str().unwrap(),
|
||||
"asset_dir": crate_config.asset_dir.to_str().unwrap(),
|
||||
});
|
||||
|
||||
for i in 1..(manager.len()? as i32 + 1) {
|
||||
let _ = manager.get::<i32, PluginInfo>(i)?;
|
||||
let code = format!("manager[{i}].on_load()");
|
||||
let code = format!("manager[{i}].build.on_start({})", info.to_string());
|
||||
lua.load(&code).exec()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user