feat: commit lua code
This commit is contained in:
1 parent
ca8855b168
commit
bd2853a194
7 files changed
+135
-37
No files matched your search
Vendored
+5
-1
@@ -1 +1,5 @@
|
|||||||
{}
|
{
|
||||||
|
"Lua.diagnostics.globals": [
|
||||||
|
"plugin_logger"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
local api = require("interface")
|
||||||
|
local log = api.log;
|
||||||
|
|
||||||
|
Manager = {}
|
||||||
|
|
||||||
|
Manager.info = {
|
||||||
|
name = "Dioxus-CLI Plugin Demo",
|
||||||
|
repository = "http://github.com/DioxusLabs/cli",
|
||||||
|
author = "YuKun Liu <mrxzx.info@gmail.com>",
|
||||||
|
}
|
||||||
|
|
||||||
|
Manager.onbuild = function ()
|
||||||
|
print("")
|
||||||
|
end
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
local interface = {}
|
||||||
|
|
||||||
|
if plugin_logger ~= nil then
|
||||||
|
interface.log = plugin_logger
|
||||||
|
else
|
||||||
|
interface.log = {
|
||||||
|
trace = function (info)
|
||||||
|
print("trace: " .. info)
|
||||||
|
end,
|
||||||
|
debug = function (info)
|
||||||
|
print("debug: " .. info)
|
||||||
|
end,
|
||||||
|
info = function (info)
|
||||||
|
print("info: " .. info)
|
||||||
|
end,
|
||||||
|
warn = function (info)
|
||||||
|
print("warn: " .. info)
|
||||||
|
end,
|
||||||
|
error = function (info)
|
||||||
|
print("error: " .. info)
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
return interface
|
||||||
+3
-20
@@ -40,25 +40,8 @@ script = []
|
|||||||
# serve: [dev-server] only
|
# serve: [dev-server] only
|
||||||
script = []
|
script = []
|
||||||
|
|
||||||
[application.tools]
|
[application.plugins]
|
||||||
|
|
||||||
# use binaryen.wasm-opt for output Wasm file
|
available = true
|
||||||
# binaryen just will trigger in `web` platform
|
|
||||||
binaryen = { wasm_opt = true }
|
|
||||||
|
|
||||||
# use sass auto will auto check sass file and build it.
|
required = []
|
||||||
|
|
||||||
|
|
||||||
# [application.tools.sass]
|
|
||||||
|
|
||||||
# auto will check the assets dirs, and auto to transform all scss file to css file.
|
|
||||||
# input = "*"
|
|
||||||
|
|
||||||
# or you can specify some scss file -> css file
|
|
||||||
# input = [
|
|
||||||
# # some sass file path
|
|
||||||
# # this file will translate to `/css/test.css`
|
|
||||||
# "/css/test.scss"
|
|
||||||
# ]
|
|
||||||
|
|
||||||
# source_map = true
|
|
||||||
+7
-16
@@ -1,4 +1,4 @@
|
|||||||
use crate::error::Result;
|
use crate::{error::Result, plugin::PluginConfig};
|
||||||
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};
|
||||||
|
|
||||||
@@ -34,7 +34,10 @@ impl Default for DioxusConfig {
|
|||||||
default_platform: "web".to_string(),
|
default_platform: "web".to_string(),
|
||||||
out_dir: Some(PathBuf::from("dist")),
|
out_dir: Some(PathBuf::from("dist")),
|
||||||
asset_dir: Some(PathBuf::from("public")),
|
asset_dir: Some(PathBuf::from("public")),
|
||||||
|
|
||||||
tools: None,
|
tools: None,
|
||||||
|
plugins: None,
|
||||||
|
|
||||||
sub_package: None,
|
sub_package: None,
|
||||||
},
|
},
|
||||||
web: WebConfig {
|
web: WebConfig {
|
||||||
@@ -66,7 +69,10 @@ pub struct ApplicationConfig {
|
|||||||
pub default_platform: String,
|
pub default_platform: String,
|
||||||
pub out_dir: Option<PathBuf>,
|
pub out_dir: Option<PathBuf>,
|
||||||
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>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,19 +224,4 @@ impl CrateConfig {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub fn with_build_options(&mut self, options: &BuildOptions) {
|
|
||||||
// if let Some(name) = &options.example {
|
|
||||||
// self.as_example(name.clone());
|
|
||||||
// }
|
|
||||||
// self.release = options.release;
|
|
||||||
// self.out_dir = options.outdir.clone().into();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn with_develop_options(&mut self, options: &DevelopOptions) {
|
|
||||||
// if let Some(name) = &options.example {
|
|
||||||
// self.as_example(name.clone());
|
|
||||||
// }
|
|
||||||
// self.release = options.release;
|
|
||||||
// self.out_dir = tempfile::Builder::new().tempdir().expect("").into_path();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
use log;
|
||||||
|
use mlua::UserData;
|
||||||
|
|
||||||
|
pub struct PluginLogger;
|
||||||
|
impl UserData for PluginLogger {
|
||||||
|
fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) {
|
||||||
|
methods.add_function("trace", |_, info: String| {
|
||||||
|
log::trace!("{}", info);
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
methods.add_function("info", |_, info: String| {
|
||||||
|
log::info!("{}", info);
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
methods.add_function("debug", |_, info: String| {
|
||||||
|
log::debug!("{}", info);
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
methods.add_function("warn", |_, info: String| {
|
||||||
|
log::warn!("{}", info);
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
methods.add_function("error", |_, info: String| {
|
||||||
|
log::error!("{}", info);
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
use std::{fs::create_dir_all, path::PathBuf};
|
||||||
|
|
||||||
|
use anyhow::Ok;
|
||||||
|
use mlua::Lua;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
|
use crate::tools::app_path;
|
||||||
|
|
||||||
|
pub mod log;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct PluginConfig {
|
||||||
|
available: bool,
|
||||||
|
required: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PluginManager {
|
||||||
|
lua: Lua,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PluginManager {
|
||||||
|
pub fn init(config: &PluginConfig) -> Option<Self> {
|
||||||
|
if config.available {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let lua = Lua::new();
|
||||||
|
|
||||||
|
let manager = lua.create_table().ok()?;
|
||||||
|
|
||||||
|
let plugin_dir = Self::init_plugin_dir();
|
||||||
|
for entry in WalkDir::new(plugin_dir).into_iter().filter_map(|e| e.ok()) {
|
||||||
|
let plugin_dir = entry.path().to_path_buf();
|
||||||
|
if plugin_dir.is_dir() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.globals().set("manager", manager).ok()?;
|
||||||
|
|
||||||
|
Some(Self { lua })
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init_plugin_dir() -> PathBuf {
|
||||||
|
let app_path = app_path();
|
||||||
|
let plugin_path = app_path.join("plugins");
|
||||||
|
if !plugin_path.is_dir() {
|
||||||
|
create_dir_all(&plugin_path).unwrap();
|
||||||
|
}
|
||||||
|
plugin_path
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user