🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
check
  • Loading branch information
levkk committed Nov 27, 2023
commit bace11f36db9bf8c8b6b1938f977cfd064b3073d
24 changes: 20 additions & 4 deletions packages/cargo-pgml-components/src/frontend/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,26 @@ pub fn watch() {
std::thread::sleep(std::time::Duration::MAX);
}

pub fn lint() {
unwrap_or_exit!(execute_with_nvm(
Command::new("prettier").arg("--write").arg("src/**/*.js")
));
pub fn lint(check: bool) {
let mut cmd = Command::new("prettier");
if check {
cmd.arg("--check");
} else {
cmd.arg("--write");
}

cmd.arg("src/**/*.js");

print("linting...");

let result = execute_with_nvm(&mut cmd);

if check && result.is_err() {
error("diff detected");
error!("{}", result.err().unwrap());
} else {
info("ok");
}
}

fn rebuild() {
Expand Down
9 changes: 6 additions & 3 deletions packages/cargo-pgml-components/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ enum Commands {
Watch,

/// Lint your code
Lint,
Lint {
#[arg(long, default_value = "false")]
check: bool,
},
}

#[derive(Subcommand, Debug)]
Expand Down Expand Up @@ -122,8 +125,8 @@ fn main() {
Commands::Watch => {
frontend::tools::watch();
}
Commands::Lint => {
frontend::tools::lint();
Commands::Lint { check } => {
frontend::tools::lint(check);
}
}
}
Expand Down