feat(cli): add --api flavor to autumn new for JSON-first projects#1847
Conversation
`autumn new <name> --api` emits a lean, JSON-first project skeleton with zero HTML/CSS/Tailwind artifacts. Handlers return `Json<...>` and register via `routes![]`; the `maud` dependency and autumn-web's view features (maud/htmx/tailwind) are dropped via `default-features = false`, while `db` and migrations are kept so database features still work. The API flavor skips the Tailwind/CSS build step, `input.css`, `tailwind.config.js`, and the vendored htmx/JS static assets, and uses dedicated `main`, `Cargo.toml`, `Dockerfile`, and `build.rs` templates so the default fullstack scaffold is unchanged. `--api` composes with `--with-i18n` and `--with-seed`, and is rejected together with the daemon flavors (`--daemon`/`--bundled-pg`), whose feature sets conflict. Adds a CLI conformance test asserting the generated `--api` tree carries no HTML/CSS template artifacts and has a Json handler + `routes![]`, plus an ignored cargo-check test that compiles the generated API app.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 339a692f36
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| COPY --from=builder /app/target/release/{{project_name}} /usr/local/bin/{{project_name}} | ||
| COPY --from=builder /app/autumn.toml /app/autumn.toml | ||
| COPY --from=builder /app/migrations /app/migrations |
There was a problem hiding this comment.
Copy i18n locales into API images
When a project is scaffolded with autumn new <app> --api --with-i18n, inject_i18n_api makes src/main.rs call .i18n_auto(), and this Dockerfile builds without the embed-assets feature, so the app falls back to loading /app/i18n/en.ftl at startup. This copy block never carries the i18n/ sidecar into the runtime image (and the builder stage does not copy it either), so that generated Docker image panics on startup with the default locale missing.
Useful? React with 👍 / 👎.
|
Confirmed — the finding is correct and now fixed in One correction: this isn't Generated by Claude Code |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## trunk-dev #1847 +/- ##
=============================================
+ Coverage 86.82% 87.05% +0.22%
=============================================
Files 273 276 +3
Lines 202424 207776 +5352
=============================================
+ Hits 175761 180883 +5122
- Misses 26663 26893 +230 🚀 New features to boost your workflow:
|
Before / After
Before —
autumn new myapiproduces exactly one skeleton: a fullstack HTML app wired for Tailwind. To turn it into a JSON API you hand-delete ~5 files/sections:tailwind.config.js,input.css, the CSS-compilation step inbuild.rs, the maudlayout()+ HTML routes inmain.rs, and the stylesheet<link>.After —
autumn new myapi --apiproduces a JSON-first skeleton with zero HTML/CSS/Tailwind artifacts. The firstcargo runserves JSON and you delete zero files to reach a clean starting point.How
The
--apiflag selects a separate, lean template set rather than rewriting the existing one, so the default path is untouched:autumn-cli/src/templates/:main.api.rs.tmpl—Jsonhandlers registered viaroutes[], keeps migrations wiring, no maud/HTML.Cargo.api.toml.tmpl— no maud dependency, lean feature set.Dockerfile.api.tmpl— no Tailwind/CSS build step.build.api.rs.tmpl— build/git provenance only, no CSS compile.autumn-cli/src/new.rs— adds awith_apioption;--apiconflicts with--daemon/--bundled-pg; conditional template selection; skipsstatic/,input.css,tailwind.config.js, and vendored assets; API branch inrender_cargo_toml; i18n composition plus README/summary adjustments for the API flavor.autumn-cli/src/main.rs— threads the--apiclap flag through dispatch.autumn-cli/tests/integration/api_scaffold.rs(registered inmod.rs) — conformance tests.Acceptance criteria
autumn new myapi --apisucceeds; the generated project compiles andcargo runserves a sample route returning HTTP 200 withContent-Type: application/json. — Generated app cargo-checks clean against patchedautumn-web; runtime proof:GET /returns HTTP 200 withContent-Type: application/json.--apiproject contains zero HTML/CSS/Tailwind artifacts (notailwind.config.js,input.css, CSSbuild.rsstep,maud::html!/layout(), or stylesheet<link>); grep fortailwind,input.css,maud::htmlreturns zero matches. — Grep across the generated--apitree returns zero matches for all three.--apimain.rsdefines at least one handler returningJsonand registers it viaroutes[]. —main.api.rs.tmplemitsJsonhandlers wired throughroutes[].--apiautumn.tomlomits the asset/CSS config blocks the fullstack template includes. —Cargo.api.toml.tmpldrops the maud dep and asset/CSS blocks; API branch inrender_cargo_toml.--apiDockerfilehas no CSS/asset build step. —Dockerfile.api.tmplomits the Tailwind/CSS step.--apiproduces today's fullstack project unchanged (byte-for-byte). — Default (no-flag) output verified byte-for-byte unchanged.--with-i18nand--with-seedcompose correctly with--api. — i18n composition handled innew.rs; covered by conformance tests.--apigenerated project carries no HTML/CSS template artifacts. —api_scaffold.rsasserts absence of HTML/CSS/Tailwind artifacts.Testing
cargo fmt --all -- --check— clean.cargo clippy -p autumn-cli --all-targets -- -D warnings— clean.cargo build -p autumn-cli— builds.--apiapp cargo-checks clean with patchedautumn-web.GET /returns HTTP 200 withContent-Type: application/json.tailwind/input.css/maud::htmlacross the generated--apitree returns zero matches.#[ignore]cargo-check test all pass; fullcli_testssuite: 157 passed.Out of scope
Per the issue, OpenAPI auto-wiring (
openapi.rs) and the MCP tool surface are deliberately excluded — desirable follow-ups, not part of this slice.Closes #1390
Generated by Claude Code