spark_cli 1.0.0-alpha.3
spark_cli: ^1.0.0-alpha.3 copied to clipboard
Command-line interface for the Spark Framework. Provides project scaffolding, hot reload development server, production builds, and OpenAPI specification generation.
Spark CLI #
Command-line interface for the Spark Framework - a Dart web framework for building server-side rendered applications with interactive islands.
Features #
- Project scaffolding - Quickly bootstrap new Spark projects with
spark init - Hot reload development - Fast development cycle with automatic hot reload using
spark dev - Production builds - Optimized builds with native server compilation using
spark build - OpenAPI generation - Automatic API documentation from your endpoints with
spark openapi
Installation #
Add spark_cli as a dev dependency in your pubspec.yaml:
dev_dependencies:
spark_cli: ^1.0.0
Or install globally:
dart pub global activate spark_cli
Commands #
| Command | Description |
|---|---|
spark init <name> |
Create a new Spark project |
spark dev |
Start development server with hot reload |
spark build |
Build for production |
spark openapi |
Generate OpenAPI specification |
spark init #
Creates a new Spark project with a complete starter template including a counter component, home page, and API endpoint.
spark init my_app
This generates:
pubspec.yaml- Project configurationbin/server.dart- Server entry pointlib/pages/home_page.dart- Example page with SSRlib/components/counter.dart- Interactive island componentlib/endpoints/endpoints.dart- Example API endpointanalysis_options.yaml- Linting configuration.gitignore- Git ignore rules
spark dev #
Starts the development server with:
- Hot reload - Dart code changes are instantly applied
- Live reload - Browser automatically refreshes on changes
- Watch mode - Automatic code generation via
build_runner
spark dev
The development server monitors your files and:
- Runs
build_runner watchfor code generation - Starts the server with VM service for hot reload
- Automatically restarts when router configuration changes
- Triggers browser refresh on file changes
spark build #
Builds your Spark application for production deployment.
spark build
Options:
| Option | Default | Description |
|---|---|---|
--clean |
true |
Clean build directory before building |
-v, --verbose |
false |
Show verbose build output |
-o, --output |
build |
Output directory path |
Build phases:
- Clean build directory (optional)
- Run code generation with
build_runner - Compile server to native executable
- Compile web assets with dart2js (O2 optimization)
- Copy static assets
- Clean up development artifacts
Examples:
# Standard production build
spark build
# Build to custom directory
spark build -o dist
# Build without cleaning
spark build --no-clean
# Verbose output
spark build -v
spark openapi #
Generates an OpenAPI 3.0 specification from your @Endpoint annotations.
spark openapi
Options:
| Option | Default | Description |
|---|---|---|
-o, --output |
openapi.json |
Output file path |
Features:
- Automatically discovers endpoints annotated with
@Endpoint - Extracts path parameters, request bodies, and response types
- Infers error responses from thrown exceptions
- Supports validation annotations for schema constraints
- Generates component schemas for DTOs
Examples:
# Generate to default location
spark openapi
# Generate to custom file
spark openapi -o api-spec.json
Quick Start #
-
Create a new project:
spark init my_app cd my_app -
Install dependencies:
dart pub get -
Start development:
spark dev -
Open http://localhost:8080 in your browser
-
When ready for production:
spark build
Related Packages #
- spark_framework - Core Spark Framework
- spark_generator - Code generation for Spark