Compare commits
31
Commits
757b729986
...
v26.7.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a3dae99f5 | ||
|
|
c95ca6c812 | ||
|
|
eb65f472dd | ||
|
|
444567ffb3 | ||
|
|
314bf3a4b0 | ||
|
|
3066cc477e | ||
|
|
9fd1181497 | ||
|
|
7c6d01212e | ||
|
|
59967af078 | ||
|
|
ed2deeda1c | ||
|
|
4cf92b18e5 | ||
|
|
77c3c2a0ff | ||
|
|
c7b58db24e | ||
|
|
7080b207a7 | ||
|
|
6d99144a75 | ||
|
|
235b87dcae | ||
|
|
6e84f467a8 | ||
|
|
995c3cd45e | ||
|
|
b630478985 | ||
|
|
7beadde4be | ||
|
|
48276890e8 | ||
|
|
8a282fa9c8 | ||
|
|
02c3c35d87 | ||
|
|
1b0a9b40a6 | ||
|
|
04e20cfccf | ||
|
|
b071896b10 | ||
|
|
4985adad00 | ||
|
|
685c51b7e0 | ||
|
|
3f86841d4b | ||
|
|
f84c50b97e | ||
|
|
277e0bd289 |
No files matched your search
@@ -0,0 +1,79 @@
|
|||||||
|
name: Release
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags: ['v*']
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
# Gitea's delete-asset API differs from GitHub's (it requires the release id in the
|
||||||
|
# path), so softprops' delete-then-reupload 404s when re-releasing an existing tag.
|
||||||
|
# Delete the whole release first so every run's uploads are fresh. Portable: the
|
||||||
|
# get-by-tag + delete-by-id endpoints exist on both Gitea and GitHub, and deleting
|
||||||
|
# first is harmless on GitHub (softprops just recreates it).
|
||||||
|
prepare:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Delete existing release for this tag
|
||||||
|
env:
|
||||||
|
GT_TOKEN: ${{ github.token }}
|
||||||
|
run: |
|
||||||
|
tag="$GITHUB_REF_NAME"
|
||||||
|
api="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY"
|
||||||
|
id=$(curl -sSL -H "Authorization: token $GT_TOKEN" "$api/releases/tags/$tag" \
|
||||||
|
| grep -o '"id":[0-9]*' | head -1 | cut -d: -f2 || true)
|
||||||
|
if [ -n "${id:-}" ]; then
|
||||||
|
echo "deleting existing release id=$id for $tag"
|
||||||
|
curl -sS -X DELETE -H "Authorization: token $GT_TOKEN" "$api/releases/$id" || true
|
||||||
|
else
|
||||||
|
echo "no existing release for $tag — nothing to delete"
|
||||||
|
fi
|
||||||
|
|
||||||
|
build:
|
||||||
|
needs: prepare
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- target: aarch64-apple-darwin
|
||||||
|
os: macos-14
|
||||||
|
- target: x86_64-apple-darwin
|
||||||
|
os: macos-14
|
||||||
|
- target: x86_64-unknown-linux-musl
|
||||||
|
os: ubuntu-latest
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Rust
|
||||||
|
run: |
|
||||||
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
|
||||||
|
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
|
- name: Add target + musl tooling
|
||||||
|
run: |
|
||||||
|
rustup target add ${{ matrix.target }}
|
||||||
|
if [ "${{ matrix.target }}" = "x86_64-unknown-linux-musl" ]; then
|
||||||
|
sudo apt-get update && sudo apt-get install -y musl-tools
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: cargo build --release --locked --target ${{ matrix.target }}
|
||||||
|
|
||||||
|
- name: Package
|
||||||
|
run: |
|
||||||
|
TAR="matcha-${{ matrix.target }}.tar.gz"
|
||||||
|
tar -czf "$TAR" -C "target/${{ matrix.target }}/release" matcha
|
||||||
|
if command -v sha256sum >/dev/null 2>&1; then
|
||||||
|
sha256sum "$TAR" > "$TAR.sha256"
|
||||||
|
else
|
||||||
|
shasum -a 256 "$TAR" > "$TAR.sha256"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Upload to release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
files: |
|
||||||
|
matcha-${{ matrix.target }}.tar.gz
|
||||||
|
matcha-${{ matrix.target }}.tar.gz.sha256
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
.superpowers/
|
.superpowers/
|
||||||
|
.specs/
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
# matcha — green-tea CLI · Design
|
|
||||||
|
|
||||||
**Date:** 2026-07-11
|
|
||||||
**Status:** Approved (brainstorming), pending spec review
|
|
||||||
**Repo:** `Green-Tea/matcha` (separate repo, Rust — created by Diego)
|
|
||||||
**Relates to:** `Green-Tea/core` (the green-tea framework)
|
|
||||||
|
|
||||||
## 1. What it is
|
|
||||||
|
|
||||||
`matcha` is the developer-experience CLI for the green-tea HTTP framework. A
|
|
||||||
single **native binary written in Rust**, distributed independently of the
|
|
||||||
framework. It does not require a JS runtime to *install or operate*; it only
|
|
||||||
*delegates* to the project's runtime when it needs to run or type-check the
|
|
||||||
project.
|
|
||||||
|
|
||||||
**Name rationale:** matcha *is* premium green tea — on-brand, distinctive, no
|
|
||||||
CLI collision (`gt`=Graphite, `tea`=Gitea's CLI, `gtea`≈gitea were all ruled
|
|
||||||
out). Crate `matcha`, brew `matcha`, repo `Green-Tea/matcha`.
|
|
||||||
|
|
||||||
## 2. Command surface
|
|
||||||
|
|
||||||
```
|
|
||||||
matcha new <name> [--template-url gh:owner/repo] # scaffold a project
|
|
||||||
matcha run # detect runtime, run in watch
|
|
||||||
matcha create <module|controller|step> <Name> # generate a piece + auto-wire
|
|
||||||
matcha add <sse|stream|buffer> # add a capability to a file
|
|
||||||
```
|
|
||||||
|
|
||||||
`new` scaffolds **projects**; `create` scaffolds **pieces inside** a project.
|
|
||||||
This split retires the earlier ambiguous `create app`.
|
|
||||||
|
|
||||||
## 3. `matcha new`
|
|
||||||
|
|
||||||
- No flag → **official `starter` template, embedded in the binary**
|
|
||||||
(`include_dir!`), zero network.
|
|
||||||
- `--template-url gh:owner/repo` → `git clone --depth 1` of the given repo.
|
|
||||||
`git` is ubiquitous on dev machines, so the binary carries **no HTTP/TLS
|
|
||||||
dependency**. This opens a bring-your-own-template ecosystem while we
|
|
||||||
maintain only one official template.
|
|
||||||
- Token substitution on copy is minimal: `{{project_name}}`. Nothing more.
|
|
||||||
|
|
||||||
### The official `starter` (the "wow")
|
|
||||||
|
|
||||||
A live app the moment you run it — the create-react-app effect:
|
|
||||||
|
|
||||||
- Serves an `index.html` showing the **green-tea logo** (demonstrates
|
|
||||||
`@Html` static serving).
|
|
||||||
- A `@Sse('/zen')` endpoint that streams a **rotating zen message every 30
|
|
||||||
seconds** (demonstrates live streaming). The page subscribes via
|
|
||||||
`EventSource('/zen')` and updates the zen line under the logo, untouched by
|
|
||||||
the user.
|
|
||||||
|
|
||||||
Faithful to the real framework API (verified in `core`):
|
|
||||||
|
|
||||||
```ts
|
|
||||||
@Route('/')
|
|
||||||
class HomeController {
|
|
||||||
@Get('/')
|
|
||||||
@Html('public/index.html')
|
|
||||||
home() {}
|
|
||||||
|
|
||||||
@Sse('/zen')
|
|
||||||
zen() {
|
|
||||||
const messages = [/* zen lines */];
|
|
||||||
return (async function* () {
|
|
||||||
for (let i = 0; ; i++) {
|
|
||||||
yield { zen: messages[i % messages.length] };
|
|
||||||
await new Promise((r) => setTimeout(r, 30_000));
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Starter layout:
|
|
||||||
|
|
||||||
```
|
|
||||||
<name>/
|
|
||||||
src/app.module.ts # @Module wiring HomeController
|
|
||||||
src/controllers/home.controller.ts
|
|
||||||
public/index.html # logo + EventSource('/zen')
|
|
||||||
<runtime config> # deno.json | package.json | ...
|
|
||||||
matcha.toml # optional runtime override
|
|
||||||
```
|
|
||||||
|
|
||||||
## 4. `matcha run` — runtime detection
|
|
||||||
|
|
||||||
Precedence (first match wins):
|
|
||||||
|
|
||||||
1. `matcha.toml` `runtime` field — explicit override
|
|
||||||
2. `deno.json(c)` → **deno**
|
|
||||||
3. `bun.lock(b)` → **bun**
|
|
||||||
4. `package.json` → **node**
|
|
||||||
|
|
||||||
Runs the project's entry in watch mode by wrapping the detected runtime.
|
|
||||||
**Edge is not a `run` target in v1** — it deploys, it does not run locally.
|
|
||||||
|
|
||||||
## 5. `create` / `add` — codegen
|
|
||||||
|
|
||||||
Three distinct jobs, three tools:
|
|
||||||
|
|
||||||
- **Edit** → `tree-sitter` + `tree-sitter-typescript` (in-process, no runtime).
|
|
||||||
Inserts the `import` and adds the class to the right `@Module` array
|
|
||||||
(`controllers` / `providers` / steps) via range-based splice that preserves
|
|
||||||
the file's existing formatting byte-for-byte.
|
|
||||||
- **Syntax check** → re-parse with tree-sitter. If an `ERROR` node appears, the
|
|
||||||
edit broke structure → **revert, leave the file untouched**. Free, in-process.
|
|
||||||
- **Semantic check (optional)** → if a `tsconfig` / `deno.json` is present, run
|
|
||||||
`tsc --noEmit` / `deno check` with the detected runtime. Behind `--check`
|
|
||||||
(or automatic when config is present). This is the lazy-correct alternative
|
|
||||||
to an LSP: an LSP is built for interactive editing, cannot insert into an
|
|
||||||
array, and would reintroduce a runtime dependency — a one-shot `tsc`/`deno
|
|
||||||
check` gives the same diagnostics with none of the plumbing.
|
|
||||||
|
|
||||||
**Idempotent:** if the piece is already registered, do not duplicate.
|
|
||||||
|
|
||||||
**Agreed fallback:** if auto-wire proves fragile ("truena como ejote"),
|
|
||||||
degrade to emit-only — write the file and print "add it to your module."
|
|
||||||
Auto-wire stays, but is allowed to become opt-in rather than a blocker.
|
|
||||||
|
|
||||||
## 6. Architecture (Rust)
|
|
||||||
|
|
||||||
- Command parsing: `clap`.
|
|
||||||
- Templates: `include_dir!` embeds the starter; `--template-url` shells to
|
|
||||||
`git clone --depth 1`.
|
|
||||||
- Codegen: `tree-sitter` + `tree-sitter-typescript`, range-based edits.
|
|
||||||
- Validation: spawn detected runtime for `tsc --noEmit` / `deno check`.
|
|
||||||
- Runtime detection: filesystem probes in the precedence order above.
|
|
||||||
|
|
||||||
Each command is an isolated unit: parse args → do one job → report. No shared
|
|
||||||
mutable state between commands.
|
|
||||||
|
|
||||||
## 7. Out of scope for v1 (YAGNI)
|
|
||||||
|
|
||||||
Template catalog (one starter + BYO url is enough), edge as a `run` target,
|
|
||||||
plugin system, custom LSP, custom bundler/dev-server.
|
|
||||||
|
|
||||||
## 8. Open handoff items
|
|
||||||
|
|
||||||
- Diego creates the `Green-Tea/matcha` repo; this spec moves there.
|
|
||||||
- green-tea logo asset for the starter (`assets/` in `core` has branding).
|
|
||||||
File diff suppressed because it is too large.
Load diff
Generated
+1
-1
@@ -254,7 +254,7 @@ checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "matcha"
|
name = "matcha"
|
||||||
version = "0.1.0"
|
version = "26.7.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"assert_cmd",
|
"assert_cmd",
|
||||||
"clap",
|
"clap",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "matcha"
|
name = "matcha"
|
||||||
version = "0.1.0"
|
version = "26.7.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
|||||||
@@ -5,7 +5,20 @@ The [green-tea](https://git.svc.zoit.services/Green-Tea/core) CLI — scaffold,
|
|||||||
## Install
|
## Install
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo install matcha # or: brew install matcha (once published)
|
curl -fsSL https://git.svc.zoit.services/Green-Tea/matcha/raw/branch/main/install.sh | sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Installs a prebuilt binary to `~/.local/bin` — no Rust required. Env vars go on
|
||||||
|
the `sh` side of the pipe:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -fsSL …/install.sh | MATCHA_VERSION=v26.7.0 MATCHA_INSTALL_DIR=/usr/local/bin sh
|
||||||
|
```
|
||||||
|
|
||||||
|
**From source** (requires Rust — compiles and installs):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo install --git https://git.svc.zoit.services/Green-Tea/matcha
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|||||||
Executable
+84
@@ -0,0 +1,84 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# matcha installer — downloads a prebuilt binary from Gitea Releases.
|
||||||
|
# curl -fsSL <raw>/install.sh | sh
|
||||||
|
# Env: MATCHA_VERSION (tag, default latest), MATCHA_INSTALL_DIR (default ~/.local/bin),
|
||||||
|
# MATCHA_REPO_BASE (default the Gitea repo URL).
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
REPO_BASE="${MATCHA_REPO_BASE:-https://git.svc.zoit.services/Green-Tea/matcha}"
|
||||||
|
# The API lives at the host root (/api/v1/...), NOT under the repo path. Keep it
|
||||||
|
# separate from REPO_BASE (which is used for release DOWNLOAD urls under the repo).
|
||||||
|
API_BASE="${MATCHA_API_BASE:-https://git.svc.zoit.services/api/v1/repos/Green-Tea/matcha}"
|
||||||
|
INSTALL_DIR="${MATCHA_INSTALL_DIR:-$HOME/.local/bin}"
|
||||||
|
|
||||||
|
err() { echo "matcha-install: $*" >&2; exit 1; }
|
||||||
|
|
||||||
|
if command -v curl >/dev/null 2>&1; then
|
||||||
|
fetch_out() { curl -fsSL "$1" -o "$2"; }
|
||||||
|
fetch() { curl -fsSL "$1"; }
|
||||||
|
elif command -v wget >/dev/null 2>&1; then
|
||||||
|
fetch_out() { wget -qO "$2" "$1"; }
|
||||||
|
fetch() { wget -qO- "$1"; }
|
||||||
|
else
|
||||||
|
err "need curl or wget"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v sha256sum >/dev/null 2>&1; then
|
||||||
|
sha256() { sha256sum "$1" | awk '{print $1}'; }
|
||||||
|
elif command -v shasum >/dev/null 2>&1; then
|
||||||
|
sha256() { shasum -a 256 "$1" | awk '{print $1}'; }
|
||||||
|
else
|
||||||
|
err "need sha256sum or shasum"
|
||||||
|
fi
|
||||||
|
|
||||||
|
os=$(uname -s); arch=$(uname -m)
|
||||||
|
case "$os" in
|
||||||
|
Darwin)
|
||||||
|
case "$arch" in
|
||||||
|
arm64|aarch64) triple="aarch64-apple-darwin" ;;
|
||||||
|
x86_64) triple="x86_64-apple-darwin" ;;
|
||||||
|
*) err "unsupported macOS arch: $arch" ;;
|
||||||
|
esac ;;
|
||||||
|
Linux)
|
||||||
|
case "$arch" in
|
||||||
|
x86_64|amd64) triple="x86_64-unknown-linux-musl" ;;
|
||||||
|
arm64|aarch64) err "linux arm64 has no prebuilt binary yet — use: cargo install --git $REPO_BASE" ;;
|
||||||
|
*) err "unsupported Linux arch: $arch" ;;
|
||||||
|
esac ;;
|
||||||
|
*) err "unsupported OS: $os — try: cargo install --git $REPO_BASE" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
version="${MATCHA_VERSION:-latest}"
|
||||||
|
if [ "$version" = "latest" ]; then
|
||||||
|
tag=$(fetch "$API_BASE/releases/latest" \
|
||||||
|
| grep -o '"tag_name":[[:space:]]*"[^"]*"' | head -1 | cut -d'"' -f4)
|
||||||
|
[ -n "$tag" ] || err "could not resolve latest release tag"
|
||||||
|
else
|
||||||
|
tag="$version"
|
||||||
|
fi
|
||||||
|
|
||||||
|
asset="matcha-${triple}.tar.gz"
|
||||||
|
url="$REPO_BASE/releases/download/${tag}/${asset}"
|
||||||
|
|
||||||
|
tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT
|
||||||
|
echo "matcha-install: downloading $asset ($tag)"
|
||||||
|
fetch_out "$url" "$tmp/$asset" || err "download failed: $url"
|
||||||
|
fetch_out "$url.sha256" "$tmp/$asset.sha256" || err "checksum download failed: $url.sha256"
|
||||||
|
|
||||||
|
want=$(awk '{print $1}' < "$tmp/$asset.sha256")
|
||||||
|
got=$(sha256 "$tmp/$asset")
|
||||||
|
[ -n "$want" ] || err "empty checksum file"
|
||||||
|
[ "$want" = "$got" ] || err "checksum mismatch (want $want, got $got)"
|
||||||
|
|
||||||
|
tar -xzf "$tmp/$asset" -C "$tmp"
|
||||||
|
[ -f "$tmp/matcha" ] || err "archive did not contain 'matcha'"
|
||||||
|
mkdir -p "$INSTALL_DIR"
|
||||||
|
chmod +x "$tmp/matcha"
|
||||||
|
mv "$tmp/matcha" "$INSTALL_DIR/matcha"
|
||||||
|
|
||||||
|
echo "matcha-install: installed to $INSTALL_DIR/matcha ($tag)"
|
||||||
|
case ":${PATH}:" in
|
||||||
|
*":$INSTALL_DIR:"*) ;;
|
||||||
|
*) echo "matcha-install: add to PATH -> export PATH=\"$INSTALL_DIR:\$PATH\"" ;;
|
||||||
|
esac
|
||||||
|
"$INSTALL_DIR/matcha" --version 2>/dev/null || true
|
||||||
+4
-2
@@ -1,7 +1,7 @@
|
|||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(name = "matcha", about = "green-tea CLI")]
|
#[command(name = "matcha", version, about = "green-tea CLI")]
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
pub command: Command,
|
pub command: Command,
|
||||||
@@ -14,12 +14,14 @@ pub enum Command {
|
|||||||
name: String,
|
name: String,
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
template_url: Option<String>,
|
template_url: Option<String>,
|
||||||
|
#[arg(long, default_value = "node", value_parser = ["node", "deno", "bun"])]
|
||||||
|
runtime: String,
|
||||||
},
|
},
|
||||||
/// Detect the runtime and run the project in watch mode
|
/// Detect the runtime and run the project in watch mode
|
||||||
Run,
|
Run,
|
||||||
/// Generate a piece and auto-wire it into the module
|
/// Generate a piece and auto-wire it into the module
|
||||||
Create {
|
Create {
|
||||||
#[arg(value_parser = ["module", "controller", "step"])]
|
#[arg(value_parser = ["module", "controller", "step", "provider"])]
|
||||||
kind: String,
|
kind: String,
|
||||||
name: String,
|
name: String,
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
|
|||||||
+111
-29
@@ -1,33 +1,42 @@
|
|||||||
//! `matcha create <kind> <Name>` — generate a stub file for `<kind>` and
|
//! `matcha create <kind> <Name>` — generate a stub file for `<kind>` and
|
||||||
//! auto-wire it into `src/app.module.ts` via the pure text-editing helpers
|
//! auto-wire it into `src/app.module.ts` via the pure text-editing helpers
|
||||||
//! in `wire`.
|
//! in `wire`.
|
||||||
//!
|
|
||||||
//! `module` and `step` are intentionally stubbed as "not implemented yet"
|
|
||||||
//! for v1 — they will reuse the same `wire` primitives as `controller` in a
|
|
||||||
//! fast follow.
|
|
||||||
|
|
||||||
use std::io::{Error, ErrorKind};
|
use std::io::{Error, ErrorKind};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use crate::wire;
|
use crate::wire;
|
||||||
|
|
||||||
fn controller_stub(name: &str) -> String {
|
|
||||||
format!(
|
|
||||||
"import {{ Route, Get }} from '@green-tea/core';\n\n\
|
|
||||||
@Route('/{lower}')\nexport class {name}Controller {{\n \
|
|
||||||
@Get('/')\n list() {{\n return [];\n }}\n}}\n",
|
|
||||||
lower = name.to_lowercase(),
|
|
||||||
name = name
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run(kind: &str, name: &str, check: bool) -> std::io::Result<()> {
|
pub fn run(kind: &str, name: &str, check: bool) -> std::io::Result<()> {
|
||||||
match kind {
|
match kind {
|
||||||
"controller" => create_controller(name, check),
|
"controller" => create_piece(
|
||||||
"module" | "step" => Err(Error::new(
|
name,
|
||||||
ErrorKind::Unsupported,
|
check,
|
||||||
format!("create {kind} not implemented yet"),
|
"controllers",
|
||||||
)),
|
"controller",
|
||||||
|
"Controller",
|
||||||
|
"controllers",
|
||||||
|
controller_stub(name),
|
||||||
|
),
|
||||||
|
"step" => create_piece(
|
||||||
|
name,
|
||||||
|
check,
|
||||||
|
"steps",
|
||||||
|
"step",
|
||||||
|
"Step",
|
||||||
|
"steps",
|
||||||
|
step_stub(name),
|
||||||
|
),
|
||||||
|
"provider" => create_piece(
|
||||||
|
name,
|
||||||
|
check,
|
||||||
|
"providers",
|
||||||
|
"provider",
|
||||||
|
"Provider",
|
||||||
|
"providers",
|
||||||
|
provider_stub(name),
|
||||||
|
),
|
||||||
|
"module" => create_module(name, check),
|
||||||
other => Err(Error::new(
|
other => Err(Error::new(
|
||||||
ErrorKind::InvalidInput,
|
ErrorKind::InvalidInput,
|
||||||
format!("unknown kind {other}"),
|
format!("unknown kind {other}"),
|
||||||
@@ -35,32 +44,78 @@ pub fn run(kind: &str, name: &str, check: bool) -> std::io::Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_controller(name: &str, check: bool) -> std::io::Result<()> {
|
/// Writes a piece file under `src/<subdir>/` and wires it into the `@Module`
|
||||||
let file = Path::new("src/controllers").join(format!("{}.controller.ts", name.to_lowercase()));
|
/// in `src/app.module.ts` (`module_key` array). Emit-only + hint on failure.
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
fn create_piece(
|
||||||
|
name: &str,
|
||||||
|
check: bool,
|
||||||
|
subdir: &str,
|
||||||
|
ext: &str,
|
||||||
|
suffix: &str,
|
||||||
|
module_key: &str,
|
||||||
|
stub: String,
|
||||||
|
) -> std::io::Result<()> {
|
||||||
|
let lower = name.to_lowercase();
|
||||||
|
let file = Path::new("src")
|
||||||
|
.join(subdir)
|
||||||
|
.join(format!("{lower}.{ext}.ts"));
|
||||||
std::fs::create_dir_all(file.parent().unwrap())?;
|
std::fs::create_dir_all(file.parent().unwrap())?;
|
||||||
std::fs::write(&file, controller_stub(name))?;
|
std::fs::write(&file, stub)?;
|
||||||
println!("✓ {}", file.display());
|
println!("✓ {}", file.display());
|
||||||
|
|
||||||
let symbol = format!("{name}Controller");
|
let symbol = format!("{name}{suffix}");
|
||||||
let from = format!("./controllers/{}.controller", name.to_lowercase());
|
let from = format!("./{subdir}/{lower}.{ext}");
|
||||||
let module_path = Path::new("src/app.module.ts");
|
let module_path = Path::new("src/app.module.ts");
|
||||||
if !module_path.exists() {
|
if !module_path.exists() {
|
||||||
println!("→ add {symbol} to your @Module manually (no src/app.module.ts found)");
|
println!("→ add {symbol} to your @Module manually (no src/app.module.ts found)");
|
||||||
return Ok(());
|
return maybe_check(check);
|
||||||
}
|
}
|
||||||
let src = std::fs::read_to_string(module_path)?;
|
let src = std::fs::read_to_string(module_path)?;
|
||||||
let imported = wire::add_import(&src, &symbol, &from);
|
let imported = wire::add_import(&src, &symbol, &from);
|
||||||
match wire::add_to_module_array(&imported, "controllers", &symbol) {
|
match wire::add_to_module_array(&imported, module_key, &symbol) {
|
||||||
Some(wired) => {
|
Some(wired) => {
|
||||||
std::fs::write(module_path, wired)?;
|
std::fs::write(module_path, wired)?;
|
||||||
println!("✓ wired {symbol} into AppModule");
|
println!("✓ wired {symbol} into AppModule");
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// agreed fallback: emit-only, do NOT corrupt the module
|
println!("→ could not auto-wire; add {symbol} to {module_key}[] in src/app.module.ts")
|
||||||
println!("→ could not auto-wire; add {symbol} to controllers[] in src/app.module.ts");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
maybe_check(check)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Writes `src/<name>.module.ts` and registers it in the `createApp({ modules })`
|
||||||
|
/// call in `src/main.ts`. Emit-only + hint on failure.
|
||||||
|
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))?;
|
||||||
|
println!("✓ {}", file.display());
|
||||||
|
|
||||||
|
let symbol = format!("{name}Module");
|
||||||
|
let from = format!("./{lower}.module");
|
||||||
|
let main_path = Path::new("src/main.ts");
|
||||||
|
if !main_path.exists() {
|
||||||
|
println!("→ register {symbol} in createApp({{ modules }}) manually (no src/main.ts found)");
|
||||||
|
return maybe_check(check);
|
||||||
|
}
|
||||||
|
let src = std::fs::read_to_string(main_path)?;
|
||||||
|
let imported = wire::add_import(&src, &symbol, &from);
|
||||||
|
match wire::add_to_createapp_modules(&imported, &symbol) {
|
||||||
|
Some(wired) => {
|
||||||
|
std::fs::write(main_path, wired)?;
|
||||||
|
println!("✓ registered {symbol} in createApp");
|
||||||
|
}
|
||||||
|
None => println!(
|
||||||
|
"→ could not auto-register; add {symbol} to createApp modules[] in src/main.ts"
|
||||||
|
),
|
||||||
|
}
|
||||||
|
maybe_check(check)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn maybe_check(check: bool) -> std::io::Result<()> {
|
||||||
if check {
|
if check {
|
||||||
match crate::check::run(Path::new(".")) {
|
match crate::check::run(Path::new(".")) {
|
||||||
Ok(true) => println!("✓ type-check passed"),
|
Ok(true) => println!("✓ type-check passed"),
|
||||||
@@ -68,6 +123,33 @@ fn create_controller(name: &str, check: bool) -> std::io::Result<()> {
|
|||||||
Err(e) => println!("⚠ could not run type-check: {e}"),
|
Err(e) => println!("⚠ could not run type-check: {e}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn controller_stub(name: &str) -> String {
|
||||||
|
let lower = name.to_lowercase();
|
||||||
|
format!(
|
||||||
|
"import {{ Route, Get }} from '@green-tea/core';\n\n@Route('/{lower}')\nexport class {name}Controller {{\n @Get('/')\n list() {{\n return [];\n }}\n}}\n"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn step_stub(name: &str) -> String {
|
||||||
|
let lower = name.to_lowercase();
|
||||||
|
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();
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn module_stub(name: &str) -> String {
|
||||||
|
let lower = name.to_lowercase();
|
||||||
|
format!(
|
||||||
|
"import {{ Module }} from '@green-tea/core';\n\n@Module({{ mountpoint: '/{lower}', controllers: [], providers: [], steps: [] }})\nexport class {name}Module {{}}\n"
|
||||||
|
)
|
||||||
|
}
|
||||||
+9
-2
@@ -1,9 +1,10 @@
|
|||||||
use std::io::{Error, ErrorKind};
|
use std::io::{Error, ErrorKind};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
use crate::runtime::Runtime;
|
||||||
use crate::template;
|
use crate::template;
|
||||||
|
|
||||||
pub fn run(name: &str, template_url: Option<&str>) -> std::io::Result<()> {
|
pub fn run(name: &str, template_url: Option<&str>, runtime: &str) -> std::io::Result<()> {
|
||||||
let dest = Path::new(name);
|
let dest = Path::new(name);
|
||||||
if dest.exists() {
|
if dest.exists() {
|
||||||
return Err(Error::new(
|
return Err(Error::new(
|
||||||
@@ -14,8 +15,14 @@ pub fn run(name: &str, template_url: Option<&str>) -> std::io::Result<()> {
|
|||||||
|
|
||||||
match template_url {
|
match template_url {
|
||||||
None => {
|
None => {
|
||||||
|
let rt = Runtime::from_str(runtime).ok_or_else(|| {
|
||||||
|
Error::new(
|
||||||
|
ErrorKind::InvalidInput,
|
||||||
|
format!("unknown runtime '{runtime}'"),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
std::fs::create_dir_all(dest)?;
|
std::fs::create_dir_all(dest)?;
|
||||||
template::write_starter(dest, name)?;
|
template::write_starter(dest, name, rt)?;
|
||||||
}
|
}
|
||||||
Some(url) => clone_template(url, dest)?,
|
Some(url) => clone_template(url, dest)?,
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-5
@@ -6,7 +6,7 @@ use crate::runtime::{self, Runtime};
|
|||||||
fn command_for(rt: Runtime) -> (&'static str, Vec<&'static str>) {
|
fn command_for(rt: Runtime) -> (&'static str, Vec<&'static str>) {
|
||||||
match rt {
|
match rt {
|
||||||
Runtime::Deno => ("deno", vec!["task", "dev"]),
|
Runtime::Deno => ("deno", vec!["task", "dev"]),
|
||||||
Runtime::Bun => ("bun", vec!["--watch", "run", "dev"]),
|
Runtime::Bun => ("bun", vec!["run", "dev"]),
|
||||||
Runtime::Node => ("npm", vec!["run", "dev"]),
|
Runtime::Node => ("npm", vec!["run", "dev"]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,10 +38,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn bun_watch() {
|
fn bun_watch() {
|
||||||
assert_eq!(
|
assert_eq!(command_for(Runtime::Bun), ("bun", vec!["run", "dev"]));
|
||||||
command_for(Runtime::Bun),
|
|
||||||
("bun", vec!["--watch", "run", "dev"])
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn node_watch() {
|
fn node_watch() {
|
||||||
|
|||||||
+6
-2
@@ -14,8 +14,12 @@ use cli::{Cli, Command};
|
|||||||
fn main() {
|
fn main() {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
match cli.command {
|
match cli.command {
|
||||||
Command::New { name, template_url } => {
|
Command::New {
|
||||||
if let Err(e) = cmd_new::run(&name, template_url.as_deref()) {
|
name,
|
||||||
|
template_url,
|
||||||
|
runtime,
|
||||||
|
} => {
|
||||||
|
if let Err(e) = cmd_new::run(&name, template_url.as_deref(), &runtime) {
|
||||||
eprintln!("error: {e}");
|
eprintln!("error: {e}");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||||
pub enum Runtime {
|
pub enum Runtime {
|
||||||
Node,
|
Node,
|
||||||
@@ -9,7 +8,6 @@ pub enum Runtime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Runtime {
|
impl Runtime {
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn from_str(s: &str) -> Option<Runtime> {
|
pub fn from_str(s: &str) -> Option<Runtime> {
|
||||||
match s.trim() {
|
match s.trim() {
|
||||||
"node" => Some(Runtime::Node),
|
"node" => Some(Runtime::Node),
|
||||||
@@ -20,13 +18,11 @@ impl Runtime {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
fn exists(dir: &Path, name: &str) -> bool {
|
fn exists(dir: &Path, name: &str) -> bool {
|
||||||
dir.join(name).exists()
|
dir.join(name).exists()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reads `runtime = "..."` from matcha.toml without a TOML dep (one field only).
|
/// Reads `runtime = "..."` from matcha.toml without a TOML dep (one field only).
|
||||||
#[allow(dead_code)]
|
|
||||||
fn override_from_toml(dir: &Path) -> Option<Runtime> {
|
fn override_from_toml(dir: &Path) -> Option<Runtime> {
|
||||||
let text = std::fs::read_to_string(dir.join("matcha.toml")).ok()?;
|
let text = std::fs::read_to_string(dir.join("matcha.toml")).ok()?;
|
||||||
for line in text.lines() {
|
for line in text.lines() {
|
||||||
@@ -39,7 +35,6 @@ fn override_from_toml(dir: &Path) -> Option<Runtime> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn detect(dir: &Path) -> Option<Runtime> {
|
pub fn detect(dir: &Path) -> Option<Runtime> {
|
||||||
if let Some(r) = override_from_toml(dir) {
|
if let Some(r) = override_from_toml(dir) {
|
||||||
return Some(r);
|
return Some(r);
|
||||||
|
|||||||
+59
-7
@@ -1,10 +1,24 @@
|
|||||||
use include_dir::{include_dir, Dir};
|
use include_dir::{include_dir, Dir};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
pub static STARTER: Dir = include_dir!("$CARGO_MANIFEST_DIR/template/starter");
|
use crate::runtime::Runtime;
|
||||||
|
|
||||||
pub fn write_starter(dest: &Path, project_name: &str) -> std::io::Result<()> {
|
pub static SHARED: Dir = include_dir!("$CARGO_MANIFEST_DIR/template/shared");
|
||||||
write_dir(&STARTER, dest, project_name)
|
pub static RUNTIME_DENO: Dir = include_dir!("$CARGO_MANIFEST_DIR/template/runtimes/deno");
|
||||||
|
pub static RUNTIME_NODE: Dir = include_dir!("$CARGO_MANIFEST_DIR/template/runtimes/node");
|
||||||
|
pub static RUNTIME_BUN: Dir = include_dir!("$CARGO_MANIFEST_DIR/template/runtimes/bun");
|
||||||
|
|
||||||
|
fn overlay_for(runtime: Runtime) -> &'static Dir<'static> {
|
||||||
|
match runtime {
|
||||||
|
Runtime::Deno => &RUNTIME_DENO,
|
||||||
|
Runtime::Node => &RUNTIME_NODE,
|
||||||
|
Runtime::Bun => &RUNTIME_BUN,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_starter(dest: &Path, project_name: &str, runtime: Runtime) -> std::io::Result<()> {
|
||||||
|
write_dir(&SHARED, dest, project_name)?;
|
||||||
|
write_dir(overlay_for(runtime), dest, project_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_dir(dir: &Dir, dest: &Path, name: &str) -> std::io::Result<()> {
|
fn write_dir(dir: &Dir, dest: &Path, name: &str) -> std::io::Result<()> {
|
||||||
@@ -36,16 +50,54 @@ mod tests {
|
|||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn writes_starter_and_substitutes_name() {
|
fn deno_writes_shared_and_deno_overlay() {
|
||||||
let d = tempdir().unwrap();
|
let d = tempdir().unwrap();
|
||||||
write_starter(d.path(), "my-api").unwrap();
|
write_starter(d.path(), "my-api", Runtime::Deno).unwrap();
|
||||||
|
|
||||||
let html = std::fs::read_to_string(d.path().join("public/index.html")).unwrap();
|
let html = std::fs::read_to_string(d.path().join("public/index.html")).unwrap();
|
||||||
assert!(html.contains("<title>my-api</title>"));
|
assert!(html.contains("<title>my-api</title>"));
|
||||||
assert!(!html.contains("{{project_name}}"));
|
assert!(!html.contains("{{project_name}}"));
|
||||||
assert!(d.path().join("src/controllers/home.controller.ts").exists());
|
assert!(d.path().join("src/controllers/home.controller.ts").exists());
|
||||||
assert!(d.path().join("matcha.toml").exists());
|
|
||||||
assert!(d.path().join("src/main.ts").exists());
|
|
||||||
let module = std::fs::read_to_string(d.path().join("src/app.module.ts")).unwrap();
|
let module = std::fs::read_to_string(d.path().join("src/app.module.ts")).unwrap();
|
||||||
assert!(module.contains("mountpoint"));
|
assert!(module.contains("mountpoint"));
|
||||||
|
|
||||||
|
assert!(d.path().join("deno.json").exists());
|
||||||
|
assert!(d.path().join("matcha.toml").exists());
|
||||||
|
let main = std::fs::read_to_string(d.path().join("src/main.ts")).unwrap();
|
||||||
|
assert!(main.contains("Deno.serve"));
|
||||||
|
assert!(!d.path().join("package.json").exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn node_writes_shared_and_node_overlay() {
|
||||||
|
let d = tempdir().unwrap();
|
||||||
|
write_starter(d.path(), "my-api", Runtime::Node).unwrap();
|
||||||
|
|
||||||
|
assert!(d.path().join("public/index.html").exists());
|
||||||
|
assert!(d.path().join("src/app.module.ts").exists());
|
||||||
|
|
||||||
|
let pkg = std::fs::read_to_string(d.path().join("package.json")).unwrap();
|
||||||
|
assert!(pkg.contains("\"name\": \"my-api\""));
|
||||||
|
assert!(!pkg.contains("{{project_name}}"));
|
||||||
|
assert!(d.path().join("tsconfig.json").exists());
|
||||||
|
let main = std::fs::read_to_string(d.path().join("src/main.ts")).unwrap();
|
||||||
|
assert!(main.contains("app.listen"));
|
||||||
|
assert!(!d.path().join("deno.json").exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bun_writes_shared_and_bun_overlay() {
|
||||||
|
let d = tempdir().unwrap();
|
||||||
|
write_starter(d.path(), "my-api", Runtime::Bun).unwrap();
|
||||||
|
|
||||||
|
assert!(d.path().join("public/index.html").exists());
|
||||||
|
assert!(d.path().join("src/app.module.ts").exists());
|
||||||
|
|
||||||
|
let pkg = std::fs::read_to_string(d.path().join("package.json")).unwrap();
|
||||||
|
assert!(pkg.contains("\"name\": \"my-api\""));
|
||||||
|
assert!(!pkg.contains("{{project_name}}"));
|
||||||
|
let main = std::fs::read_to_string(d.path().join("src/main.ts")).unwrap();
|
||||||
|
assert!(main.contains("Bun.serve"));
|
||||||
|
assert!(!d.path().join("deno.json").exists());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+180
-38
@@ -162,27 +162,74 @@ fn find_named_imports<'a>(root: &Node<'a>, src: &str, from: &str) -> Option<Node
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Finds the `key: [ ... ]` array inside the first `@Module({...})` and
|
/// Finds the `key: [ ... ]` array inside the first `@Module({...})` and
|
||||||
/// inserts `symbol` into it. Idempotent: a repeat call that would insert an
|
/// inserts `symbol` into it, creating `key: [symbol]` inside the module
|
||||||
/// already-present symbol is a no-op. Returns `None` — leaving the caller's
|
/// object when that key is absent entirely. Idempotent: a repeat call that
|
||||||
/// original text untouched — when the edited text fails to re-parse clean
|
/// would insert an already-present symbol is a no-op. Returns `None` —
|
||||||
/// (an `ERROR`/missing node appears), which is also what happens when `key`
|
/// leaving the caller's original text untouched — when the edited text fails
|
||||||
/// doesn't exist in the module object at all (the splice can't be located).
|
/// to re-parse clean (an `ERROR`/missing node appears), or when there is no
|
||||||
|
/// `@Module(...)` object to target at all.
|
||||||
pub fn add_to_module_array(src: &str, key: &str, symbol: &str) -> Option<String> {
|
pub fn add_to_module_array(src: &str, key: &str, symbol: &str) -> Option<String> {
|
||||||
let tree = parser().parse(src, None).unwrap();
|
let tree = parser().parse(src, None).unwrap();
|
||||||
let (open, close, existing) = find_array(&tree.root_node(), src, key)?;
|
let root = tree.root_node();
|
||||||
if existing.split(',').map(str::trim).any(|s| s == symbol) {
|
let object = find_module_object(&root, src)?;
|
||||||
return Some(src.to_string()); // idempotent
|
insert_into_object_array(src, object, key, symbol)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Inserts `symbol` into the `modules` array of the first `createApp(...)`
|
||||||
|
/// call's argument object (creating the `modules` key if absent). Idempotent;
|
||||||
|
/// reverts (returns `None`) on parse breakage or when no `createApp(...)` call
|
||||||
|
/// with an object argument is found.
|
||||||
|
pub fn add_to_createapp_modules(src: &str, symbol: &str) -> Option<String> {
|
||||||
|
let tree = parser().parse(src, None).unwrap();
|
||||||
|
let root = tree.root_node();
|
||||||
|
let object = find_createapp_object(&root, src)?;
|
||||||
|
insert_into_object_array(src, object, "modules", symbol)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Inserts `symbol` into the `key: [...]` array directly inside `object`
|
||||||
|
/// (an object-literal node). If that `key` pair is absent, a new
|
||||||
|
/// `key: [symbol]` pair is inserted into the object. Idempotent; re-parses and
|
||||||
|
/// returns `None` on breakage.
|
||||||
|
fn insert_into_object_array(src: &str, object: Node, key: &str, symbol: &str) -> Option<String> {
|
||||||
|
if let Some((open, close)) = find_key_array_span(object, src, key) {
|
||||||
|
let inner = &src[open + 1..close];
|
||||||
|
if inner.split(',').map(str::trim).any(|s| s == symbol) {
|
||||||
|
return Some(src.to_string()); // idempotent
|
||||||
|
}
|
||||||
|
let joined = if inner.trim().is_empty() {
|
||||||
|
symbol.to_string()
|
||||||
|
} else {
|
||||||
|
format!("{}, {}", inner.trim_end().trim_end_matches(','), symbol)
|
||||||
|
};
|
||||||
|
let mut out = String::with_capacity(src.len() + symbol.len() + 2);
|
||||||
|
out.push_str(&src[..open + 1]);
|
||||||
|
out.push_str(&joined);
|
||||||
|
out.push_str(&src[close..]);
|
||||||
|
return if parses_clean(&out) { Some(out) } else { None };
|
||||||
}
|
}
|
||||||
let inner = &src[open + 1..close]; // between [ ]
|
|
||||||
let joined = if inner.trim().is_empty() {
|
// The key exists but its value isn't an array literal (e.g. `controllers: SHARED`
|
||||||
symbol.to_string()
|
// or `modules: MODULES`). Creating a second `key: [...]` pair parses clean yet
|
||||||
|
// silently shadows the user's value at runtime (JS keeps the last duplicate key),
|
||||||
|
// so `parses_clean` can't catch it. Refuse — the caller falls back to emit-only.
|
||||||
|
if object_has_key(object, src, key) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
// key absent → create `key: [symbol]` inside the object, before its '}'
|
||||||
|
let obj_open = object.start_byte();
|
||||||
|
let obj_close = object.end_byte() - 1; // the '}'
|
||||||
|
let existing = src[obj_open + 1..obj_close].trim();
|
||||||
|
let pair = format!("{key}: [{symbol}]");
|
||||||
|
let new_inner = if existing.is_empty() {
|
||||||
|
format!(" {pair} ")
|
||||||
} else {
|
} else {
|
||||||
format!("{}, {}", inner.trim_end().trim_end_matches(','), symbol)
|
format!(" {}, {pair} ", existing.trim_end_matches(','))
|
||||||
};
|
};
|
||||||
let mut out = String::with_capacity(src.len() + symbol.len() + 2);
|
let mut out = String::with_capacity(src.len() + pair.len() + 4);
|
||||||
out.push_str(&src[..open + 1]);
|
out.push_str(&src[..obj_open + 1]);
|
||||||
out.push_str(&joined);
|
out.push_str(&new_inner);
|
||||||
out.push_str(&src[close..]);
|
out.push_str(&src[obj_close..]);
|
||||||
if parses_clean(&out) {
|
if parses_clean(&out) {
|
||||||
Some(out)
|
Some(out)
|
||||||
} else {
|
} else {
|
||||||
@@ -190,18 +237,29 @@ pub fn add_to_module_array(src: &str, key: &str, symbol: &str) -> Option<String>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `(open_bracket_byte, close_bracket_byte, inner_text)` for the
|
/// True when `object` has any direct `pair` child whose key text equals `key`,
|
||||||
/// `key: [...]` pair found directly inside the first `@Module({...})`
|
/// regardless of the value's kind. Used to avoid creating a duplicate key when
|
||||||
/// decorator's argument object. Unscoped searches over the whole tree would
|
/// an existing pair's value isn't an array literal.
|
||||||
/// risk matching a same-named key in an unrelated object literal (e.g. a
|
fn object_has_key(object: Node, src: &str, key: &str) -> bool {
|
||||||
/// nested `providers:`/`controllers:` array inside `imports: [X.register({
|
let mut c = object.walk();
|
||||||
/// ... })]`, or a decoy object literal elsewhere in the file) — scoping to
|
for child in object.named_children(&mut c) {
|
||||||
/// the `@Module(...)` object's own pairs avoids that.
|
if child.kind() == "pair"
|
||||||
fn find_array(root: &Node, src: &str, key: &str) -> Option<(usize, usize, String)> {
|
&& child
|
||||||
let module_object = find_module_object(root, src)?;
|
.child_by_field_name("key")
|
||||||
|
.and_then(|k| k.utf8_text(src.as_bytes()).ok())
|
||||||
|
== Some(key)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
let mut c = module_object.walk();
|
/// Returns `(open_bracket_byte, close_bracket_byte)` of the `key: [...]` array
|
||||||
for child in module_object.named_children(&mut c) {
|
/// among `object`'s direct `pair` children, or `None` if absent.
|
||||||
|
fn find_key_array_span(object: Node, src: &str, key: &str) -> Option<(usize, usize)> {
|
||||||
|
let mut c = object.walk();
|
||||||
|
for child in object.named_children(&mut c) {
|
||||||
if child.kind() != "pair" {
|
if child.kind() != "pair" {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -217,14 +275,43 @@ fn find_array(root: &Node, src: &str, key: &str) -> Option<(usize, usize, String
|
|||||||
if v.kind() != "array" {
|
if v.kind() != "array" {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let open = v.start_byte();
|
return Some((v.start_byte(), v.end_byte() - 1));
|
||||||
let close = v.end_byte() - 1; // the ']'
|
|
||||||
let inner = src[open + 1..close].to_string();
|
|
||||||
return Some((open, close, inner));
|
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Locates the argument object literal of the first `createApp(...)` call
|
||||||
|
/// expression (function identifier `createApp`), in source order.
|
||||||
|
fn find_createapp_object<'a>(root: &Node<'a>, src: &str) -> Option<Node<'a>> {
|
||||||
|
fn visit<'a>(node: Node<'a>, src: &str) -> Option<Node<'a>> {
|
||||||
|
if node.kind() == "call_expression" {
|
||||||
|
let is_createapp = node
|
||||||
|
.child_by_field_name("function")
|
||||||
|
.filter(|f| f.kind() == "identifier")
|
||||||
|
.and_then(|f| f.utf8_text(src.as_bytes()).ok())
|
||||||
|
== Some("createApp");
|
||||||
|
if is_createapp {
|
||||||
|
if let Some(args) = node.child_by_field_name("arguments") {
|
||||||
|
let mut ac = args.walk();
|
||||||
|
for child in args.named_children(&mut ac) {
|
||||||
|
if child.kind() == "object" {
|
||||||
|
return Some(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut c = node.walk();
|
||||||
|
for child in node.children(&mut c) {
|
||||||
|
if let Some(r) = visit(child, src) {
|
||||||
|
return Some(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
visit(*root, src)
|
||||||
|
}
|
||||||
|
|
||||||
/// Inserts `method_src` immediately before the closing `}` of `class
|
/// Inserts `method_src` immediately before the closing `}` of `class
|
||||||
/// <class>`'s body. Returns `None` — leaving the caller's original text
|
/// <class>`'s body. Returns `None` — leaving the caller's original text
|
||||||
/// untouched — when the edited text fails to re-parse clean, or when no
|
/// untouched — when the edited text fails to re-parse clean, or when no
|
||||||
@@ -347,7 +434,11 @@ export class AppModule {}
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn broken_result_is_rejected() {
|
fn broken_result_is_rejected() {
|
||||||
// key missing entirely → our splice can't find it → None, file untouched upstream
|
// Predates create-if-absent: `providers` used to be missing entirely,
|
||||||
|
// so the old `find_array` couldn't locate it → None. Now the key is
|
||||||
|
// created instead, so either outcome is accepted here; the dedicated
|
||||||
|
// `creates_providers_key_and_reverts_on_break` test above covers the
|
||||||
|
// create-if-absent behavior explicitly.
|
||||||
assert!(
|
assert!(
|
||||||
add_to_module_array(MOD, "providers", "X").is_none()
|
add_to_module_array(MOD, "providers", "X").is_none()
|
||||||
|| add_to_module_array(MOD, "providers", "X")
|
|| add_to_module_array(MOD, "providers", "X")
|
||||||
@@ -356,12 +447,11 @@ export class AppModule {}
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extra coverage beyond the brief: `broken_result_is_rejected` above only
|
/// Extra coverage beyond the brief: this exercises the `None` path where
|
||||||
/// exercises the "key not found" `None` path (via `find_array`). This
|
/// `insert_into_object_array` finds (or creates) the target but the
|
||||||
/// exercises the *other* `None` path — a splice that finds the array but
|
/// splice produces text that no longer parses clean — proving the
|
||||||
/// produces text that no longer parses clean — proving the revert-on-ERROR
|
/// revert-on-ERROR guarantee (`parses_clean` check) is real, not just
|
||||||
/// guarantee (`parses_clean` check in `add_to_module_array`) is real, not
|
/// theoretically reachable.
|
||||||
/// just theoretically reachable.
|
|
||||||
#[test]
|
#[test]
|
||||||
fn revert_on_actual_parse_error() {
|
fn revert_on_actual_parse_error() {
|
||||||
// A "symbol" containing stray syntax breaks the array/object/class
|
// A "symbol" containing stray syntax breaks the array/object/class
|
||||||
@@ -426,4 +516,56 @@ export class AppModule {}
|
|||||||
let out = add_import(src, "Sse", "@green-tea/core");
|
let out = add_import(src, "Sse", "@green-tea/core");
|
||||||
assert!(out.contains("import { Sse } from '@green-tea/core';"));
|
assert!(out.contains("import { Sse } from '@green-tea/core';"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn creates_steps_key_when_absent() {
|
||||||
|
// MOD has only `controllers` — adding a step must CREATE `steps: [...]`
|
||||||
|
let out = add_to_module_array(MOD, "steps", "PasitoStep").unwrap();
|
||||||
|
assert!(out.contains("steps: [PasitoStep]"));
|
||||||
|
assert!(out.contains("controllers: [HomeController]")); // untouched
|
||||||
|
// idempotent
|
||||||
|
assert_eq!(
|
||||||
|
add_to_module_array(&out, "steps", "PasitoStep").unwrap(),
|
||||||
|
out
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn creates_providers_key_and_reverts_on_break() {
|
||||||
|
let out = add_to_module_array(MOD, "providers", "ConfigProvider").unwrap();
|
||||||
|
assert!(out.contains("providers: [ConfigProvider]"));
|
||||||
|
// a symbol with stray syntax must still be rejected (revert guard)
|
||||||
|
assert!(add_to_module_array(MOD, "providers", "X]; class Evil {").is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
const MAIN: &str = "import { createApp } from '@green-tea/core';\nimport { AppModule } from './app.module';\n\nconst app = createApp({ modules: [AppModule] });\n";
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn adds_module_to_createapp() {
|
||||||
|
let out = add_to_createapp_modules(MAIN, "UsersModule").unwrap();
|
||||||
|
assert!(out.contains("AppModule, UsersModule"));
|
||||||
|
assert_eq!(add_to_createapp_modules(&out, "UsersModule").unwrap(), out);
|
||||||
|
// idempotent
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn createapp_creates_modules_key_when_absent() {
|
||||||
|
let src = "const app = createApp({});\n";
|
||||||
|
let out = add_to_createapp_modules(src, "AppModule").unwrap();
|
||||||
|
assert!(out.contains("modules: [AppModule]"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn refuses_duplicate_key_when_module_value_not_array() {
|
||||||
|
// `controllers` exists but its value is an identifier, not an array literal.
|
||||||
|
// Adding must NOT create a second `controllers` pair (silent runtime shadowing).
|
||||||
|
let src = "@Module({ mountpoint: '/', controllers: SHARED })\nexport class AppModule {}\n";
|
||||||
|
assert!(add_to_module_array(src, "controllers", "X").is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn refuses_duplicate_modules_when_createapp_value_not_array() {
|
||||||
|
let src = "const app = createApp({ modules: MODULES });\n";
|
||||||
|
assert!(add_to_createapp_modules(src, "UsersModule").is_none());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
runtime = "bun"
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"name": "{{project_name}}",
|
||||||
|
"type": "module",
|
||||||
|
"private": true,
|
||||||
|
"scripts": { "dev": "bun --watch run src/main.ts" },
|
||||||
|
"dependencies": { "@green-tea/core": "^26.7.0-beta.0" }
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { createApp } from '@green-tea/core';
|
||||||
|
import { AppModule } from './app.module';
|
||||||
|
|
||||||
|
const app = createApp({ modules: [AppModule] });
|
||||||
|
|
||||||
|
Bun.serve({ port: 8000, fetch: app.fetch });
|
||||||
|
console.log('🍵 green-tea running on http://localhost:8000');
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "esnext",
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true
|
||||||
|
}
|
||||||
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1 @@
|
|||||||
|
runtime = "node"
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "{{project_name}}",
|
||||||
|
"type": "module",
|
||||||
|
"private": true,
|
||||||
|
"scripts": { "dev": "tsx watch src/main.ts" },
|
||||||
|
"dependencies": { "@green-tea/core": "^26.7.0-beta.0" },
|
||||||
|
"devDependencies": { "tsx": "^4", "typescript": "^5" }
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { createApp } from '@green-tea/core';
|
||||||
|
import { AppModule } from './app.module';
|
||||||
|
|
||||||
|
const app = createApp({ modules: [AppModule] });
|
||||||
|
|
||||||
|
app.listen(3000);
|
||||||
|
console.log('🍵 green-tea running on http://localhost:3000');
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es2020",
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true
|
||||||
|
}
|
||||||
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
Executable
+46
@@ -0,0 +1,46 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Tests install.sh against a local file:// fixture (no network).
|
||||||
|
set -eu
|
||||||
|
here=$(cd "$(dirname "$0")" && pwd)
|
||||||
|
fail() { echo "FAIL: $*" >&2; exit 1; }
|
||||||
|
|
||||||
|
# derive this machine's expected triple the same way install.sh does
|
||||||
|
os=$(uname -s); arch=$(uname -m)
|
||||||
|
case "$os" in
|
||||||
|
Darwin) case "$arch" in arm64|aarch64) triple=aarch64-apple-darwin;; x86_64) triple=x86_64-apple-darwin;; esac;;
|
||||||
|
Linux) case "$arch" in x86_64|amd64) triple=x86_64-unknown-linux-musl;; esac;;
|
||||||
|
esac
|
||||||
|
[ -n "${triple:-}" ] || { echo "SKIP: unsupported test host"; exit 0; }
|
||||||
|
|
||||||
|
work=$(mktemp -d); trap 'rm -rf "$work"' EXIT
|
||||||
|
tag=v0.0.0
|
||||||
|
assetdir="$work/fixture/releases/download/$tag"
|
||||||
|
mkdir -p "$assetdir"
|
||||||
|
|
||||||
|
# build a fake release asset: a tarball containing a 'matcha' executable
|
||||||
|
printf '#!/bin/sh\necho "matcha 0.0.0-test"\n' > "$work/matcha"
|
||||||
|
chmod +x "$work/matcha"
|
||||||
|
tar -czf "$assetdir/matcha-$triple.tar.gz" -C "$work" matcha
|
||||||
|
if command -v sha256sum >/dev/null 2>&1; then
|
||||||
|
( cd "$assetdir" && sha256sum "matcha-$triple.tar.gz" > "matcha-$triple.tar.gz.sha256" )
|
||||||
|
else
|
||||||
|
( cd "$assetdir" && shasum -a 256 "matcha-$triple.tar.gz" > "matcha-$triple.tar.gz.sha256" )
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- case 1: happy path installs the binary ---
|
||||||
|
bin="$work/bin"
|
||||||
|
MATCHA_REPO_BASE="file://$work/fixture" MATCHA_VERSION="$tag" MATCHA_INSTALL_DIR="$bin" \
|
||||||
|
sh "$here/install.sh" >/dev/null 2>&1 || fail "install.sh exited non-zero on happy path"
|
||||||
|
[ -x "$bin/matcha" ] || fail "matcha not installed to $bin"
|
||||||
|
"$bin/matcha" --version >/dev/null 2>&1 || fail "installed matcha not runnable"
|
||||||
|
|
||||||
|
# --- case 2: checksum mismatch aborts and does NOT install ---
|
||||||
|
echo "deadbeef matcha-$triple.tar.gz" > "$assetdir/matcha-$triple.tar.gz.sha256"
|
||||||
|
bin2="$work/bin2"
|
||||||
|
if MATCHA_REPO_BASE="file://$work/fixture" MATCHA_VERSION="$tag" MATCHA_INSTALL_DIR="$bin2" \
|
||||||
|
sh "$here/install.sh" >/dev/null 2>&1; then
|
||||||
|
fail "install.sh should have failed on checksum mismatch"
|
||||||
|
fi
|
||||||
|
[ -e "$bin2/matcha" ] && fail "matcha must NOT be installed on checksum mismatch"
|
||||||
|
|
||||||
|
echo "PASS: test_install.sh"
|
||||||
@@ -30,3 +30,57 @@ fn create_controller_writes_and_wires() {
|
|||||||
assert!(module.contains("UsersController"));
|
assert!(module.contains("UsersController"));
|
||||||
assert!(module.contains("import { UsersController }"));
|
assert!(module.contains("import { UsersController }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn create_step_writes_and_wires() {
|
||||||
|
let d = tempdir().unwrap();
|
||||||
|
seed_module(d.path()); // writes src/app.module.ts with `@Module({ controllers: [] })`
|
||||||
|
Command::cargo_bin("matcha")
|
||||||
|
.unwrap()
|
||||||
|
.current_dir(d.path())
|
||||||
|
.args(["create", "step", "Pasito"])
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
assert!(d.path().join("src/steps/pasito.step.ts").exists());
|
||||||
|
let m = std::fs::read_to_string(d.path().join("src/app.module.ts")).unwrap();
|
||||||
|
assert!(m.contains("PasitoStep"));
|
||||||
|
assert!(m.contains("import { PasitoStep }"));
|
||||||
|
assert!(m.contains("steps: [PasitoStep]"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn create_provider_writes_and_wires() {
|
||||||
|
let d = tempdir().unwrap();
|
||||||
|
seed_module(d.path());
|
||||||
|
Command::cargo_bin("matcha")
|
||||||
|
.unwrap()
|
||||||
|
.current_dir(d.path())
|
||||||
|
.args(["create", "provider", "Config"])
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
assert!(d.path().join("src/providers/config.provider.ts").exists());
|
||||||
|
let m = std::fs::read_to_string(d.path().join("src/app.module.ts")).unwrap();
|
||||||
|
assert!(m.contains("providers: [ConfigProvider]"));
|
||||||
|
assert!(m.contains("import { ConfigProvider }"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn create_module_writes_and_registers_in_createapp() {
|
||||||
|
let d = tempdir().unwrap();
|
||||||
|
std::fs::create_dir_all(d.path().join("src")).unwrap();
|
||||||
|
std::fs::write(
|
||||||
|
d.path().join("src/main.ts"),
|
||||||
|
"import { createApp } from '@green-tea/core';\nimport { AppModule } from './app.module';\n\nconst app = createApp({ modules: [AppModule] });\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
Command::cargo_bin("matcha")
|
||||||
|
.unwrap()
|
||||||
|
.current_dir(d.path())
|
||||||
|
.args(["create", "module", "Users"])
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
assert!(d.path().join("src/users.module.ts").exists());
|
||||||
|
let main = std::fs::read_to_string(d.path().join("src/main.ts")).unwrap();
|
||||||
|
assert!(main.contains("AppModule, UsersModule"));
|
||||||
|
assert!(main.contains("import { UsersModule }"));
|
||||||
|
}
|
||||||
@@ -16,6 +16,66 @@ fn new_scaffolds_into_named_dir() {
|
|||||||
assert!(root.join("public/index.html").exists());
|
assert!(root.join("public/index.html").exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn new_default_runtime_is_node() {
|
||||||
|
let d = tempdir().unwrap();
|
||||||
|
Command::cargo_bin("matcha")
|
||||||
|
.unwrap()
|
||||||
|
.current_dir(d.path())
|
||||||
|
.args(["new", "demo"])
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
let root = d.path().join("demo");
|
||||||
|
let pkg = std::fs::read_to_string(root.join("package.json")).unwrap();
|
||||||
|
assert!(pkg.contains("\"name\": \"demo\""));
|
||||||
|
assert!(root.join("tsconfig.json").exists());
|
||||||
|
assert!(!root.join("deno.json").exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn new_with_deno_runtime_produces_deno_json() {
|
||||||
|
let d = tempdir().unwrap();
|
||||||
|
Command::cargo_bin("matcha")
|
||||||
|
.unwrap()
|
||||||
|
.current_dir(d.path())
|
||||||
|
.args(["new", "demo-deno", "--runtime", "deno"])
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
let root = d.path().join("demo-deno");
|
||||||
|
assert!(root.join("deno.json").exists());
|
||||||
|
assert!(!root.join("package.json").exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn new_with_node_runtime_produces_package_json() {
|
||||||
|
let d = tempdir().unwrap();
|
||||||
|
Command::cargo_bin("matcha")
|
||||||
|
.unwrap()
|
||||||
|
.current_dir(d.path())
|
||||||
|
.args(["new", "demo", "--runtime", "node"])
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
let root = d.path().join("demo");
|
||||||
|
let pkg = std::fs::read_to_string(root.join("package.json")).unwrap();
|
||||||
|
assert!(pkg.contains("\"name\": \"demo\""));
|
||||||
|
assert!(!root.join("deno.json").exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn new_with_bun_runtime_produces_package_json() {
|
||||||
|
let d = tempdir().unwrap();
|
||||||
|
Command::cargo_bin("matcha")
|
||||||
|
.unwrap()
|
||||||
|
.current_dir(d.path())
|
||||||
|
.args(["new", "demo-bun", "--runtime", "bun"])
|
||||||
|
.assert()
|
||||||
|
.success();
|
||||||
|
let root = d.path().join("demo-bun");
|
||||||
|
let pkg = std::fs::read_to_string(root.join("package.json")).unwrap();
|
||||||
|
assert!(pkg.contains("\"name\": \"demo-bun\""));
|
||||||
|
assert!(!root.join("deno.json").exists());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn new_refuses_existing_dir() {
|
fn new_refuses_existing_dir() {
|
||||||
let d = tempdir().unwrap();
|
let d = tempdir().unwrap();
|
||||||
|
|||||||
Reference in new issue
Block a user