13 files changed
+81
-55
No files matched your search
@@ -50,7 +50,7 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
|
|||||||
log::info!("🚅 Running build command...");
|
log::info!("🚅 Running build command...");
|
||||||
let cmd = subprocess::Exec::cmd("cargo");
|
let cmd = subprocess::Exec::cmd("cargo");
|
||||||
let cmd = cmd
|
let cmd = cmd
|
||||||
.cwd(&crate_dir)
|
.cwd(crate_dir)
|
||||||
.arg("build")
|
.arg("build")
|
||||||
.arg("--target")
|
.arg("--target")
|
||||||
.arg("wasm32-unknown-unknown")
|
.arg("wasm32-unknown-unknown")
|
||||||
@@ -152,7 +152,7 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
|
|||||||
"-o",
|
"-o",
|
||||||
target_file.to_str().unwrap(),
|
target_file.to_str().unwrap(),
|
||||||
];
|
];
|
||||||
if config.release == true {
|
if config.release {
|
||||||
args.push("-Oz");
|
args.push("-Oz");
|
||||||
}
|
}
|
||||||
binaryen.call("wasm-opt", args)?;
|
binaryen.call("wasm-opt", args)?;
|
||||||
@@ -192,7 +192,7 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
|
|||||||
config_path,
|
config_path,
|
||||||
];
|
];
|
||||||
|
|
||||||
if config.release == true {
|
if config.release {
|
||||||
args.push("--minify");
|
args.push("--minify");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,7 +215,7 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
|
|||||||
depth: 0,
|
depth: 0,
|
||||||
};
|
};
|
||||||
if asset_dir.is_dir() {
|
if asset_dir.is_dir() {
|
||||||
for entry in std::fs::read_dir(&asset_dir)? {
|
for entry in std::fs::read_dir(asset_dir)? {
|
||||||
let path = entry?.path();
|
let path = entry?.path();
|
||||||
if path.is_file() {
|
if path.is_file() {
|
||||||
std::fs::copy(&path, out_dir.join(path.file_name().unwrap()))?;
|
std::fs::copy(&path, out_dir.join(path.file_name().unwrap()))?;
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ impl Metadata {
|
|||||||
/// TODO @Jon, find a different way that doesn't rely on the cargo metadata command (it's slow)
|
/// TODO @Jon, find a different way that doesn't rely on the cargo metadata command (it's slow)
|
||||||
pub fn get() -> Result<Self> {
|
pub fn get() -> Result<Self> {
|
||||||
let output = Command::new("cargo")
|
let output = Command::new("cargo")
|
||||||
.args(&["metadata"])
|
.args(["metadata"])
|
||||||
.output()
|
.output()
|
||||||
.map_err(|_| Error::CargoError("Manifset".to_string()))?;
|
.map_err(|_| Error::CargoError("Manifset".to_string()))?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use futures::{stream::FuturesUnordered, StreamExt};
|
use futures::{stream::FuturesUnordered, StreamExt};
|
||||||
use std::{fs, process::exit};
|
use std::{fs, path::Path, process::exit};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ async fn autoformat_project(check: bool) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_rs_files(folder: &PathBuf, files: &mut Vec<PathBuf>) {
|
fn collect_rs_files(folder: &Path, files: &mut Vec<PathBuf>) {
|
||||||
let Ok(folder) = folder.read_dir() else { return };
|
let Ok(folder) = folder.read_dir() else { return };
|
||||||
|
|
||||||
// load the gitignore
|
// load the gitignore
|
||||||
@@ -157,7 +157,33 @@ fn collect_rs_files(folder: &PathBuf, files: &mut Vec<PathBuf>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[tokio::test]
|
||||||
|
async fn test_auto_fmt() {
|
||||||
|
let test_rsx = r#"
|
||||||
|
//
|
||||||
|
|
||||||
|
rsx! {
|
||||||
|
|
||||||
|
div {}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
"#
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
let fmt = Autoformat {
|
||||||
|
check: false,
|
||||||
|
raw: Some(test_rsx),
|
||||||
|
file: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
fmt.autoformat().await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*#[test]
|
||||||
fn spawn_properly() {
|
fn spawn_properly() {
|
||||||
let out = Command::new("dioxus")
|
let out = Command::new("dioxus")
|
||||||
.args([
|
.args([
|
||||||
@@ -181,4 +207,4 @@ rsx! {
|
|||||||
.expect("failed to execute process");
|
.expect("failed to execute process");
|
||||||
|
|
||||||
dbg!(out);
|
dbg!(out);
|
||||||
}
|
}*/
|
||||||
@@ -11,9 +11,11 @@ pub struct Create {
|
|||||||
|
|
||||||
impl Create {
|
impl Create {
|
||||||
pub fn create(self) -> Result<()> {
|
pub fn create(self) -> Result<()> {
|
||||||
let mut args = GenerateArgs::default();
|
let args = GenerateArgs {
|
||||||
args.template_path = TemplatePath {
|
template_path: TemplatePath {
|
||||||
auto_path: Some(self.template),
|
auto_path: Some(self.template),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,10 +67,8 @@ impl Create {
|
|||||||
fn remove_tripple_newlines(string: &str) -> String {
|
fn remove_tripple_newlines(string: &str) -> String {
|
||||||
let mut new_string = String::new();
|
let mut new_string = String::new();
|
||||||
for char in string.chars() {
|
for char in string.chars() {
|
||||||
if char == '\n' {
|
if char == '\n' && new_string.ends_with("\n\n") {
|
||||||
if new_string.ends_with("\n\n") {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
new_string.push(char);
|
new_string.push(char);
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-12
@@ -19,6 +19,7 @@ use clap::{Parser, Subcommand};
|
|||||||
use html_parser::Dom;
|
use html_parser::Dom;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{
|
use std::{
|
||||||
|
fmt::Display,
|
||||||
fs::{remove_dir_all, File},
|
fs::{remove_dir_all, File},
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
@@ -71,19 +72,18 @@ pub enum Commands {
|
|||||||
Plugin(plugin::Plugin),
|
Plugin(plugin::Plugin),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Commands {
|
impl Display for Commands {
|
||||||
pub fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Commands::Build(_) => "build",
|
Commands::Build(_) => write!(f, "build"),
|
||||||
Commands::Translate(_) => "translate",
|
Commands::Translate(_) => write!(f, "translate"),
|
||||||
Commands::Serve(_) => "serve",
|
Commands::Serve(_) => write!(f, "serve"),
|
||||||
Commands::Create(_) => "create",
|
Commands::Create(_) => write!(f, "create"),
|
||||||
Commands::Clean(_) => "clean",
|
Commands::Clean(_) => write!(f, "clean"),
|
||||||
Commands::Config(_) => "config",
|
Commands::Config(_) => write!(f, "config"),
|
||||||
Commands::Plugin(_) => "plugin",
|
Commands::Plugin(_) => write!(f, "plugin"),
|
||||||
Commands::Version(_) => "version",
|
Commands::Version(_) => write!(f, "version"),
|
||||||
Commands::Autoformat(_) => "fmt",
|
Commands::Autoformat(_) => write!(f, "fmt"),
|
||||||
}
|
}
|
||||||
.to_string()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ impl Translate {
|
|||||||
|
|
||||||
// Write the output
|
// Write the output
|
||||||
match self.output {
|
match self.output {
|
||||||
Some(output) => std::fs::write(&output, out)?,
|
Some(output) => std::fs::write(output, out)?,
|
||||||
None => print!("{}", out),
|
None => print!("{}", out),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ impl Translate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_html_to_formatted_rsx(dom: &Dom, component: bool) -> String {
|
pub fn convert_html_to_formatted_rsx(dom: &Dom, component: bool) -> String {
|
||||||
let callbody = rsx_rosetta::rsx_from_html(&dom);
|
let callbody = rsx_rosetta::rsx_from_html(dom);
|
||||||
|
|
||||||
match component {
|
match component {
|
||||||
true => write_callbody_with_icon_section(callbody),
|
true => write_callbody_with_icon_section(callbody),
|
||||||
@@ -114,7 +114,7 @@ fn determine_input(file: Option<String>, raw: Option<String>) -> Result<String>
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(file) = file {
|
if let Some(file) = file {
|
||||||
return Ok(std::fs::read_to_string(&file)?);
|
return Ok(std::fs::read_to_string(file)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If neither exist, we try to read from stdin
|
// If neither exist, we try to read from stdin
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ impl CrateConfig {
|
|||||||
None => crate_dir.join("public"),
|
None => crate_dir.join("public"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let manifest = cargo_toml::Manifest::from_path(&cargo_def).unwrap();
|
let manifest = cargo_toml::Manifest::from_path(cargo_def).unwrap();
|
||||||
|
|
||||||
let output_filename = {
|
let output_filename = {
|
||||||
match &manifest.package.as_ref().unwrap().default_run {
|
match &manifest.package.as_ref().unwrap().default_run {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use std::process::{Command, Stdio};
|
|||||||
|
|
||||||
use mlua::{FromLua, UserData};
|
use mlua::{FromLua, UserData};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
enum StdioFromString {
|
enum StdioFromString {
|
||||||
Inherit,
|
Inherit,
|
||||||
Piped,
|
Piped,
|
||||||
@@ -41,7 +42,7 @@ impl UserData for PluginCommander {
|
|||||||
let stdout = args.1;
|
let stdout = args.1;
|
||||||
let stderr = args.2;
|
let stderr = args.2;
|
||||||
|
|
||||||
if cmd.len() == 0 {
|
if cmd.is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let cmd_name = cmd.get(0).unwrap();
|
let cmd_name = cmd.get(0).unwrap();
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ impl UserData for PluginFileSystem {
|
|||||||
let file = PathBuf::from(args.0);
|
let file = PathBuf::from(args.0);
|
||||||
let target = PathBuf::from(args.1);
|
let target = PathBuf::from(args.1);
|
||||||
let res = extract_zip(&file, &target);
|
let res = extract_zip(&file, &target);
|
||||||
if let Err(_) = res {
|
if res.is_err() {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
Ok(true)
|
Ok(true)
|
||||||
|
|||||||
@@ -18,10 +18,11 @@ impl UserData for PluginPath {
|
|||||||
methods.add_function("parent", |_, path: String| {
|
methods.add_function("parent", |_, path: String| {
|
||||||
let current_path = PathBuf::from(&path);
|
let current_path = PathBuf::from(&path);
|
||||||
let parent = current_path.parent();
|
let parent = current_path.parent();
|
||||||
if parent.is_none() {
|
|
||||||
return Ok(path);
|
if let Some(parent) = parent {
|
||||||
|
Ok(parent.to_str().unwrap().to_string())
|
||||||
} else {
|
} else {
|
||||||
return Ok(parent.unwrap().to_str().unwrap().to_string());
|
Ok(path)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
methods.add_function("exists", |_, path: String| {
|
methods.add_function("exists", |_, path: String| {
|
||||||
|
|||||||
@@ -151,14 +151,12 @@ impl PluginManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if let Ok(index) = name_index.get::<_, u32>(info.name.clone()) {
|
||||||
|
let _ = manager.set(index, info.clone());
|
||||||
} else {
|
} else {
|
||||||
if let Ok(index) = name_index.get::<_, u32>(info.name.clone()) {
|
let _ = manager.set(index, info.clone());
|
||||||
let _ = manager.set(index, info.clone());
|
index += 1;
|
||||||
} else {
|
let _ = name_index.set(info.name, index);
|
||||||
let _ = manager.set(index, info.clone());
|
|
||||||
index += 1;
|
|
||||||
let _ = name_index.set(info.name, index);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_e) => {
|
Err(_e) => {
|
||||||
@@ -172,7 +170,7 @@ impl PluginManager {
|
|||||||
|
|
||||||
lua.globals().set("manager", manager).unwrap();
|
lua.globals().set("manager", manager).unwrap();
|
||||||
|
|
||||||
return Ok(());
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_build_start(crate_config: &CrateConfig, platform: &str) -> anyhow::Result<()> {
|
pub fn on_build_start(crate_config: &CrateConfig, platform: &str) -> anyhow::Result<()> {
|
||||||
|
|||||||
@@ -631,7 +631,7 @@ fn print_console_info(ip: &String, port: u16, config: &CrateConfig, options: Pre
|
|||||||
"\t> Network : {}",
|
"\t> Network : {}",
|
||||||
format!("http://{}:{}/", ip, port).blue()
|
format!("http://{}:{}/", ip, port).blue()
|
||||||
);
|
);
|
||||||
println!("");
|
println!();
|
||||||
println!("\t> Profile : {}", profile.green());
|
println!("\t> Profile : {}", profile.green());
|
||||||
println!("\t> Hot Reload : {}", hot_reload.cyan());
|
println!("\t> Hot Reload : {}", hot_reload.cyan());
|
||||||
if let Some(proxies) = proxies {
|
if let Some(proxies) = proxies {
|
||||||
@@ -644,14 +644,14 @@ fn print_console_info(ip: &String, port: u16, config: &CrateConfig, options: Pre
|
|||||||
}
|
}
|
||||||
println!("\t> Index Template : {}", custom_html_file.green());
|
println!("\t> Index Template : {}", custom_html_file.green());
|
||||||
println!("\t> URL Rewrite [index_on_404] : {}", url_rewrite.purple());
|
println!("\t> URL Rewrite [index_on_404] : {}", url_rewrite.purple());
|
||||||
println!("");
|
println!();
|
||||||
println!(
|
println!(
|
||||||
"\t> Build Time Use : {} millis",
|
"\t> Build Time Use : {} millis",
|
||||||
options.elapsed_time.to_string().green().bold()
|
options.elapsed_time.to_string().green().bold()
|
||||||
);
|
);
|
||||||
println!("");
|
println!();
|
||||||
|
|
||||||
if options.warnings.len() == 0 {
|
if options.warnings.is_empty() {
|
||||||
log::info!("{}\n", "A perfect compilation!".green().bold());
|
log::info!("{}\n", "A perfect compilation!".green().bold());
|
||||||
} else {
|
} else {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
@@ -718,9 +718,9 @@ fn get_ip() -> Option<String> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match socket.local_addr() {
|
match socket.local_addr() {
|
||||||
Ok(addr) => return Some(addr.ip().to_string()),
|
Ok(addr) => Some(addr.ip().to_string()),
|
||||||
Err(_) => return None,
|
Err(_) => None,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn ws_handler(
|
async fn ws_handler(
|
||||||
|
|||||||
@@ -320,11 +320,11 @@ impl Tool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn extract_zip(file: &Path, target: &Path) -> anyhow::Result<()> {
|
pub fn extract_zip(file: &Path, target: &Path) -> anyhow::Result<()> {
|
||||||
let zip_file = std::fs::File::open(&file)?;
|
let zip_file = std::fs::File::open(file)?;
|
||||||
let mut zip = zip::ZipArchive::new(zip_file)?;
|
let mut zip = zip::ZipArchive::new(zip_file)?;
|
||||||
|
|
||||||
if !target.exists() {
|
if !target.exists() {
|
||||||
let _ = std::fs::create_dir_all(target)?;
|
std::fs::create_dir_all(target)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 0..zip.len() {
|
for i in 0..zip.len() {
|
||||||
@@ -332,7 +332,7 @@ pub fn extract_zip(file: &Path, target: &Path) -> anyhow::Result<()> {
|
|||||||
if file.is_dir() {
|
if file.is_dir() {
|
||||||
// dir
|
// dir
|
||||||
let target = target.join(Path::new(&file.name().replace('\\', "")));
|
let target = target.join(Path::new(&file.name().replace('\\', "")));
|
||||||
let _ = std::fs::create_dir_all(target)?;
|
std::fs::create_dir_all(target)?;
|
||||||
} else {
|
} else {
|
||||||
// file
|
// file
|
||||||
let file_path = target.join(Path::new(file.name()));
|
let file_path = target.join(Path::new(file.name()));
|
||||||
|
|||||||
Reference in new issue
Block a user