Skip to content

feat: add @fresh/cli package for project management and code generation#3787

Draft
bartlomieju wants to merge 1 commit intomainfrom
feat/fresh-cli
Draft

feat: add @fresh/cli package for project management and code generation#3787
bartlomieju wants to merge 1 commit intomainfrom
feat/fresh-cli

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

Summary

Introduces a new @fresh/cli package — a unified CLI tool installable globally as fresh:

deno install -gAf jsr:@fresh/cli

Commands

Command Description
fresh init [dir] Create a new project (delegates to @fresh/init)
fresh dev Start dev server (auto-detects Vite vs Builder)
fresh build Build for production
fresh start Start production server
fresh generate <type> <name> Generate files (aliases: gen, g)
fresh routes List all routes with URL patterns and types

Generators

  • route — page route with optional --handler flag
  • api — API-only route (.ts, handler only)
  • island — island component with props interface
  • middleware — scoped or root middleware
  • layout — scoped or root layout
  • component — server component

Features

  • Auto-detects Fresh project root (walks up to find deno.json with fresh import)
  • Computes correct relative utils.ts import paths at any nesting depth
  • Derives PascalCase component names from file paths (including dynamic params like [id])
  • Route collision detection (e.g. about.tsx vs about/index.tsx)
  • --dry-run to preview without writing
  • --force to overwrite existing files
  • Templates follow existing Fresh conventions (define.page, define.handlers, etc.)

Example usage

fresh generate route about
fresh generate route users/[id] --handler
fresh gen api health
fresh g island SearchBar
fresh generate middleware admin
fresh generate layout dashboard
fresh routes

Test plan

  • 20 unit/integration tests covering all generators, utils, import path resolution, and collision detection
  • Manual testing of dev, build, start commands against a real Fresh project
  • Test global installation via deno install -gAf

…tion

Introduces a unified CLI tool (`fresh`) that handles:
- `fresh init` — delegates to @fresh/init for project scaffolding
- `fresh dev` / `fresh build` / `fresh start` — project lifecycle commands
- `fresh generate` (aliases: gen, g) — code generation for routes, API routes,
  islands, middleware, layouts, and components
- `fresh routes` — lists all routes with URL patterns and types

The generate command auto-detects the Fresh project root, computes correct
relative import paths for utils.ts, derives PascalCase component names, checks
for route collisions, and supports --dry-run, --force, and --handler flags.

20 tests covering utils and all generator types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant