Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8f1658e4d | ||
|
|
865d87487b | ||
|
|
9641bd51a7 | ||
|
|
ea510c5112 |
No files matched your search
@@ -13,6 +13,13 @@ is pinned to is `CORE_VERSION` in `src/template.rs`, and each entry below says w
|
||||
|
||||
### Added
|
||||
|
||||
- **Every starter ships an `AGENTS.md` and a `CLAUDE.md` that imports it.** green-tea is new, so a
|
||||
coding agent falls back on Express habits. The file states the rules that differ: it is a graph, not a
|
||||
chain, a handler declares its needs in its signature, and the graph is checked at boot. It also points
|
||||
the agent at `matcha routes|tokens|explain --json`, so it reads the app instead of guessing, and at the
|
||||
`llms.txt` shipped inside the installed `@green-tea/core`.
|
||||
- **`matcha agents`** writes the same two files into a project that predates them. The files name the
|
||||
core version the project actually depends on. An existing file is left alone unless `--force` is passed.
|
||||
- **`matcha routes` and `matcha tokens`.** `routes` lists every route with its transport and chain.
|
||||
`tokens` lists every token, with who provides it and who needs it, handlers included. It is
|
||||
the check to run before writing `@needs('x')`.
|
||||
@@ -27,6 +34,24 @@ is pinned to is `CORE_VERSION` in `src/template.rs`, and each entry below says w
|
||||
question and gets one JSON document back, then renders it as text unless `--json` is passed.
|
||||
Text output is unchanged. The layer is also the seam a future `matcha mcp` would serve over
|
||||
MCP. It adds `serde_json` as a dependency.
|
||||
- **The node starter awaits `app.listen(3000)`.** A port already in use, or a provider that fails at
|
||||
boot, now stops the process with its own error rather than an unhandled rejection.
|
||||
- **The node and edge starters declare `engines: { node: ">=22" }`**, matching `@green-tea/core`,
|
||||
which no longer supports Node 18 or 20.
|
||||
- **`matcha create step|provider` derives the token from the class name in camelCase.**
|
||||
`create step current-user` writes `CurrentUserStep` providing `currentUser`. It used to write
|
||||
`current-userStep` and `return { current-user: null }`, which does not parse. A single word is
|
||||
unchanged (`Users` still provides `users`).
|
||||
|
||||
### Fixed
|
||||
|
||||
- **`matcha create` no longer overwrites a file that already exists.** Running it twice with the same
|
||||
name silently replaced the first file, edits included. Now it refuses and names the file.
|
||||
- **`matcha create` rejects names that cannot become a class** (`2fast`, `us.ers`) instead of
|
||||
writing a file that does not compile. For a step or provider, it also rejects names whose token
|
||||
core already provides (`logger`, `rooms`, `events`, `bus`, and the request tokens `req`,
|
||||
`params`, `query`, `body`, `headers`, `cookies`, `inbound`, `abort`). `createApp` would refuse the
|
||||
first group, and the second would shadow what every route reads.
|
||||
|
||||
## [26.9.0-beta.1] - 2026-09-24
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ matcha routes # every route and the chain it runs
|
||||
matcha tokens # every token: who provides it, who needs it
|
||||
matcha openapi # structural OpenAPI 3.1 for the route table
|
||||
matcha doctor # check the project for confusing misconfigurations
|
||||
matcha agents # write AGENTS.md/CLAUDE.md for coding agents (new projects get them)
|
||||
```
|
||||
|
||||
### The starter
|
||||
@@ -54,6 +55,12 @@ matcha doctor # check the project for confusing mis
|
||||
with the green-tea logo and streams a rotating zen message over `@Sse('/zen')`.
|
||||
Open the browser and it's already alive — `matcha run` boots it.
|
||||
|
||||
It also writes an `AGENTS.md` (and a `CLAUDE.md` that imports it) for coding
|
||||
agents. green-tea is new enough that an agent's training data says Express, so
|
||||
the file states the rules that differ, points at `matcha routes|tokens|explain
|
||||
--json` for reading the app, and at the `llms.txt` inside the installed core.
|
||||
`matcha agents` adds the same files to an older project.
|
||||
|
||||
The graph is composed in `src/app.ts`, which exports the app; `src/main.ts`
|
||||
imports it and binds a port. The split is what lets `matcha graph` and
|
||||
`matcha explain` read your application without starting a server.
|
||||
|
||||
@@ -48,6 +48,12 @@ pub enum Command {
|
||||
},
|
||||
/// Check the project for the misconfigurations that fail confusingly
|
||||
Doctor,
|
||||
/// Write AGENTS.md and CLAUDE.md: green-tea's rules for coding agents
|
||||
Agents {
|
||||
/// Overwrite the files if they exist
|
||||
#[arg(long)]
|
||||
force: bool,
|
||||
},
|
||||
/// Print the dependency graph (Mermaid, DOT, or JSON)
|
||||
Graph {
|
||||
#[arg(long, default_value = "mermaid", value_parser = ["mermaid", "dot", "json"])]
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
//! `matcha agents` — write `AGENTS.md` and `CLAUDE.md` into a project that was
|
||||
//! scaffolded before matcha wrote them, so a coding agent opening it finds
|
||||
//! green-tea's rules instead of applying Express habits.
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use crate::template::{self, AGENT_FILES, CORE_VERSION};
|
||||
|
||||
pub fn run(dir: &Path, force: bool) -> std::io::Result<()> {
|
||||
let name = project_name(dir);
|
||||
let version = core_version(dir).unwrap_or_else(|| CORE_VERSION.to_string());
|
||||
|
||||
for file in AGENT_FILES {
|
||||
let path = dir.join(file);
|
||||
if path.exists() && !force {
|
||||
println!("· {file} exists, left as is (--force to overwrite)");
|
||||
continue;
|
||||
}
|
||||
let contents = template::agent_file(file, &name, &version)
|
||||
.expect("agent files are embedded in the binary");
|
||||
std::fs::write(&path, contents)?;
|
||||
println!("✓ {file}");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// `package.json`'s `name`, else the directory's.
|
||||
fn project_name(dir: &Path) -> String {
|
||||
std::fs::read_to_string(dir.join("package.json"))
|
||||
.ok()
|
||||
.and_then(|pkg| field(&pkg, "\"name\""))
|
||||
.or_else(|| {
|
||||
std::fs::canonicalize(dir)
|
||||
.ok()
|
||||
.and_then(|p| p.file_name().map(|n| n.to_string_lossy().into_owned()))
|
||||
})
|
||||
.unwrap_or_else(|| "this project".to_string())
|
||||
}
|
||||
|
||||
/// The core version the project actually depends on, so the file names the
|
||||
/// version whose rules apply: `package.json` (npm, Bun, edge) or `deno.json`'s
|
||||
/// `jsr:@green-tea/core@…` import.
|
||||
fn core_version(dir: &Path) -> Option<String> {
|
||||
if let Ok(pkg) = std::fs::read_to_string(dir.join("package.json")) {
|
||||
if let Some(v) = field(&pkg, "\"@green-tea/core\"") {
|
||||
return Some(v.trim_start_matches(['^', '~', '=']).to_string());
|
||||
}
|
||||
}
|
||||
let deno = std::fs::read_to_string(dir.join("deno.json")).ok()?;
|
||||
let at = deno.find("@green-tea/core@")? + "@green-tea/core@".len();
|
||||
Some(
|
||||
deno[at..]
|
||||
.chars()
|
||||
.take_while(|c| !matches!(c, '"' | '/'))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
/// The string value after `key:` in a JSON text. Enough for the two flat
|
||||
/// fields read here, without a JSON parse of a file that may not be valid.
|
||||
fn field(json: &str, key: &str) -> Option<String> {
|
||||
let rest = &json[json.find(key)? + key.len()..];
|
||||
let rest = rest
|
||||
.trim_start()
|
||||
.strip_prefix(':')?
|
||||
.trim_start()
|
||||
.strip_prefix('"')?;
|
||||
Some(rest[..rest.find('"')?].to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use tempfile::tempdir;
|
||||
|
||||
#[test]
|
||||
fn writes_both_files_with_the_projects_own_core_version() {
|
||||
let d = tempdir().unwrap();
|
||||
std::fs::write(
|
||||
d.path().join("package.json"),
|
||||
r#"{ "name": "shop", "dependencies": { "@green-tea/core": "26.9.0-beta.1" } }"#,
|
||||
)
|
||||
.unwrap();
|
||||
run(d.path(), false).unwrap();
|
||||
let agents = std::fs::read_to_string(d.path().join("AGENTS.md")).unwrap();
|
||||
assert!(agents.contains("# AGENTS.md — shop"));
|
||||
assert!(agents.contains("26.9.0-beta.1"));
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(d.path().join("CLAUDE.md"))
|
||||
.unwrap()
|
||||
.trim(),
|
||||
"@AGENTS.md"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leaves_an_existing_file_alone_unless_forced() {
|
||||
let d = tempdir().unwrap();
|
||||
std::fs::write(d.path().join("AGENTS.md"), "mine").unwrap();
|
||||
run(d.path(), false).unwrap();
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(d.path().join("AGENTS.md")).unwrap(),
|
||||
"mine"
|
||||
);
|
||||
run(d.path(), true).unwrap();
|
||||
assert_ne!(
|
||||
std::fs::read_to_string(d.path().join("AGENTS.md")).unwrap(),
|
||||
"mine"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reads_the_version_from_a_deno_import() {
|
||||
let d = tempdir().unwrap();
|
||||
std::fs::write(
|
||||
d.path().join("deno.json"),
|
||||
r#"{ "imports": { "@green-tea/core": "jsr:@green-tea/core@26.9.0-beta.2" } }"#,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(core_version(d.path()).as_deref(), Some("26.9.0-beta.2"));
|
||||
}
|
||||
}
|
||||
+62
-7
@@ -5,7 +5,7 @@
|
||||
use std::io::{Error, ErrorKind};
|
||||
use std::path::Path;
|
||||
|
||||
use crate::{entry, wire};
|
||||
use crate::{entry, naming, wire};
|
||||
|
||||
/// A piece that lives inside a module: a file under `src/<subdir>/` plus an
|
||||
/// entry in one of `@Module`'s arrays.
|
||||
@@ -60,7 +60,64 @@ pub fn kinds() -> Vec<&'static str> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Tokens core already owns. A step or provider that provides one fails `createApp` (the framework
|
||||
/// tokens) or shadows what every route reads from the request (the request tokens).
|
||||
const TAKEN_TOKENS: &[&str] = &[
|
||||
"logger", "rooms", "events", "bus", "req", "params", "query", "body", "headers", "cookies",
|
||||
"inbound", "abort",
|
||||
];
|
||||
|
||||
/// `Users` stays `Users`; `current-user`, `current_user` and `current user` become `CurrentUser`.
|
||||
/// `None` for anything that cannot become a TypeScript class name.
|
||||
fn class_name(name: &str) -> Option<String> {
|
||||
let name = name.trim();
|
||||
if name.starts_with(|c: char| c.is_ascii_alphabetic())
|
||||
&& name.chars().all(|c| c.is_ascii_alphanumeric())
|
||||
{
|
||||
let (first, rest) = name.split_at(1);
|
||||
return Some(first.to_ascii_uppercase() + rest);
|
||||
}
|
||||
naming::slug(name).map(|s| naming::pascal(&s))
|
||||
}
|
||||
|
||||
/// The token a step or provider named `CurrentUser` provides: `currentUser`.
|
||||
fn token(class: &str) -> String {
|
||||
let (first, rest) = class.split_at(1);
|
||||
first.to_ascii_lowercase() + rest
|
||||
}
|
||||
|
||||
/// Refuses to replace a file the person may already have edited.
|
||||
fn write_new(file: &Path, contents: String) -> std::io::Result<()> {
|
||||
if file.exists() {
|
||||
return Err(Error::new(
|
||||
ErrorKind::AlreadyExists,
|
||||
format!(
|
||||
"{} already exists; matcha create does not overwrite it",
|
||||
file.display()
|
||||
),
|
||||
));
|
||||
}
|
||||
std::fs::create_dir_all(file.parent().unwrap())?;
|
||||
std::fs::write(file, contents)
|
||||
}
|
||||
|
||||
pub fn run(kind: &str, name: &str, check: bool) -> std::io::Result<()> {
|
||||
let Some(class) = class_name(name) else {
|
||||
return Err(Error::new(
|
||||
ErrorKind::InvalidInput,
|
||||
format!("'{name}' cannot name a class: use letters and digits, starting with a letter (Users, CurrentUser, current-user)"),
|
||||
));
|
||||
};
|
||||
let name = class.as_str();
|
||||
if (kind == "step" || kind == "provider") && TAKEN_TOKENS.contains(&token(name).as_str()) {
|
||||
return Err(Error::new(
|
||||
ErrorKind::InvalidInput,
|
||||
format!(
|
||||
"a {kind} named {name} would provide '{}', which core already provides; pick another name",
|
||||
token(name)
|
||||
),
|
||||
));
|
||||
}
|
||||
if kind == "module" {
|
||||
return create_module(name, check);
|
||||
}
|
||||
@@ -87,8 +144,7 @@ fn create_piece(name: &str, check: bool, piece: &Piece) -> std::io::Result<()> {
|
||||
let file = Path::new("src")
|
||||
.join(subdir)
|
||||
.join(format!("{lower}.{ext}.ts"));
|
||||
std::fs::create_dir_all(file.parent().unwrap())?;
|
||||
std::fs::write(&file, (piece.stub)(name))?;
|
||||
write_new(&file, (piece.stub)(name))?;
|
||||
println!("✓ {}", file.display());
|
||||
|
||||
let symbol = format!("{name}{suffix}");
|
||||
@@ -117,8 +173,7 @@ fn create_piece(name: &str, check: bool, piece: &Piece) -> std::io::Result<()> {
|
||||
fn create_module(name: &str, check: bool) -> std::io::Result<()> {
|
||||
let lower = name.to_lowercase();
|
||||
let file = Path::new("src").join(format!("{lower}.module.ts"));
|
||||
std::fs::create_dir_all(file.parent().unwrap())?;
|
||||
std::fs::write(&file, module_stub(name))?;
|
||||
write_new(&file, module_stub(name))?;
|
||||
println!("✓ {}", file.display());
|
||||
|
||||
let symbol = format!("{name}Module");
|
||||
@@ -164,14 +219,14 @@ fn controller_stub(name: &str) -> String {
|
||||
}
|
||||
|
||||
fn step_stub(name: &str) -> String {
|
||||
let lower = name.to_lowercase();
|
||||
let lower = token(name);
|
||||
format!(
|
||||
"import {{ Step }} from '@green-tea/core';\n\n@Step({{ provides: '{lower}', needs: [] }})\nexport class {name}Step {{\n run(ctx: Record<string, unknown>) {{\n return {{ {lower}: null }};\n }}\n}}\n"
|
||||
)
|
||||
}
|
||||
|
||||
fn provider_stub(name: &str) -> String {
|
||||
let lower = name.to_lowercase();
|
||||
let lower = token(name);
|
||||
format!(
|
||||
"import {{ Provider }} from '@green-tea/core';\n\n@Provider({{ provides: '{lower}' }})\nexport class {name}Provider {{\n provide() {{\n return {{ {lower}: null }};\n }}\n}}\n"
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@ mod ask;
|
||||
mod check;
|
||||
mod cli;
|
||||
mod cmd_add;
|
||||
mod cmd_agents;
|
||||
mod cmd_create;
|
||||
mod cmd_doctor;
|
||||
mod cmd_graph;
|
||||
@@ -88,6 +89,12 @@ fn main() {
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
Command::Agents { force } => {
|
||||
if let Err(e) = cmd_agents::run(std::path::Path::new("."), force) {
|
||||
eprintln!("error: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
Command::Doctor => {
|
||||
if let Err(e) = cmd_doctor::run(std::path::Path::new(".")) {
|
||||
eprintln!("error: {e}");
|
||||
|
||||
+45
-5
@@ -50,11 +50,7 @@ fn write_dir(dir: &Dir, dest: &Path, name: &str) -> std::io::Result<()> {
|
||||
std::fs::create_dir_all(parent)?;
|
||||
}
|
||||
let contents = std::str::from_utf8(f.contents())
|
||||
.map(|s| {
|
||||
s.replace("{{project_name}}", name)
|
||||
.replace("{{core_version}}", CORE_VERSION)
|
||||
.into_bytes()
|
||||
})
|
||||
.map(|s| render(s, name, CORE_VERSION).into_bytes())
|
||||
.unwrap_or_else(|_| f.contents().to_vec());
|
||||
std::fs::write(out, contents)?;
|
||||
}
|
||||
@@ -63,6 +59,28 @@ fn write_dir(dir: &Dir, dest: &Path, name: &str) -> std::io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn render(template: &str, project_name: &str, core_version: &str) -> String {
|
||||
template
|
||||
.replace("{{project_name}}", project_name)
|
||||
.replace("{{core_version}}", core_version)
|
||||
}
|
||||
|
||||
/// The files that tell a coding agent how this project and green-tea work:
|
||||
/// `AGENTS.md` (read by Codex, OpenCode and others) and a `CLAUDE.md` that
|
||||
/// imports it. `matcha new` writes them with the starter; `matcha agents`
|
||||
/// writes them into a project that predates them.
|
||||
pub const AGENT_FILES: [&str; 2] = ["AGENTS.md", "CLAUDE.md"];
|
||||
|
||||
/// Renders one of [`AGENT_FILES`] for a project already on `core_version`.
|
||||
pub fn agent_file(file: &str, project_name: &str, core_version: &str) -> Option<String> {
|
||||
let f = SHARED.get_file(file)?;
|
||||
Some(render(
|
||||
std::str::from_utf8(f.contents()).ok()?,
|
||||
project_name,
|
||||
core_version,
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -122,6 +140,28 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// Every starter tells a coding agent where green-tea's rules are, with the
|
||||
/// version it was scaffolded on, and points it at the introspection
|
||||
/// commands rather than at guessing.
|
||||
#[test]
|
||||
fn every_runtime_scaffolds_the_agent_files() {
|
||||
for rt in [Runtime::Node, Runtime::Deno, Runtime::Bun, Runtime::Edge] {
|
||||
let d = tempdir().unwrap();
|
||||
write_starter(d.path(), "my-api", rt).unwrap();
|
||||
let agents = std::fs::read_to_string(d.path().join("AGENTS.md")).unwrap();
|
||||
assert!(agents.contains("# AGENTS.md — my-api"), "{rt:?}");
|
||||
assert!(agents.contains(CORE_VERSION), "{rt:?}");
|
||||
assert!(!agents.contains("{{"), "{rt:?} left a placeholder");
|
||||
assert!(agents.contains("matcha tokens --json"), "{rt:?}");
|
||||
assert!(
|
||||
agents.contains("node_modules/@green-tea/core/llms.txt"),
|
||||
"{rt:?}"
|
||||
);
|
||||
let claude = std::fs::read_to_string(d.path().join("CLAUDE.md")).unwrap();
|
||||
assert_eq!(claude.trim(), "@AGENTS.md", "{rt:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deno_writes_shared_and_deno_overlay() {
|
||||
let d = tempdir().unwrap();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"name": "{{project_name}}",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"engines": { "node": ">=22" },
|
||||
"scripts": { "dev": "wrangler dev", "deploy": "wrangler deploy" },
|
||||
"dependencies": { "@green-tea/core": "npm:@jsr/green-tea__core@{{core_version}}" },
|
||||
"devDependencies": { "tsx": "^4", "typescript": "^5", "wrangler": "^4" }
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"name": "{{project_name}}",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"engines": { "node": ">=22" },
|
||||
"scripts": { "dev": "tsx watch src/main.ts" },
|
||||
"dependencies": { "@green-tea/core": "{{core_version}}" },
|
||||
"devDependencies": { "tsx": "^4", "typescript": "^5" }
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { app } from './app';
|
||||
|
||||
app.listen(3000);
|
||||
// Awaited, so a boot or bind failure stops the process with its own error instead of surfacing
|
||||
// later as an unhandled rejection.
|
||||
await app.listen(3000);
|
||||
console.log('🍵 green-tea running on http://localhost:3000');
|
||||
@@ -0,0 +1,58 @@
|
||||
# AGENTS.md — {{project_name}}
|
||||
|
||||
A [green-tea](https://green-tea.expressive-tea.io/docs/) app (`@green-tea/core` {{core_version}}), scaffolded by
|
||||
matcha. Read this before editing.
|
||||
|
||||
## green-tea is not Express
|
||||
|
||||
green-tea is new, so code that looks right from Express, Fastify or NestJS habits is usually wrong here.
|
||||
|
||||
- The request pipeline is a **dependency graph**, not a middleware chain. There is no `app.use`, no
|
||||
`next()`, and nothing mutates `req` or `res`.
|
||||
- A `@Provider` builds a value once at boot. A `@Step` computes a value per request. Each declares
|
||||
`provides` and `needs`, and green-tea derives the order from those declarations.
|
||||
- A handler declares what it needs **in its signature**: `@needs('user')`, `@param('id')`, `@body()`,
|
||||
`@query()`, `@cookie('name')`. Return a value to answer: an object becomes JSON 200, `undefined` becomes 204.
|
||||
Throw `Unauthorized`, `NotFound` or another `HttpError` to fail the request.
|
||||
- `createApp` validates the graph at boot. A token nothing provides, a token with two producers, or a node
|
||||
that needs what it provides all fail before the app serves anything.
|
||||
- **Reuse what the graph already has.** Before writing a new step, check whether a token you need, such as
|
||||
`user`, already exists. Before writing `@needs('x')`, check that something provides `x`.
|
||||
|
||||
## Look before you edit
|
||||
|
||||
Ask the app what it contains instead of guessing. These commands read `src/app.ts` without starting a
|
||||
server or opening connections:
|
||||
|
||||
```bash
|
||||
matcha routes --json # every route, its transport, and the chain it runs
|
||||
matcha tokens --json # every token: who provides it, who needs it
|
||||
matcha explain /some/:pattern --json # one route's chain, in execution order
|
||||
matcha graph --format json # the whole graph
|
||||
```
|
||||
|
||||
`explain` takes the route **pattern** as declared (`/users/:id`), not a URL.
|
||||
|
||||
## Where things are
|
||||
|
||||
- `src/app.ts` builds and exports `app` (`createApp({ modules: [...] })`). Introspection and tests import it.
|
||||
- `src/main.ts` serves `app`. It is the only file that differs per runtime.
|
||||
- `src/app.module.ts` lists the providers, steps and controllers with `@Module`.
|
||||
- `matcha create controller|step|provider|module <Name>` generates a piece and wires it into the module.
|
||||
- `matcha add sse|ws|upload|stream|buffer` adds a capability to a controller.
|
||||
|
||||
## Check your work
|
||||
|
||||
- Type-check: `npx tsc --noEmit` (Node, edge), `deno check src/main.ts` (Deno), `bunx tsc --noEmit` (Bun).
|
||||
- Test without a port: `await app.fetch(new Request('http://x/api/thing'))` returns a `Response`.
|
||||
- `matcha doctor` finds the misconfigurations that fail confusingly.
|
||||
|
||||
## The full guide
|
||||
|
||||
The rules, decorators, built-in tokens and common mistakes for the installed version are in the package
|
||||
itself:
|
||||
|
||||
- npm / Bun: `node_modules/@green-tea/core/llms.txt`
|
||||
- Deno (JSR): `https://jsr.io/@green-tea/core/{{core_version}}/llms.txt`
|
||||
|
||||
The complete docs as one file: https://green-tea.expressive-tea.io/docs/llms-full.txt
|
||||
@@ -0,0 +1 @@
|
||||
@AGENTS.md
|
||||
@@ -119,3 +119,54 @@ fn create_module_prefers_app_ts_over_main_ts() {
|
||||
let main = std::fs::read_to_string(d.path().join("src/main.ts")).unwrap();
|
||||
assert!(!main.contains("UsersModule"), "main.ts was edited: {main}");
|
||||
}
|
||||
|
||||
fn create(dir: &std::path::Path, kind: &str, name: &str) -> assert_cmd::assert::Assert {
|
||||
Command::cargo_bin("matcha")
|
||||
.unwrap()
|
||||
.current_dir(dir)
|
||||
.args(["create", kind, name])
|
||||
.assert()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_step_keeps_camel_case_in_the_token_and_reads_kebab_input() {
|
||||
let d = tempdir().unwrap();
|
||||
seed_module(d.path());
|
||||
create(d.path(), "step", "current-user").success();
|
||||
let step = std::fs::read_to_string(d.path().join("src/steps/currentuser.step.ts")).unwrap();
|
||||
assert!(step.contains("class CurrentUserStep"), "{step}");
|
||||
assert!(step.contains("provides: 'currentUser'"), "{step}");
|
||||
assert!(step.contains("return { currentUser: null }"), "{step}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_refuses_a_token_core_already_provides() {
|
||||
let d = tempdir().unwrap();
|
||||
seed_module(d.path());
|
||||
create(d.path(), "provider", "Logger")
|
||||
.failure()
|
||||
.stderr(predicates::str::contains("core already provides"));
|
||||
create(d.path(), "step", "req").failure();
|
||||
assert!(!d.path().join("src/providers/logger.provider.ts").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_refuses_a_name_that_cannot_be_a_class() {
|
||||
let d = tempdir().unwrap();
|
||||
seed_module(d.path());
|
||||
create(d.path(), "controller", "2fast").failure();
|
||||
create(d.path(), "controller", "us.ers").failure();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_does_not_overwrite_an_existing_file() {
|
||||
let d = tempdir().unwrap();
|
||||
seed_module(d.path());
|
||||
create(d.path(), "controller", "Users").success();
|
||||
let file = d.path().join("src/controllers/users.controller.ts");
|
||||
std::fs::write(&file, "// edited\n").unwrap();
|
||||
create(d.path(), "controller", "Users")
|
||||
.failure()
|
||||
.stderr(predicates::str::contains("already exists"));
|
||||
assert_eq!(std::fs::read_to_string(&file).unwrap(), "// edited\n");
|
||||
}
|
||||
Reference in new issue
Block a user