feat: add some command
This commit is contained in:
1 parent
9ee572ad26
commit
6004cfdd40
4 files changed
+35
-56
No files matched your search
+6
-35
@@ -18,48 +18,19 @@ impl Plugin {
|
||||
pub async fn plugin(self) -> Result<()> {
|
||||
match self {
|
||||
Plugin::List {} => {
|
||||
for item in tools::tool_list() {
|
||||
if tools::Tool::from_str(item).unwrap().is_installed() {
|
||||
println!("- {item} [installed]");
|
||||
} else {
|
||||
println!("- {item}");
|
||||
}
|
||||
for item in crate::plugin::PluginManager::plugin_list() {
|
||||
println!("- {item}");
|
||||
}
|
||||
}
|
||||
Plugin::AppPath {} => {
|
||||
if let Some(v) = tools::tools_path().to_str() {
|
||||
if let Some(v) = crate::plugin::PluginManager::init_plugin_dir().to_str() {
|
||||
println!("{}", v);
|
||||
} else {
|
||||
log::error!("Tools path get failed.");
|
||||
log::error!("Plugin path get failed.");
|
||||
}
|
||||
}
|
||||
Plugin::Add { name } => {
|
||||
let tool_list = tools::tool_list();
|
||||
|
||||
if !tool_list.contains(&name.as_str()) {
|
||||
log::error!("Tool {name} not found.");
|
||||
return Ok(());
|
||||
}
|
||||
let target_tool = tools::Tool::from_str(&name).unwrap();
|
||||
|
||||
if target_tool.is_installed() {
|
||||
log::warn!("Tool {name} is installed.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
log::info!("Start to download tool package...");
|
||||
if let Err(e) = target_tool.download_package().await {
|
||||
log::error!("Tool download failed: {e}");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
log::info!("Start to install tool package...");
|
||||
if let Err(e) = target_tool.install_package().await {
|
||||
log::error!("Tool install failed: {e}");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
log::info!("Tool {name} install successfully!");
|
||||
Plugin::Add { name: _ } => {
|
||||
log::info!("You can use `dioxus plugin app-path` to get Installation position");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
+2
-2
@@ -12,8 +12,8 @@ async fn main() -> Result<()> {
|
||||
required: vec![],
|
||||
});
|
||||
|
||||
if !plugin_state {
|
||||
log::error!("🚫 Plugin system initialization failed");
|
||||
if let Err(e) = plugin_state {
|
||||
log::error!("🚫 Plugin system initialization failed: {e}");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
+24
-16
@@ -37,18 +37,13 @@ pub struct PluginConfig {
|
||||
pub struct PluginManager;
|
||||
|
||||
impl PluginManager {
|
||||
pub fn init(config: &PluginConfig) -> bool {
|
||||
|
||||
let lua = if let Ok(v) = LUA.lock() {
|
||||
v
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
pub fn init(config: &PluginConfig) -> anyhow::Result<()> {
|
||||
let lua = LUA.lock().unwrap();
|
||||
|
||||
if !config.available {
|
||||
// // if plugin system is available, just set manager to nil.
|
||||
// lua.globals().set("manager", mlua::Value::Nil).unwrap();
|
||||
return true;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let manager = lua.create_table().unwrap();
|
||||
@@ -71,11 +66,7 @@ impl PluginManager {
|
||||
|
||||
let mut index: u32 = 1;
|
||||
let mut init_list: Vec<(u32, PathBuf, PluginInfo)> = Vec::new();
|
||||
let dirs = if let Ok(v) = std::fs::read_dir(&plugin_dir) {
|
||||
v
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
let dirs = std::fs::read_dir(&plugin_dir)?;
|
||||
for entry in dirs {
|
||||
if entry.is_err() {
|
||||
continue;
|
||||
@@ -132,11 +123,10 @@ impl PluginManager {
|
||||
file.write_all(buffer).unwrap();
|
||||
}
|
||||
}
|
||||
true
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn on_build_start(crate_config: &CrateConfig, platform: &str) -> anyhow::Result<()> {
|
||||
|
||||
let lua = LUA.lock().unwrap();
|
||||
|
||||
if !lua.globals().contains_key("manager")? {
|
||||
@@ -249,7 +239,7 @@ impl PluginManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn init_plugin_dir() -> PathBuf {
|
||||
pub fn init_plugin_dir() -> PathBuf {
|
||||
let app_path = app_path();
|
||||
let plugin_path = app_path.join("plugins");
|
||||
if !plugin_path.is_dir() {
|
||||
@@ -259,4 +249,22 @@ impl PluginManager {
|
||||
}
|
||||
plugin_path
|
||||
}
|
||||
|
||||
pub fn plugin_list() -> Vec<String> {
|
||||
let mut res = vec![];
|
||||
|
||||
let app_path = app_path();
|
||||
let plugin_path = app_path.join("plugins");
|
||||
|
||||
let child_dirs = std::fs::read_dir(plugin_path).unwrap();
|
||||
for p in child_dirs {
|
||||
if let Ok(p) = p {
|
||||
if p.path().is_dir() && p.file_name() != "library" {
|
||||
res.push(p.file_name().to_str().unwrap().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -18,9 +18,9 @@ pub enum Tool {
|
||||
Tailwind,
|
||||
}
|
||||
|
||||
pub fn tool_list() -> Vec<&'static str> {
|
||||
vec!["binaryen", "sass", "tailwindcss"]
|
||||
}
|
||||
// pub fn tool_list() -> Vec<&'static str> {
|
||||
// vec!["binaryen", "sass", "tailwindcss"]
|
||||
// }
|
||||
|
||||
pub fn app_path() -> PathBuf {
|
||||
let data_local = dirs::data_local_dir().unwrap();
|
||||
|
||||
Reference in new issue
Block a user