feat: commit build field
This commit is contained in:
1 parent
6f4028f065
commit
d9891d9f0c
9 files changed
+249
-248
No files matched your search
@@ -1,3 +1,5 @@
|
||||
use crate::plugin::PluginManager;
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Build the Rust WASM app and all of its assets.
|
||||
@@ -9,7 +11,7 @@ pub struct Build {
|
||||
}
|
||||
|
||||
impl Build {
|
||||
pub fn build(self) -> Result<()> {
|
||||
pub fn build(self, plugin_manager: PluginManager) -> Result<()> {
|
||||
let mut crate_config = crate::CrateConfig::new()?;
|
||||
|
||||
// change the release state.
|
||||
@@ -32,6 +34,8 @@ impl Build {
|
||||
.clone()
|
||||
});
|
||||
|
||||
let _ = plugin_manager.on_build_event(&crate_config, &platform);
|
||||
|
||||
match platform.as_str() {
|
||||
"web" => {
|
||||
crate::builder::build(&crate_config, false)?;
|
||||
|
||||
@@ -56,3 +56,17 @@ pub enum Commands {
|
||||
#[clap(subcommand)]
|
||||
Tool(tool::Tool),
|
||||
}
|
||||
|
||||
impl Commands {
|
||||
pub fn to_string(&self) -> String {
|
||||
match self {
|
||||
Commands::Build(_) => "build",
|
||||
Commands::Translate(_) => "translate",
|
||||
Commands::Serve(_) => "sevre",
|
||||
Commands::Create(_) => "create",
|
||||
Commands::Clean(_) => "clean",
|
||||
Commands::Config(_) => "config",
|
||||
Commands::Tool(_) => "tool",
|
||||
}.to_string()
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -11,8 +11,6 @@ async fn main() -> Result<()> {
|
||||
required: vec![],
|
||||
}).unwrap();
|
||||
|
||||
plugin_manager.load_all_plugins().unwrap();
|
||||
|
||||
match args.action {
|
||||
Commands::Translate(opts) => {
|
||||
if let Err(e) = opts.translate() {
|
||||
@@ -21,7 +19,7 @@ async fn main() -> Result<()> {
|
||||
}
|
||||
|
||||
Commands::Build(opts) => {
|
||||
if let Err(e) = opts.build() {
|
||||
if let Err(e) = opts.build(plugin_manager) {
|
||||
log::error!("🚫 Build project failed: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -9,7 +9,7 @@ use axum::{
|
||||
use cargo_metadata::diagnostic::Diagnostic;
|
||||
use colored::Colorize;
|
||||
use dioxus_rsx_interpreter::SetRsxMessage;
|
||||
use notify::{RecommendedWatcher, Watcher};
|
||||
use notify::Watcher;
|
||||
use syn::spanned::Spanned;
|
||||
|
||||
use std::{net::UdpSocket, path::PathBuf, process::Command, sync::Arc};
|
||||
@@ -98,7 +98,7 @@ pub async fn startup_hot_reload(port: u16, config: CrateConfig) -> Result<()> {
|
||||
.unwrap_or_else(|| vec![PathBuf::from("src")]);
|
||||
|
||||
let watcher_config = config.clone();
|
||||
let mut watcher = RecommendedWatcher::new(move |evt: notify::Result<notify::Event>| {
|
||||
let mut watcher = notify::recommended_watcher(move |evt: notify::Result<notify::Event>| {
|
||||
let config = watcher_config.clone();
|
||||
if chrono::Local::now().timestamp() > last_update_time {
|
||||
// Give time for the change to take effect before reading the file
|
||||
@@ -304,7 +304,7 @@ pub async fn startup_default(port: u16, config: CrateConfig) -> Result<()> {
|
||||
.unwrap_or_else(|| vec![PathBuf::from("src")]);
|
||||
|
||||
let watcher_config = config.clone();
|
||||
let mut watcher = RecommendedWatcher::new(move |info: notify::Result<notify::Event>| {
|
||||
let mut watcher = notify::recommended_watcher(move |info: notify::Result<notify::Event>| {
|
||||
let config = watcher_config.clone();
|
||||
if info.is_ok() {
|
||||
if chrono::Local::now().timestamp() > last_update_time {
|
||||
|
||||
Reference in new issue
Block a user