replace gitignore with ignore
This commit is contained in:
1 parent
2eec2bc673
commit
f40e2f3cef
5 files changed
+78
-106
No files matched your search
Generated
+2
-10
@@ -2501,11 +2501,11 @@ dependencies = [
|
|||||||
"flate2",
|
"flate2",
|
||||||
"fs_extra",
|
"fs_extra",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"gitignore",
|
|
||||||
"headers 0.3.9",
|
"headers 0.3.9",
|
||||||
"html_parser",
|
"html_parser",
|
||||||
"hyper 0.14.28",
|
"hyper 0.14.28",
|
||||||
"hyper-rustls 0.23.2",
|
"hyper-rustls 0.23.2",
|
||||||
|
"ignore",
|
||||||
"indicatif",
|
"indicatif",
|
||||||
"interprocess-docfix",
|
"interprocess-docfix",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
@@ -2514,6 +2514,7 @@ dependencies = [
|
|||||||
"mlua",
|
"mlua",
|
||||||
"notify",
|
"notify",
|
||||||
"open",
|
"open",
|
||||||
|
"rayon",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rsx-rosetta",
|
"rsx-rosetta",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -4119,15 +4120,6 @@ dependencies = [
|
|||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "gitignore"
|
|
||||||
version = "1.0.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7d051488d9a601181a9b90c9ad8ae7e8251d642ddd2463008f2f5019d255bd89"
|
|
||||||
dependencies = [
|
|
||||||
"glob",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gix-actor"
|
name = "gix-actor"
|
||||||
version = "0.28.1"
|
version = "0.28.1"
|
||||||
|
|||||||
+15
-16
@@ -58,23 +58,23 @@ version = "0.4.3"
|
|||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
dioxus = { path = "packages/dioxus", version = "0.4.0" }
|
dioxus = { path = "packages/dioxus", version = "0.4.0" }
|
||||||
dioxus-core = { path = "packages/core", version = "0.4.2" }
|
dioxus-core = { path = "packages/core", version = "0.4.2" }
|
||||||
dioxus-core-macro = { path = "packages/core-macro", version = "0.4.0" }
|
dioxus-core-macro = { path = "packages/core-macro", version = "0.4.0" }
|
||||||
dioxus-router = { path = "packages/router", version = "0.4.1" }
|
dioxus-router = { path = "packages/router", version = "0.4.1" }
|
||||||
dioxus-router-macro = { path = "packages/router-macro", version = "0.4.1" }
|
dioxus-router-macro = { path = "packages/router-macro", version = "0.4.1" }
|
||||||
dioxus-html = { path = "packages/html", default-features = false, version = "0.4.0" }
|
dioxus-html = { path = "packages/html", default-features = false, version = "0.4.0" }
|
||||||
dioxus-html-internal-macro = { path = "packages/html-internal-macro", version = "0.4.0" }
|
dioxus-html-internal-macro = { path = "packages/html-internal-macro", version = "0.4.0" }
|
||||||
dioxus-hooks = { path = "packages/hooks", version = "0.4.0" }
|
dioxus-hooks = { path = "packages/hooks", version = "0.4.0" }
|
||||||
dioxus-web = { path = "packages/web", version = "0.4.0" }
|
dioxus-web = { path = "packages/web", version = "0.4.0" }
|
||||||
dioxus-ssr = { path = "packages/ssr", version = "0.4.0" }
|
dioxus-ssr = { path = "packages/ssr", version = "0.4.0" }
|
||||||
dioxus-desktop = { path = "packages/desktop", version = "0.4.0" }
|
dioxus-desktop = { path = "packages/desktop", version = "0.4.0" }
|
||||||
dioxus-mobile = { path = "packages/mobile", version = "0.4.0" }
|
dioxus-mobile = { path = "packages/mobile", version = "0.4.0" }
|
||||||
dioxus-interpreter-js = { path = "packages/interpreter", version = "0.4.0" }
|
dioxus-interpreter-js = { path = "packages/interpreter", version = "0.4.0" }
|
||||||
fermi = { path = "packages/fermi", version = "0.4.0" }
|
fermi = { path = "packages/fermi", version = "0.4.0" }
|
||||||
dioxus-liveview = { path = "packages/liveview", version = "0.4.0" }
|
dioxus-liveview = { path = "packages/liveview", version = "0.4.0" }
|
||||||
dioxus-autofmt = { path = "packages/autofmt", version = "0.4.0" }
|
dioxus-autofmt = { path = "packages/autofmt", version = "0.4.0" }
|
||||||
dioxus-check = { path = "packages/check", version = "0.4.0" }
|
dioxus-check = { path = "packages/check", version = "0.4.0" }
|
||||||
dioxus-rsx = { path = "packages/rsx", version = "0.4.0" }
|
dioxus-rsx = { path = "packages/rsx", version = "0.4.0" }
|
||||||
dioxus-tui = { path = "packages/dioxus-tui", version = "0.4.0" }
|
dioxus-tui = { path = "packages/dioxus-tui", version = "0.4.0" }
|
||||||
plasmo = { path = "packages/rink", version = "0.4.0" }
|
plasmo = { path = "packages/rink", version = "0.4.0" }
|
||||||
dioxus-native-core = { path = "packages/native-core", version = "0.4.0" }
|
dioxus-native-core = { path = "packages/native-core", version = "0.4.0" }
|
||||||
dioxus-native-core-macro = { path = "packages/native-core-macro", version = "0.4.0" }
|
dioxus-native-core-macro = { path = "packages/native-core-macro", version = "0.4.0" }
|
||||||
@@ -83,7 +83,7 @@ dioxus-signals = { path = "packages/signals" }
|
|||||||
dioxus-cli-config = { path = "packages/cli-config", version = "0.4.1" }
|
dioxus-cli-config = { path = "packages/cli-config", version = "0.4.1" }
|
||||||
generational-box = { path = "packages/generational-box", version = "0.4.3" }
|
generational-box = { path = "packages/generational-box", version = "0.4.3" }
|
||||||
dioxus-hot-reload = { path = "packages/hot-reload", version = "0.4.0" }
|
dioxus-hot-reload = { path = "packages/hot-reload", version = "0.4.0" }
|
||||||
dioxus-fullstack = { path = "packages/fullstack", version = "0.4.1" }
|
dioxus-fullstack = { path = "packages/fullstack", version = "0.4.1" }
|
||||||
dioxus_server_macro = { path = "packages/server-macro", version = "0.4.1" }
|
dioxus_server_macro = { path = "packages/server-macro", version = "0.4.1" }
|
||||||
tracing = "0.1.37"
|
tracing = "0.1.37"
|
||||||
tracing-futures = "0.2.5"
|
tracing-futures = "0.2.5"
|
||||||
@@ -144,4 +144,3 @@ thiserror = { workspace = true }
|
|||||||
manganis = { workspace = true }
|
manganis = { workspace = true }
|
||||||
tracing-subscriber = "0.3.17"
|
tracing-subscriber = "0.3.17"
|
||||||
http-range = "0.1.5"
|
http-range = "0.1.5"
|
||||||
|
|
||||||
@@ -240,3 +240,10 @@ pub(crate) fn write_ifmt(input: &IfmtInput, writable: &mut impl Write) -> std::f
|
|||||||
let display = DisplayIfmt(input);
|
let display = DisplayIfmt(input);
|
||||||
write!(writable, "{}", display)
|
write!(writable, "{}", display)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Call rustfmt to format code, i32 as exitcode
|
||||||
|
pub fn rustfmt(input: &str) -> Option<String> {
|
||||||
|
let syntax_tree = syn::parse_file(input).ok()?;
|
||||||
|
let output = prettyplease::unparse(&syntax_tree);
|
||||||
|
Some(output)
|
||||||
|
}
|
||||||
@@ -26,7 +26,7 @@ fs_extra = "1.2.0"
|
|||||||
cargo_toml = "0.18.0"
|
cargo_toml = "0.18.0"
|
||||||
futures-util.workspace = true
|
futures-util.workspace = true
|
||||||
notify = { version = "5.0.0-pre.16", features = ["serde"] }
|
notify = { version = "5.0.0-pre.16", features = ["serde"] }
|
||||||
html_parser = { workspace = true }
|
html_parser = { workspace = true }
|
||||||
cargo_metadata = "0.18.1"
|
cargo_metadata = "0.18.1"
|
||||||
tokio = { version = "1.16.1", features = ["fs", "sync", "rt", "macros"] }
|
tokio = { version = "1.16.1", features = ["fs", "sync", "rt", "macros"] }
|
||||||
atty = "0.2.14"
|
atty = "0.2.14"
|
||||||
@@ -36,6 +36,7 @@ hyper = "0.14.17"
|
|||||||
hyper-rustls = "0.23.2"
|
hyper-rustls = "0.23.2"
|
||||||
indicatif = "0.17.5"
|
indicatif = "0.17.5"
|
||||||
subprocess = "0.2.9"
|
subprocess = "0.2.9"
|
||||||
|
rayon = "1.8.0"
|
||||||
|
|
||||||
axum = { version = "0.5.1", features = ["ws", "headers"] }
|
axum = { version = "0.5.1", features = ["ws", "headers"] }
|
||||||
axum-server = { version = "0.5.1", features = ["tls-rustls"] }
|
axum-server = { version = "0.5.1", features = ["tls-rustls"] }
|
||||||
@@ -84,7 +85,7 @@ dioxus-html = { workspace = true, features = ["hot-reload-context"] }
|
|||||||
dioxus-core = { workspace = true, features = ["serialize"] }
|
dioxus-core = { workspace = true, features = ["serialize"] }
|
||||||
dioxus-hot-reload = { workspace = true }
|
dioxus-hot-reload = { workspace = true }
|
||||||
interprocess-docfix = { version = "1.2.2" }
|
interprocess-docfix = { version = "1.2.2" }
|
||||||
gitignore = "1.0.8"
|
ignore = "0.4.22"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use dioxus_autofmt::{IndentOptions, IndentType};
|
use dioxus_autofmt::{IndentOptions, IndentType};
|
||||||
use futures_util::{stream::FuturesUnordered, StreamExt};
|
use rayon::prelude::*;
|
||||||
use std::{fs, path::Path, process::exit};
|
use std::{fs, io, path::Path, process::exit};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@@ -40,13 +40,14 @@ impl Autoformat {
|
|||||||
raw,
|
raw,
|
||||||
file,
|
file,
|
||||||
split_line_attributes,
|
split_line_attributes,
|
||||||
rustfmt,
|
rustfmt: do_rustfmt,
|
||||||
..
|
..
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
// Default to formatting the project
|
// Default to formatting the project
|
||||||
if raw.is_none() && file.is_none() {
|
if raw.is_none() && file.is_none() {
|
||||||
if let Err(e) = autoformat_project(check, split_line_attributes).await {
|
println!("format project !");
|
||||||
|
if let Err(e) = autoformat_project(check, split_line_attributes, do_rustfmt).await {
|
||||||
eprintln!("error formatting project: {}", e);
|
eprintln!("error formatting project: {}", e);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -65,46 +66,13 @@ impl Autoformat {
|
|||||||
|
|
||||||
// Format single file
|
// Format single file
|
||||||
if let Some(file) = file {
|
if let Some(file) = file {
|
||||||
refactor_file(file, split_line_attributes, rustfmt)?;
|
refactor_file(file, split_line_attributes, do_rustfmt)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call rustfmt to format code, i32 as exitcode
|
|
||||||
fn rustfmt(input: String) -> Result<String> {
|
|
||||||
use std::thread;
|
|
||||||
|
|
||||||
let mut child = Command::new("rustfmt")
|
|
||||||
.stdin(Stdio::piped())
|
|
||||||
.stdout(Stdio::piped())
|
|
||||||
.spawn()
|
|
||||||
.map_err(|e| Error::IO(e))?;
|
|
||||||
|
|
||||||
let mut stdin = child.stdin.take().unwrap();
|
|
||||||
let pass_in = input.to_string();
|
|
||||||
let handle = thread::spawn(move || -> Result<()> {
|
|
||||||
stdin
|
|
||||||
.write_all(pass_in.as_bytes())
|
|
||||||
.map_err(|e| Error::IO(e))?;
|
|
||||||
Ok(())
|
|
||||||
});
|
|
||||||
handle.join().unwrap()?;
|
|
||||||
|
|
||||||
let output = child.wait_with_output().map_err(|e| Error::IO(e))?;
|
|
||||||
|
|
||||||
if let Some(exit_code) = output.status.code() {
|
|
||||||
if exit_code != 0 {
|
|
||||||
return Err(Error::ExitCodeNotZero(exit_code));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let output = String::from_utf8(output.stdout).map_err(|e| Error::Other(e.into()))?;
|
|
||||||
|
|
||||||
Ok(output)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn refactor_file(file: String, split_line_attributes: bool, do_rustfmt: bool) -> Result<(), Error> {
|
fn refactor_file(file: String, split_line_attributes: bool, do_rustfmt: bool) -> Result<(), Error> {
|
||||||
let indent = indentation_for(".", split_line_attributes)?;
|
let indent = indentation_for(".", split_line_attributes)?;
|
||||||
let file_content = if file == "-" {
|
let file_content = if file == "-" {
|
||||||
@@ -120,7 +88,7 @@ fn refactor_file(file: String, split_line_attributes: bool, do_rustfmt: bool) ->
|
|||||||
};
|
};
|
||||||
|
|
||||||
if do_rustfmt {
|
if do_rustfmt {
|
||||||
s = rustfmt(s)?;
|
s = dioxus_autofmt::rustfmt(&s).ok_or_else(|| Error::ParseError("Syntax Error".into()))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let edits = dioxus_autofmt::fmt_file(&s, indent);
|
let edits = dioxus_autofmt::fmt_file(&s, indent);
|
||||||
@@ -137,25 +105,21 @@ fn refactor_file(file: String, split_line_attributes: bool, do_rustfmt: bool) ->
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_project_files(config: &CrateConfig) -> Vec<PathBuf> {
|
use std::ffi::OsStr;
|
||||||
let mut files = vec![];
|
fn get_project_files() -> Vec<PathBuf> {
|
||||||
|
let mut files = Vec::new();
|
||||||
let gitignore_path = config.crate_dir.join(".gitignore");
|
for result in ignore::Walk::new("./") {
|
||||||
if gitignore_path.is_file() {
|
let path = result.unwrap().into_path();
|
||||||
let gitigno = gitignore::File::new(gitignore_path.as_path()).unwrap();
|
if let Some(ext) = path.extension() {
|
||||||
if let Ok(git_files) = gitigno.included_files() {
|
if ext == OsStr::new("rs") {
|
||||||
let git_files = git_files
|
files.push(path);
|
||||||
.into_iter()
|
}
|
||||||
.filter(|f| f.ends_with(".rs") && !is_target_dir(f));
|
}
|
||||||
files.extend(git_files)
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
collect_rs_files(&config.crate_dir, &mut files);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
files
|
files
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
fn is_target_dir(file: &Path) -> bool {
|
fn is_target_dir(file: &Path) -> bool {
|
||||||
let stripped = if let Ok(cwd) = std::env::current_dir() {
|
let stripped = if let Ok(cwd) = std::env::current_dir() {
|
||||||
file.strip_prefix(cwd).unwrap_or(file)
|
file.strip_prefix(cwd).unwrap_or(file)
|
||||||
@@ -169,18 +133,30 @@ fn is_target_dir(file: &Path) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn format_file(
|
fn format_file(path: impl AsRef<Path>, indent: IndentOptions, do_rustfmt: bool) -> Result<usize> {
|
||||||
path: impl AsRef<Path>,
|
let mut contents = fs::read_to_string(&path)?;
|
||||||
indent: IndentOptions,
|
let mut if_write = false;
|
||||||
) -> Result<usize, tokio::io::Error> {
|
if do_rustfmt {
|
||||||
let contents = tokio::fs::read_to_string(&path).await?;
|
let formatted = dioxus_autofmt::rustfmt(&contents)
|
||||||
|
.ok_or_else(|| Error::ParseError("Syntax Error".into()))?;
|
||||||
|
if contents != formatted {
|
||||||
|
if_write = true;
|
||||||
|
contents = formatted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("at {} : {:#?}", path.as_ref().display(), &contents);
|
||||||
|
|
||||||
let edits = dioxus_autofmt::fmt_file(&contents, indent);
|
let edits = dioxus_autofmt::fmt_file(&contents, indent);
|
||||||
let len = edits.len();
|
let len = edits.len();
|
||||||
|
|
||||||
if !edits.is_empty() {
|
if !edits.is_empty() {
|
||||||
|
if_write = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if if_write {
|
||||||
let out = dioxus_autofmt::apply_formats(&contents, edits);
|
let out = dioxus_autofmt::apply_formats(&contents, edits);
|
||||||
tokio::fs::write(path, out).await?;
|
fs::write(path, out)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(len)
|
Ok(len)
|
||||||
@@ -190,11 +166,15 @@ async fn format_file(
|
|||||||
///
|
///
|
||||||
/// Runs using Tokio for multithreading, so it should be really really fast
|
/// Runs using Tokio for multithreading, so it should be really really fast
|
||||||
///
|
///
|
||||||
/// Doesn't do mod-descending, so it will still try to format unreachable files. TODO.
|
/// Doesnhttps://www.rustwiki.org.cn/zh-CN/std/'t do mod-descending, so it will still try to format unreachable files. TODO.
|
||||||
async fn autoformat_project(check: bool, split_line_attributes: bool) -> Result<()> {
|
async fn autoformat_project(
|
||||||
let crate_config = dioxus_cli_config::CrateConfig::new(None)?;
|
check: bool,
|
||||||
|
split_line_attributes: bool,
|
||||||
|
do_rustfmt: bool,
|
||||||
|
) -> Result<()> {
|
||||||
|
let files_to_format = get_project_files();
|
||||||
|
|
||||||
let files_to_format = get_project_files(&crate_config);
|
dbg!(&files_to_format);
|
||||||
|
|
||||||
if files_to_format.is_empty() {
|
if files_to_format.is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -203,26 +183,18 @@ async fn autoformat_project(check: bool, split_line_attributes: bool) -> Result<
|
|||||||
let indent = indentation_for(&files_to_format[0], split_line_attributes)?;
|
let indent = indentation_for(&files_to_format[0], split_line_attributes)?;
|
||||||
|
|
||||||
let counts = files_to_format
|
let counts = files_to_format
|
||||||
.into_iter()
|
.into_par_iter()
|
||||||
.map(|path| async {
|
.map(|path| {
|
||||||
let path_clone = path.clone();
|
let res = format_file(&path, indent.clone(), do_rustfmt);
|
||||||
let res = tokio::spawn(format_file(path, indent.clone())).await;
|
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
|
Ok(cnt) => Some(cnt),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("error formatting file: {}\n{err}", path_clone.display());
|
eprintln!("error formatting file : {}\n{:#?}", path.display(), err);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
Ok(Err(err)) => {
|
|
||||||
eprintln!("error formatting file: {}\n{err}", path_clone.display());
|
|
||||||
None
|
|
||||||
}
|
|
||||||
Ok(Ok(res)) => Some(res),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<FuturesUnordered<_>>()
|
.collect::<Vec<_>>();
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.await;
|
|
||||||
|
|
||||||
let files_formatted: usize = counts.into_iter().flatten().sum();
|
let files_formatted: usize = counts.into_iter().flatten().sum();
|
||||||
|
|
||||||
@@ -281,6 +253,7 @@ fn indentation_for(
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
fn collect_rs_files(folder: &impl AsRef<Path>, files: &mut Vec<PathBuf>) {
|
fn collect_rs_files(folder: &impl AsRef<Path>, files: &mut Vec<PathBuf>) {
|
||||||
if is_target_dir(folder.as_ref()) {
|
if is_target_dir(folder.as_ref()) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in new issue
Block a user