recipe crud
Scaffold a CRUD pattern, model + 5-method service + 3 screens, all wired together.
A multi-step recipe that scaffolds a typical CRUD-shaped resource end to end: a model, a service with five methods, three screens, plus all the routing, DI, and navigation wiring.
Synopsis
Section titled “Synopsis”swiftspawn recipe crud <Resource> [--in <feature>] [--from <path-or-url>] [--with-tests] [--dry-run] [--force] [--quiet] [--verbose]Description
Section titled “Description”recipe crud Movie is roughly equivalent to:
generate model Movie(with--fromif provided).generate service Movie, but with five methods instead of one:fetch,fetchOne,create,update,delete.generate screen MovieList on Movies --uses MovieServicegenerate screen MovieDetail on Movies --uses MovieServicegenerate screen MovieEdit on Movies --uses MovieService
All routes are added, all navigation is wired, and the service is registered in DI.
The feature folder defaults to <Resource>s (so Movie becomes Movies). Override with --in <feature>.
If --from is supplied, the model fields are inferred from the JSON sample. Without it, the model is an empty skeleton you fill in.
This is the fastest way to get from “I have an API and a sample response” to “I have a working SwiftUI app fetching and displaying data.”
Examples
Section titled “Examples”swiftspawn recipe crud Movieswiftspawn recipe crud Movie --in Movies --from sample.json --with-testsswiftspawn recipe crud Movie --from https://api.example.com/movies/1Generated files
Section titled “Generated files”Features/Movies/Models/Movie.swiftServices/MovieService.swiftServices/MovieServiceImpl.swiftServices/MockMovieService.swiftFeatures/Movies/MovieList/MovieListView.swiftFeatures/Movies/MovieList/MovieListViewModel.swiftFeatures/Movies/MovieDetail/MovieDetailView.swiftFeatures/Movies/MovieDetail/MovieDetailViewModel.swiftFeatures/Movies/MovieEdit/MovieEditView.swiftFeatures/Movies/MovieEdit/MovieEditViewModel.swiftWith --with-tests, the matching *ViewModelTests.swift for each screen.
Side effects
Section titled “Side effects”- Adds
case movieList,case movieDetail,case movieEdittoRoute.swift. - Wires those cases into
RootView.swift. - Registers
movieServiceinDIContainer.swift.
Options
Section titled “Options”| Flag | Description |
|---|---|
--in <feature> | Feature folder to nest screens under. Defaults to <Resource>s. |
--from <path-or-url> | Path or URL to a JSON sample for the model. |
--with-tests | Also generate test files for each screen. |
--dry-run | Preview without writing. |
--force | Overwrite existing files. |
Exit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
| 2 | Invalid resource name. |
| 5 | Not in a swiftspawn project. |
| 7 | Route.swift is missing markers. |
| 9, 10, 11 | JSON sample issues (file, URL, parse). |