Skip to content

Add prettier #1189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion packages/cargo-pgml-components/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cargo-pgml-components/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-pgml-components"
version = "0.1.22"
version = "0.1.23"
edition = "2021"
authors = ["PostgresML <team@postgresml.org>"]
license = "MIT"
Expand Down
30 changes: 29 additions & 1 deletion packages/cargo-pgml-components/src/frontend/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::time::Duration;
use notify_debouncer_full::{new_debouncer, notify::*, DebounceEventResult};

/// Required tools.
static TOOLS: &[&str] = &["sass", "rollup"];
static TOOLS: &[&str] = &["sass", "rollup", "prettier"];
static ROLLUP_PLUGINS: &[&str] = &["@rollup/plugin-terser", "@rollup/plugin-node-resolve"];
static NVM_EXEC: &'static str = "/tmp/pgml-components-nvm.sh";
static NVM_SOURCE: &'static str = "https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh";
Expand Down Expand Up @@ -182,6 +182,34 @@ pub fn watch() {
std::thread::sleep(std::time::Duration::MAX);
}

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 let Err(err) = result {
if check {
error("diff detected");
} else {
error!("error");
}

error!("{}", err);
exit(1);
}

info("ok");
}

fn rebuild() {
unwrap_or_exit!(execute_command(
Command::new("cargo").arg("pgml-components").arg("bundle")
Expand Down
11 changes: 10 additions & 1 deletion packages/cargo-pgml-components/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ enum Commands {
#[command(subcommand)]
LocalDev(LocalDevCommands),

/// Watch for local changes,
/// Watch for local changes
Watch,

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

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