xtask fmt

This commit is contained in:
nora 2022-02-22 14:13:39 +01:00
parent 9a819bc3f4
commit 33d1ef820b
3 changed files with 39 additions and 12 deletions

29
xtask/src/fmt.rs Normal file
View file

@ -0,0 +1,29 @@
use crate::project_root;
use anyhow::ensure;
use std::process::Command;
pub fn main() -> anyhow::Result<()> {
println!("$ cargo fmt");
let status = Command::new("cargo")
.arg("fmt")
.current_dir(project_root())
.status()?;
ensure!(status.success(), "`cargo fmt` did not exit successfully");
println!("$ yarn fmt");
let status = Command::new("yarn")
.arg("fmt")
.current_dir(project_root().join("test-js"))
.status()?;
ensure!(status.success(), "`yarn fmt` did not exist successfully");
println!("$ prettier -w .");
let status = Command::new("prettier")
.arg("-w")
.arg(".")
.current_dir(project_root().join("amqp_dashboard/assets"))
.status()?;
ensure!(status.success(), "`prettier .` did not exist successfully");
Ok(())
}

View file

@ -1,6 +1,7 @@
use std::path::PathBuf; use std::path::PathBuf;
mod codegen; mod codegen;
mod fmt;
mod test_js; mod test_js;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
@ -18,6 +19,8 @@ enum Commands {
Generate, Generate,
/// Run Javascript integration tests /// Run Javascript integration tests
TestJs, TestJs,
/// Format all code
Fmt,
} }
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
@ -26,15 +29,12 @@ fn main() -> anyhow::Result<()> {
match args.command { match args.command {
Commands::Generate => codegen::main(), Commands::Generate => codegen::main(),
Commands::TestJs => test_js::main(), Commands::TestJs => test_js::main(),
Commands::Fmt => fmt::main(),
} }
} }
pub fn project_root() -> PathBuf { pub fn project_root() -> PathBuf {
PathBuf::from(file!()) PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.expect("src directory path")
.parent()
.expect("xtask root path")
.parent() .parent()
.expect("project root path") .expect("project root path")
.to_path_buf() .to_path_buf()

View file

@ -1,24 +1,22 @@
use crate::project_root; use crate::project_root;
use anyhow::{bail, Context, Result}; use anyhow::{ensure, Context, Result};
use std::process::Command; use std::process::Command;
pub fn main() -> Result<()> { pub fn main() -> Result<()> {
let test_js_root = project_root().join("test-js"); let test_js_root = project_root().join("test-js");
println!("$ yarn");
let status = Command::new("yarn") let status = Command::new("yarn")
.current_dir(&test_js_root) .current_dir(&test_js_root)
.status() .status()
.context("yarn install tests")?; .context("yarn install tests")?;
if !status.success() { ensure!(status.success(), "yarn install failed");
bail!("yarn install failed"); println!("$ yarn test");
}
let status = Command::new("yarn") let status = Command::new("yarn")
.arg("test") .arg("test")
.current_dir(&test_js_root) .current_dir(&test_js_root)
.status() .status()
.context("yarn test tests")?; .context("yarn test tests")?;
if !status.success() { ensure!(status.success(), "yarn tests failed");
bail!("yarn tests failed");
}
Ok(()) Ok(())
} }