feat: commit code
This commit is contained in:
1 parent
5104f767b3
commit
f238e43bff
3 files changed
+11
-21
No files matched your search
+3
-4
@@ -1,4 +1,4 @@
|
|||||||
use crate::{error::Result, plugin::PluginConfig};
|
use crate::error::Result;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{collections::HashMap, fs::File, io::Read, path::PathBuf};
|
use std::{collections::HashMap, fs::File, io::Read, path::PathBuf};
|
||||||
|
|
||||||
@@ -6,6 +6,7 @@ use std::{collections::HashMap, fs::File, io::Read, path::PathBuf};
|
|||||||
pub struct DioxusConfig {
|
pub struct DioxusConfig {
|
||||||
pub application: ApplicationConfig,
|
pub application: ApplicationConfig,
|
||||||
pub web: WebConfig,
|
pub web: WebConfig,
|
||||||
|
pub plugin: toml::Value,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DioxusConfig {
|
impl DioxusConfig {
|
||||||
@@ -36,7 +37,6 @@ impl Default for DioxusConfig {
|
|||||||
asset_dir: Some(PathBuf::from("public")),
|
asset_dir: Some(PathBuf::from("public")),
|
||||||
|
|
||||||
tools: None,
|
tools: None,
|
||||||
plugins: None,
|
|
||||||
|
|
||||||
sub_package: None,
|
sub_package: None,
|
||||||
},
|
},
|
||||||
@@ -59,6 +59,7 @@ impl Default for DioxusConfig {
|
|||||||
script: Some(vec![]),
|
script: Some(vec![]),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
plugin: toml::Value::Table(toml::map::Map::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,7 +72,6 @@ pub struct ApplicationConfig {
|
|||||||
pub asset_dir: Option<PathBuf>,
|
pub asset_dir: Option<PathBuf>,
|
||||||
|
|
||||||
pub tools: Option<HashMap<String, toml::Value>>,
|
pub tools: Option<HashMap<String, toml::Value>>,
|
||||||
pub plugins: Option<PluginConfig>,
|
|
||||||
|
|
||||||
pub sub_package: Option<String>,
|
pub sub_package: Option<String>,
|
||||||
}
|
}
|
||||||
@@ -223,5 +223,4 @@ impl CrateConfig {
|
|||||||
self.features = Some(features);
|
self.features = Some(features);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+4
-5
@@ -1,5 +1,5 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use dioxus_cli::{*, plugin::{PluginManager, PluginConfig}};
|
use dioxus_cli::{plugin::PluginManager, *};
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@@ -7,10 +7,9 @@ async fn main() -> Result<()> {
|
|||||||
let args = Cli::parse();
|
let args = Cli::parse();
|
||||||
set_up_logging();
|
set_up_logging();
|
||||||
|
|
||||||
let plugin_state = PluginManager::init(&PluginConfig {
|
let dioxus_config = DioxusConfig::load()?;
|
||||||
available: true,
|
|
||||||
required: vec![],
|
let plugin_state = PluginManager::init(dioxus_config.plugin);
|
||||||
});
|
|
||||||
|
|
||||||
if let Err(e) = plugin_state {
|
if let Err(e) = plugin_state {
|
||||||
log::error!("🚫 Plugin system initialization failed: {e}");
|
log::error!("🚫 Plugin system initialization failed: {e}");
|
||||||
|
|||||||
+4
-12
@@ -5,7 +5,6 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use mlua::{AsChunk, Lua, Table};
|
use mlua::{AsChunk, Lua, Table};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -28,23 +27,16 @@ lazy_static::lazy_static! {
|
|||||||
static ref LUA: Mutex<Lua> = Mutex::new(Lua::new());
|
static ref LUA: Mutex<Lua> = Mutex::new(Lua::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
pub struct PluginConfig {
|
|
||||||
pub available: bool,
|
|
||||||
pub required: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct PluginManager;
|
pub struct PluginManager;
|
||||||
|
|
||||||
impl PluginManager {
|
impl PluginManager {
|
||||||
pub fn init(config: &PluginConfig) -> anyhow::Result<()> {
|
pub fn init(config: toml::Value) -> anyhow::Result<()> {
|
||||||
let lua = LUA.lock().unwrap();
|
let lua = LUA.lock().unwrap();
|
||||||
|
|
||||||
if !config.available {
|
if !config.is_table() {
|
||||||
// // if plugin system is available, just set manager to nil.
|
// if plugins config is not a table, then termination init
|
||||||
// lua.globals().set("manager", mlua::Value::Nil).unwrap();
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let manager = lua.create_table().unwrap();
|
let manager = lua.create_table().unwrap();
|
||||||
let plugin_dir = Self::init_plugin_dir();
|
let plugin_dir = Self::init_plugin_dir();
|
||||||
|
|||||||
Reference in new issue
Block a user