Skip to content

Commit 3d682bb

Browse files
committed
add just and setup codegen cli
1 parent 64737cd commit 3d682bb

File tree

12 files changed

+573
-3
lines changed

12 files changed

+573
-3
lines changed

Cargo.lock

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
members = [
33
"crates/*",
44
"lib/*",
5-
"xtask/"
5+
"xtask/codegen"
66
]
77
resolver = "2"
88

clippy.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
allow-dbg-in-tests = true
2+

justfile

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
_default:
2+
just --list -u
3+
4+
alias f := format
5+
alias t := test
6+
# alias r := ready
7+
# alias l := lint
8+
# alias qt := test-quick
9+
10+
# Installs the tools needed to develop
11+
# install-tools:
12+
# cargo install cargo-binstall
13+
# cargo binstall cargo-insta taplo-cli wasm-pack wasm-tools knope
14+
15+
# Upgrades the tools needed to develop
16+
# upgrade-tools:
17+
# cargo install cargo-binstall --force
18+
# cargo binstall cargo-insta taplo-cli wasm-pack wasm-tools knope --force
19+
20+
# Generate all files across crates and tools. You rarely want to use it locally.
21+
# gen-all:
22+
# cargo run -p xtask_codegen -- all
23+
# cargo codegen-configuration
24+
# cargo codegen-migrate
25+
# just gen-bindings
26+
# just format
27+
28+
# Generates TypeScript types and JSON schema of the configuration
29+
# gen-bindings:
30+
# cargo codegen-schema
31+
# cargo codegen-bindings
32+
33+
# Generates code generated files for the linter
34+
# gen-lint:
35+
# cargo run -p xtask_codegen -- analyzer
36+
# cargo codegen-configuration
37+
# cargo codegen-migrate
38+
# just gen-bindings
39+
# cargo run -p rules_check
40+
# just format
41+
42+
# Generates the initial files for all formatter crates
43+
# gen-formatter:
44+
# cargo run -p xtask_codegen -- formatter
45+
46+
# Generates the Tailwind CSS preset for utility class sorting (requires Bun)
47+
# gen-tw:
48+
# bun packages/tailwindcss-config-analyzer/src/generate-tailwind-preset.ts
49+
50+
# Generates the code of the grammars available in Biome
51+
# gen-grammar *args='':
52+
# cargo run -p xtask_codegen -- grammar {{args}}
53+
54+
# Generates the linter documentation and Rust documentation
55+
# documentation:
56+
# RUSTDOCFLAGS='-D warnings' cargo documentation
57+
58+
# Creates a new lint rule in the given path, with the given name. Name has to be camel case.
59+
# new-js-lintrule rulename:
60+
# cargo run -p xtask_codegen -- new-lintrule --kind=js --category=lint --name={{rulename}}
61+
# just gen-lint
62+
# just documentation
63+
64+
# Creates a new lint rule in the given path, with the given name. Name has to be camel case.
65+
# new-js-assistrule rulename:
66+
# cargo run -p xtask_codegen -- new-lintrule --kind=js --category=assist --name={{rulename}}
67+
# just gen-lint
68+
# just documentation
69+
70+
# Promotes a rule from the nursery group to a new group
71+
# promote-rule rulename group:
72+
# cargo run -p xtask_codegen -- promote-rule --name={{rulename}} --group={{group}}
73+
# just gen-lint
74+
# just documentation
75+
# -cargo test -p biome_js_analyze -- {{snakecase(rulename)}}
76+
# cargo insta accept
77+
78+
79+
# Format Rust files and TOML files
80+
format:
81+
cargo format
82+
# taplo format
83+
84+
[unix]
85+
_touch file:
86+
touch {{file}}
87+
88+
[windows]
89+
_touch file:
90+
(gci {{file}}).LastWriteTime = Get-Date
91+
92+
# Run tests of all crates
93+
test:
94+
cargo test run --no-fail-fast
95+
96+
# Run tests for the crate passed as argument e.g. just test-create pg_cli
97+
test-crate name:
98+
cargo test run -p {{name}} --no-fail-fast
99+
100+
# Run doc tests
101+
test-doc:
102+
cargo test --doc
103+
104+
# Tests a lint rule. The name of the rule needs to be camel case
105+
# test-lintrule name:
106+
# just _touch crates/biome_js_analyze/tests/spec_tests.rs
107+
# just _touch crates/biome_json_analyze/tests/spec_tests.rs
108+
# just _touch crates/biome_css_analyze/tests/spec_tests.rs
109+
# just _touch crates/biome_graphql_analyze/tests/spec_tests.rs
110+
# cargo test -p biome_js_analyze -- {{snakecase(name)}} --show-output
111+
# cargo test -p biome_json_analyze -- {{snakecase(name)}} --show-output
112+
# cargo test -p biome_css_analyze -- {{snakecase(name)}} --show-output
113+
# cargo test -p biome_graphql_analyze -- {{snakecase(name)}} --show-output
114+
115+
# Tests a lint rule. The name of the rule needs to be camel case
116+
# test-transformation name:
117+
# just _touch crates/biome_js_transform/tests/spec_tests.rs
118+
# cargo test -p biome_js_transform -- {{snakecase(name)}} --show-output
119+
120+
# Run the quick_test for the given package.
121+
# test-quick package:
122+
# cargo test -p {{package}} --test quick_test -- quick_test --nocapture --ignored
123+
124+
125+
# Alias for `cargo clippy`, it runs clippy on the whole codebase
126+
lint:
127+
cargo clippy
128+
129+
# When you finished coding, run this command to run the same commands in the CI.
130+
# ready:
131+
# git diff --exit-code --quiet
132+
# just gen-all
133+
# just documentation
134+
# #just format # format is already run in `just gen-all`
135+
# just lint
136+
# just test
137+
# just test-doc
138+
# git diff --exit-code --quiet
139+
140+
# Creates a new crate
141+
new-crate name:
142+
cargo new --lib crates/{{snakecase(name)}}
143+
cargo run -p xtask_codegen -- new-crate --name={{snakecase(name)}}
144+
145+
# Creates a new changeset for the final changelog
146+
# new-changeset:
147+
# knope document-change
148+
149+
# Dry-run of the release
150+
# dry-run-release *args='':
151+
# knope release --dry-run {{args}}
152+

rustfmt.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
newline_style = "Unix"
2+

xtask/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "xtask"
3-
version = "0.1.0"
3+
version = "0.0.0"
44
publish = false
55
license = "MIT OR Apache-2.0"
66
edition = "2021"

xtask/codegen/Cargo.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
edition = "2021"
3+
name = "xtask_codegen"
4+
publish = false
5+
version = "0.0.0"
6+
7+
[dependencies]
8+
bpaf = { workspace = true, features = ["derive"] }
9+
xtask = { path = '../', version = "0.0" }
10+
11+

xtask/codegen/src/generate_crate.rs

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
use std::fs;
2+
use xtask::*;
3+
4+
fn cargo_template(name: &str) -> String {
5+
format!(
6+
r#"
7+
[package]
8+
authors.workspace = true
9+
categories.workspace = true
10+
description = "<DESCRIPTION>"
11+
edition.workspace = true
12+
homepage.workspace = true
13+
keywords.workspace = true
14+
license.workspace = true
15+
name = "{name}"
16+
repository.workspace = true
17+
version = "0.0.0"
18+
19+
[lints]
20+
workspace = true
21+
"#
22+
)
23+
}
24+
25+
// fn knope_template(name: &str) -> String {
26+
// format!(
27+
// r#"
28+
// [packages.{name}]
29+
// versioned_files = ["crates/{name}/Cargo.toml"]
30+
// changelog = "crates/{name}/CHANGELOG.md"
31+
// "#
32+
// )
33+
// }
34+
35+
pub fn generate_crate(crate_name: String) -> Result<()> {
36+
let crate_root = project_root().join("crates").join(crate_name.as_str());
37+
let cargo_file = crate_root.join("Cargo.toml");
38+
// let knope_config = project_root().join("knope.toml");
39+
40+
// let mut knope_contents = fs::read_to_string(&knope_config)?;
41+
fs::write(cargo_file, cargo_template(crate_name.as_str()))?;
42+
// let start_content = "## Rust crates. DO NOT CHANGE!\n";
43+
// let end_content = "\n## End of crates. DO NOT CHANGE!";
44+
// debug_assert!(
45+
// knope_contents.contains(start_content),
46+
// "The file knope.toml must contains `{start_content}`"
47+
// );
48+
// debug_assert!(
49+
// knope_contents.contains(end_content),
50+
// "The file knope.toml must contains `{end_content}`"
51+
// );
52+
53+
// let file_start_index = knope_contents.find(start_content).unwrap() + start_content.len();
54+
// let file_end_index = knope_contents.find(end_content).unwrap();
55+
// let crates_text = &knope_contents[file_start_index..file_end_index];
56+
// let template = knope_template(crate_name.as_str());
57+
// let new_crates_text: Vec<_> = crates_text.lines().chain(Some(&template[..])).collect();
58+
// let new_crates_text = new_crates_text.join("\n");
59+
//
60+
// knope_contents.replace_range(file_start_index..file_end_index, &new_crates_text);
61+
// fs::write(knope_config, knope_contents)?;
62+
Ok(())
63+
}
64+

xtask/codegen/src/lib.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Codegen tools. Derived from Biome's codegen
2+
3+
mod generate_crate;
4+
5+
use bpaf::Bpaf;
6+
pub use self::generate_crate::generate_crate;
7+
8+
#[derive(Debug, Clone, Bpaf)]
9+
#[bpaf(options)]
10+
pub enum TaskCommand {
11+
/// Creates a new crate
12+
#[bpaf(command, long("new-crate"))]
13+
NewCrate {
14+
/// The name of the crate
15+
#[bpaf(long("name"), argument("STRING"))]
16+
name: String,
17+
},
18+
}
19+
20+

xtask/codegen/src/main.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use xtask::{project_root, pushd, Result};
2+
3+
use xtask_codegen::{
4+
generate_crate, task_command, TaskCommand,
5+
};
6+
7+
fn main() -> Result<()> {
8+
let _d = pushd(project_root());
9+
let result = task_command().fallback_to_usage().run();
10+
11+
match result {
12+
TaskCommand::NewCrate { name } => {
13+
generate_crate(name)?;
14+
}
15+
}
16+
17+
Ok(())
18+
}
19+

0 commit comments

Comments
 (0)